(props: KeepAliveProps, { slots }: SetupContext)
| 91 | }, |
| 92 | |
| 93 | setup(props: KeepAliveProps, { slots }: SetupContext) { |
| 94 | const instance = getCurrentInstance()! |
| 95 | // KeepAlive communicates with the instantiated renderer via the |
| 96 | // ctx where the renderer passes in its internals, |
| 97 | // and the KeepAlive instance exposes activate/deactivate implementations. |
| 98 | // The whole point of this is to avoid importing KeepAlive directly in the |
| 99 | // renderer to facilitate tree-shaking. |
| 100 | const sharedContext = instance.ctx as KeepAliveContext |
| 101 | |
| 102 | // if the internal renderer is not registered, it indicates that this is server-side rendering, |
| 103 | // for KeepAlive, we just need to render its children |
| 104 | if (__SSR__ && !sharedContext.renderer) { |
| 105 | return () => { |
| 106 | const children = slots.default && slots.default() |
| 107 | return children && children.length === 1 ? children[0] : children |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | const cache: Cache = new Map() |
| 112 | const keys: Keys = new Set() |
| 113 | let current: VNode | null = null |
| 114 | |
| 115 | if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { |
| 116 | ;(instance as any).__v_cache = cache |
| 117 | } |
| 118 | |
| 119 | const parentSuspense = instance.suspense |
| 120 | |
| 121 | const { |
| 122 | renderer: { |
| 123 | p: patch, |
| 124 | m: move, |
| 125 | um: _unmount, |
| 126 | o: { createElement }, |
| 127 | }, |
| 128 | } = sharedContext |
| 129 | const storageContainer = createElement('div') |
| 130 | |
| 131 | sharedContext.activate = ( |
| 132 | vnode, |
| 133 | container, |
| 134 | anchor, |
| 135 | namespace, |
| 136 | optimized, |
| 137 | ) => { |
| 138 | const instance = vnode.component! |
| 139 | move(vnode, container, anchor, MoveType.ENTER, parentSuspense) |
| 140 | // in case props have changed |
| 141 | patch( |
| 142 | instance.vnode, |
| 143 | vnode, |
| 144 | container, |
| 145 | anchor, |
| 146 | instance, |
| 147 | parentSuspense, |
| 148 | namespace, |
| 149 | vnode.slotScopeIds, |
| 150 | optimized, |
nothing calls this directly
no test coverage detected