@@ -48,9 +48,8 @@ module.exports = {
48
48
this . idKey =
49
49
this . _checkParam ( 'track-by' ) ||
50
50
this . _checkParam ( 'trackby' ) // 0.11.0 compat
51
- this . hasTransition =
52
- this . el . hasAttribute ( config . prefix + 'transition' )
53
51
this . cache = Object . create ( null )
52
+ this . checkUpdateStrategy ( )
54
53
} ,
55
54
56
55
/**
@@ -131,6 +130,30 @@ module.exports = {
131
130
}
132
131
} ,
133
132
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
+
134
157
/**
135
158
* Update.
136
159
* This is called whenever the Array mutates.
@@ -146,14 +169,7 @@ module.exports = {
146
169
} else if ( type === 'string' ) {
147
170
data = _ . toArray ( data )
148
171
}
149
- // There are two situations where we have to use the
150
- // more complex but more accurate diff algorithm:
151
- // 1. We are using components with v-repeat - the
152
- // components could have additional state outside
153
- // of v-repeat data.
154
- // 2. We have transitions on the list, which requires
155
- // precise DOM re-positioning.
156
- this . vms = this . asComponent || this . hasTransition
172
+ this . vms = this . needDiff
157
173
? this . diff ( data , this . vms )
158
174
: this . inplaceUpdate ( data , this . vms )
159
175
// update v-ref
@@ -404,13 +420,12 @@ module.exports = {
404
420
if ( this . refID ) {
405
421
this . vm . $ [ this . refID ] = null
406
422
}
407
- var needUncache = this . asComponent || this . hasTransition
408
423
if ( this . vms ) {
409
424
var i = this . vms . length
410
425
var vm
411
426
while ( i -- ) {
412
427
vm = this . vms [ i ]
413
- if ( needUncache ) {
428
+ if ( this . needDiff ) {
414
429
this . uncacheVm ( vm )
415
430
}
416
431
vm . $destroy ( )
0 commit comments