Переглянути джерело

refactor: remove `cacheFragment` function and rename `instance` to `block` in `innerCacheBlock`

daiwei 3 місяців тому
батько
коміт
7cfd45ce79
1 змінених файлів з 4 додано та 19 видалено
  1. 4 19
      packages/runtime-vapor/src/components/KeepAlive.ts

+ 4 - 19
packages/runtime-vapor/src/components/KeepAlive.ts

@@ -102,7 +102,7 @@ const KeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
 
 
     const innerCacheBlock = (
     const innerCacheBlock = (
       key: CacheKey,
       key: CacheKey,
-      instance: VaporComponentInstance | VaporFragment,
+      block: VaporComponentInstance | VaporFragment,
     ) => {
     ) => {
       const { max } = props
       const { max } = props
 
 
@@ -118,8 +118,8 @@ const KeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
         }
         }
       }
       }
 
 
-      cache.set(key, instance)
-      current = instance
+      cache.set(key, block)
+      current = block
     }
     }
 
 
     const cacheBlock = () => {
     const cacheBlock = () => {
@@ -151,21 +151,6 @@ const KeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
       return true
       return true
     }
     }
 
 
-    const cacheFragment = (fragment: DynamicFragment) => {
-      const [innerBlock, interop] = getInnerBlock(fragment.nodes)
-      if (!innerBlock || !shouldCache(innerBlock, props, interop)) return
-
-      let key: CacheKey
-      if (interop) {
-        innerBlock.vnode!.shapeFlag! |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
-        key = innerBlock.vnode!.type
-      } else {
-        innerBlock.shapeFlag! |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
-        key = innerBlock.type
-      }
-      innerCacheBlock(key, innerBlock)
-    }
-
     const pruneCache = (filter: (name: string) => boolean) => {
     const pruneCache = (filter: (name: string) => boolean) => {
       cache.forEach((cached, key) => {
       cache.forEach((cached, key) => {
         const instance = getInstanceFromCache(cached)
         const instance = getInstanceFromCache(cached)
@@ -255,7 +240,7 @@ const KeepAliveImpl: ObjectVaporComponent = defineVaporComponent({
         },
         },
       )
       )
       ;(frag.onBeforeMount || (frag.onBeforeMount = [])).push(() =>
       ;(frag.onBeforeMount || (frag.onBeforeMount = [])).push(() =>
-        cacheFragment(frag),
+        processFragment(frag),
       )
       )
       frag.getScope = key => {
       frag.getScope = key => {
         const scope = keptAliveScopes.get(key)
         const scope = keptAliveScopes.get(key)