Skip to content

Commit

Permalink
refactor: use index instead of function
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 7, 2024
1 parent 50126ca commit b0617e5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export interface ComponentInternalInstance {
* after initialized (e.g. inline handlers)
* @internal
*/
renderCache: (Function | VNode)[]
renderCache: (Function | VNode | undefined)[]

/**
* Resolved component registry, only for components with mixins or extends
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-core/src/helpers/withMemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export function withMemo(

// shallow clone
ret.memo = memo.slice()

ret.cleanMemoCache = () => (cache[index] = undefined)
ret.memoIndex = index

return (cache[index] = ret)
}
Expand Down
5 changes: 3 additions & 2 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2110,15 +2110,16 @@ function baseCreateRenderer(
shapeFlag,
patchFlag,
dirs,
memoIndex,
} = vnode
// unset ref
if (ref != null) {
setRef(ref, null, parentSuspense, vnode, true)
}

// #6593 should clean memo cache when unmount
if (vnode.cleanMemoCache) {
vnode.cleanMemoCache()
if (memoIndex != null) {
parentComponent!.renderCache[memoIndex] = undefined
}

if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ export interface VNode<
*/
memo?: any[]
/**
* @internal clean v-memo cache
* @internal index for cleaning v-memo cache
*/
cleanMemoCache?: Function
memoIndex?: number
/**
* @internal __COMPAT__ only
*/
Expand Down

0 comments on commit b0617e5

Please sign in to comment.