File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change 1+ /* @flow */
2+
13import { callHook } from 'core/instance/lifecycle'
24import { getFirstComponentChild } from 'core/vdom/helpers/index'
35
6+ const patternTypes = [ String , RegExp ]
7+
8+ function matches ( pattern : string | RegExp , name : string ) : boolean {
9+ if ( typeof pattern === 'string' ) {
10+ return pattern . split ( ',' ) . indexOf ( name ) > - 1
11+ } else {
12+ return pattern . test ( name )
13+ }
14+ }
15+
416export default {
517 name : 'keep-alive' ,
618 abstract : true ,
19+ props : {
20+ include : patternTypes ,
21+ exclude : patternTypes
22+ } ,
723 created ( ) {
824 this . cache = Object . create ( null )
925 } ,
1026 render ( ) {
11- const vnode = getFirstComponentChild ( this . $slots . default )
27+ const vnode : VNode = getFirstComponentChild ( this . $slots . default )
1228 if ( vnode && vnode . componentOptions ) {
13- const opts = vnode . componentOptions
29+ const opts : VNodeComponentOptions = vnode . componentOptions
30+ // check pattern
31+ const name = opts . tag || opts . Ctor . options . name
32+ if ( name && (
33+ ( this . include && ! matches ( this . include , name ) ) ||
34+ ( this . exclude && matches ( this . exclude , name ) )
35+ ) ) {
36+ return vnode
37+ }
1438 const key = vnode . key == null
1539 // same constructor may get registered as different local components
1640 // so cid alone is not enough (#3269)
17- ? opts . Ctor . cid + '::' + opts . tag
41+ ? opts . Ctor . cid + ( opts . tag ? `:: ${ opts . tag } ` : '' )
1842 : vnode . key
1943 if ( this . cache [ key ] ) {
2044 vnode . child = this . cache [ key ] . child
You can’t perform that action at this time.
0 commit comments