@@ -39,6 +39,9 @@ module.exports = {
3939 this . template = this . el . tagName === 'TEMPLATE'
4040 ? templateParser . parse ( this . el , true )
4141 : this . el
42+ // check if we need to use diff instead of inplace
43+ // updates
44+ this . checkUpdateStrategy ( )
4245 // check other directives that need to be handled
4346 // at v-repeat level
4447 this . checkIf ( )
@@ -49,7 +52,38 @@ module.exports = {
4952 this . _checkParam ( 'track-by' ) ||
5053 this . _checkParam ( 'trackby' ) // 0.11.0 compat
5154 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' )
5387 } ,
5488
5589 /**
@@ -90,8 +124,10 @@ module.exports = {
90124 var id = _ . attr ( this . el , 'component' )
91125 var options = this . vm . $options
92126 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
95131 // important: transclude with no options, just
96132 // to ensure block start and block end
97133 this . template = transclude ( this . template )
@@ -130,30 +166,6 @@ module.exports = {
130166 }
131167 } ,
132168
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-
157169 /**
158170 * Update.
159171 * This is called whenever the Array mutates.
0 commit comments