@@ -39,6 +39,9 @@ module.exports = {
39
39
this . template = this . el . tagName === 'TEMPLATE'
40
40
? templateParser . parse ( this . el , true )
41
41
: this . el
42
+ // check if we need to use diff instead of inplace
43
+ // updates
44
+ this . checkUpdateStrategy ( )
42
45
// check other directives that need to be handled
43
46
// at v-repeat level
44
47
this . checkIf ( )
@@ -49,7 +52,38 @@ module.exports = {
49
52
this . _checkParam ( 'track-by' ) ||
50
53
this . _checkParam ( 'trackby' ) // 0.11.0 compat
51
54
this . cache = Object . create ( null )
52
- this . checkUpdateStrategy ( )
55
+ } ,
56
+
57
+ /**
58
+ * Check what strategy to use for updates.
59
+ *
60
+ * If the repeat is simple enough we can use in-place
61
+ * updates which simply overwrites existing instances'
62
+ * data. This strategy reuses DOM nodes and instances
63
+ * as much as possible.
64
+ *
65
+ * There are two situations where we have to use the
66
+ * more complex but more accurate diff algorithm:
67
+ * 1. We are using components with or inside v-repeat.
68
+ * The components could have private state that needs
69
+ * to be preserved across updates.
70
+ * 2. We have transitions on the list, which requires
71
+ * precise DOM re-positioning.
72
+ */
73
+
74
+ checkUpdateStrategy : function ( ) {
75
+ var components = Object . keys ( this . vm . $options . components )
76
+ var matcher
77
+ if ( components . length ) {
78
+ matcher = new RegExp (
79
+ components . map ( function ( name ) {
80
+ return '<' + name + '(>|\\s)'
81
+ } ) . join ( '|' ) + '|' + config . prefix + 'component'
82
+ )
83
+ }
84
+ this . needDiff =
85
+ ( matcher && matcher . test ( this . template . outerHTML ) ) ||
86
+ this . el . hasAttribute ( config . prefix + 'transition' )
53
87
} ,
54
88
55
89
/**
@@ -90,8 +124,10 @@ module.exports = {
90
124
var id = _ . attr ( this . el , 'component' )
91
125
var options = this . vm . $options
92
126
if ( ! id ) {
93
- this . Ctor = _ . Vue // default constructor
94
- this . inherit = true // inline repeats should inherit
127
+ // default constructor
128
+ this . Ctor = _ . Vue
129
+ // inline repeats should inherit
130
+ this . inherit = true
95
131
// important: transclude with no options, just
96
132
// to ensure block start and block end
97
133
this . template = transclude ( this . template )
@@ -130,30 +166,6 @@ module.exports = {
130
166
}
131
167
} ,
132
168
133
- /**
134
- * Check what strategy to use for updates.
135
- *
136
- * If the repeat is simple enough we can use in-place
137
- * updates which simply overwrites existing instances'
138
- * data. This strategy reuses DOM nodes and instances
139
- * as much as possible.
140
- *
141
- * There are two situations where we have to use the
142
- * more complex but more accurate diff algorithm:
143
- * 1. We are using components with or inside v-repeat.
144
- * The components could have private state that needs
145
- * to be preserved across updates.
146
- * 2. We have transitions on the list, which requires
147
- * precise DOM re-positioning.
148
- */
149
-
150
- checkUpdateStrategy : function ( ) {
151
- this . needDiff =
152
- this . asComponent ||
153
- this . el . hasAttribute ( config . prefix + 'transition' ) ||
154
- this . template . querySelector ( '[' + config . prefix + 'component]' )
155
- } ,
156
-
157
169
/**
158
170
* Update.
159
171
* This is called whenever the Array mutates.
0 commit comments