1
1
var _ = require ( '../util' )
2
- var config = require ( '../config' )
3
2
var isObject = _ . isObject
4
3
var isPlainObject = _ . isPlainObject
5
4
var textParser = require ( '../parsers/text' )
@@ -39,9 +38,6 @@ module.exports = {
39
38
this . template = this . el . tagName === 'TEMPLATE'
40
39
? templateParser . parse ( this . el , true )
41
40
: this . el
42
- // check if we need to use diff instead of inplace
43
- // updates
44
- this . checkUpdateStrategy ( )
45
41
// check other directives that need to be handled
46
42
// at v-repeat level
47
43
this . checkIf ( )
@@ -54,38 +50,6 @@ module.exports = {
54
50
this . cache = Object . create ( null )
55
51
} ,
56
52
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' )
87
- } ,
88
-
89
53
/**
90
54
* Warn against v-if usage.
91
55
*/
@@ -181,9 +145,7 @@ module.exports = {
181
145
} else if ( type === 'string' ) {
182
146
data = _ . toArray ( data )
183
147
}
184
- this . vms = this . needDiff
185
- ? this . diff ( data , this . vms )
186
- : this . inplaceUpdate ( data , this . vms )
148
+ this . vms = this . diff ( data , this . vms )
187
149
// update v-ref
188
150
if ( this . refID ) {
189
151
this . vm . $ [ this . refID ] = this . vms
@@ -195,43 +157,6 @@ module.exports = {
195
157
}
196
158
} ,
197
159
198
- /**
199
- * Inplace update that maximally reuses existing vm
200
- * instances and DOM nodes by simply swapping data into
201
- * existing vms.
202
- *
203
- * @param {Array } data
204
- * @param {Array } oldVms
205
- * @return {Array }
206
- */
207
-
208
- inplaceUpdate : function ( data , oldVms ) {
209
- oldVms = oldVms || [ ]
210
- var vms
211
- var dir = this
212
- var alias = dir . arg
213
- var converted = dir . converted
214
- if ( data . length < oldVms . length ) {
215
- oldVms . slice ( data . length ) . forEach ( function ( vm ) {
216
- vm . $destroy ( true )
217
- } )
218
- vms = oldVms . slice ( 0 , data . length )
219
- overwrite ( data , vms , alias , converted )
220
- } else if ( data . length > oldVms . length ) {
221
- var newVms = data . slice ( oldVms . length ) . map ( function ( data , i ) {
222
- var vm = dir . build ( data , i + oldVms . length )
223
- vm . $before ( dir . ref )
224
- return vm
225
- } )
226
- overwrite ( data . slice ( 0 , oldVms . length ) , oldVms , alias , converted )
227
- vms = oldVms . concat ( newVms )
228
- } else {
229
- overwrite ( data , oldVms , alias , converted )
230
- vms = oldVms
231
- }
232
- return vms
233
- } ,
234
-
235
160
/**
236
161
* Diff, based on new data and old data, determine the
237
162
* minimum amount of DOM manipulations needed to make the
@@ -440,9 +365,7 @@ module.exports = {
440
365
var vm
441
366
while ( i -- ) {
442
367
vm = this . vms [ i ]
443
- if ( this . needDiff ) {
444
- this . uncacheVm ( vm )
445
- }
368
+ this . uncacheVm ( vm )
446
369
vm . $destroy ( )
447
370
}
448
371
}
@@ -613,33 +536,4 @@ function range (n) {
613
536
ret [ i ] = i
614
537
}
615
538
return ret
616
- }
617
-
618
- /**
619
- * Helper function to overwrite new data Array on to
620
- * existing vms. Used in `inplaceUpdate`.
621
- *
622
- * @param {Array } arr
623
- * @param {Array } vms
624
- * @param {String|undefined } alias
625
- * @param {Boolean } converted
626
- */
627
-
628
- function overwrite ( arr , vms , alias , converted ) {
629
- var vm , data , raw
630
- for ( var i = 0 , l = arr . length ; i < l ; i ++ ) {
631
- vm = vms [ i ]
632
- data = raw = arr [ i ]
633
- if ( converted ) {
634
- vm . $key = data . $key
635
- raw = data . $value
636
- }
637
- if ( alias ) {
638
- vm [ alias ] = raw
639
- } else if ( ! isObject ( raw ) ) {
640
- vm . $value = raw
641
- } else {
642
- vm . _setData ( raw )
643
- }
644
- }
645
539
}
0 commit comments