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
+
1
3
import { callHook } from 'core/instance/lifecycle'
2
4
import { getFirstComponentChild } from 'core/vdom/helpers/index'
3
5
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
+
4
16
export default {
5
17
name : 'keep-alive' ,
6
18
abstract : true ,
19
+ props : {
20
+ include : patternTypes ,
21
+ exclude : patternTypes
22
+ } ,
7
23
created ( ) {
8
24
this . cache = Object . create ( null )
9
25
} ,
10
26
render ( ) {
11
- const vnode = getFirstComponentChild ( this . $slots . default )
27
+ const vnode : VNode = getFirstComponentChild ( this . $slots . default )
12
28
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
+ }
14
38
const key = vnode . key == null
15
39
// same constructor may get registered as different local components
16
40
// so cid alone is not enough (#3269)
17
- ? opts . Ctor . cid + '::' + opts . tag
41
+ ? opts . Ctor . cid + ( opts . tag ? `:: ${ opts . tag } ` : '' )
18
42
: vnode . key
19
43
if ( this . cache [ key ] ) {
20
44
vnode . child = this . cache [ key ] . child
You can’t perform that action at this time.
0 commit comments