refactor(runtime-core): extract common getComponentName function (#2454)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
ConcreteComponent,
|
||||
getCurrentInstance,
|
||||
FunctionalComponent,
|
||||
SetupContext,
|
||||
ComponentInternalInstance,
|
||||
LifecycleHooks,
|
||||
currentInstance
|
||||
currentInstance,
|
||||
getComponentName
|
||||
} from '../component'
|
||||
import { VNode, cloneVNode, isVNode, VNodeProps } from '../vnode'
|
||||
import { warn } from '../warning'
|
||||
@@ -151,7 +151,7 @@ const KeepAliveImpl = {
|
||||
|
||||
function pruneCache(filter?: (name: string) => boolean) {
|
||||
cache.forEach((vnode, key) => {
|
||||
const name = getName(vnode.type as ConcreteComponent)
|
||||
const name = getComponentName(vnode.type as ConcreteComponent)
|
||||
if (name && (!filter || !filter(name))) {
|
||||
pruneCacheEntry(key)
|
||||
}
|
||||
@@ -235,7 +235,7 @@ const KeepAliveImpl = {
|
||||
|
||||
let vnode = getInnerChild(rawVNode)
|
||||
const comp = vnode.type as ConcreteComponent
|
||||
const name = getName(comp)
|
||||
const name = getComponentName(comp)
|
||||
const { include, exclude, max } = props
|
||||
|
||||
if (
|
||||
@@ -301,10 +301,6 @@ export const KeepAlive = (KeepAliveImpl as any) as {
|
||||
}
|
||||
}
|
||||
|
||||
function getName(comp: ConcreteComponent): string | void {
|
||||
return (comp as FunctionalComponent).displayName || comp.name
|
||||
}
|
||||
|
||||
function matches(pattern: MatchPattern, name: string): boolean {
|
||||
if (isArray(pattern)) {
|
||||
return pattern.some((p: string | RegExp) => matches(p, name))
|
||||
|
||||
Reference in New Issue
Block a user