MCPcopy
hub / github.com/vuejs/core / withMemo

Function withMemo

packages/runtime-core/src/helpers/withMemo.ts:4–21  ·  view source on GitHub ↗
(
  memo: any[],
  render: () => VNode<any, any>,
  cache: any[],
  index: number,
)

Source from the content-addressed store, hash-verified

2import { type VNode, currentBlock, isBlockTreeEnabled } from '../vnode'
3
4export function withMemo(
5 memo: any[],
6 render: () => VNode<any, any>,
7 cache: any[],
8 index: number,
9): VNode<any, any> {
10 const cached = cache[index] as VNode | undefined
11 if (cached && isMemoSame(cached, memo)) {
12 return cached
13 }
14 const ret = render()
15
16 // shallow clone
17 ret.memo = memo.slice()
18 ret.cacheIndex = index
19
20 return (cache[index] = ret)
21}
22
23export function isMemoSame(cached: VNode, memo: any[]): boolean {
24 const prev: any[] = cached.memo!

Callers

nothing calls this directly

Calls 2

isMemoSameFunction · 0.85
renderFunction · 0.50

Tested by

no test coverage detected