@@ -23,19 +23,6 @@ module.exports = {
2323 bind : function ( ) {
2424 // uid as a cache identifier
2525 this . id = '__v_repeat_' + ( ++ uid )
26- // we need to insert the objToArray converter
27- // as the first read filter, because it has to be invoked
28- // before any user filters. (can't do it in `update`)
29- if ( ! this . filters ) {
30- this . filters = { }
31- }
32- // add the object -> array convert filter
33- var objectConverter = _ . bind ( objToArray , this )
34- if ( ! this . filters . read ) {
35- this . filters . read = [ objectConverter ]
36- } else {
37- this . filters . read . unshift ( objectConverter )
38- }
3926 // setup anchor node
4027 this . anchor = _ . createAnchor ( 'v-repeat' )
4128 _ . replace ( this . el , this . anchor )
@@ -219,13 +206,6 @@ module.exports = {
219206 */
220207
221208 realUpdate : function ( data ) {
222- data = data || [ ]
223- var type = typeof data
224- if ( type === 'number' ) {
225- data = range ( data )
226- } else if ( type === 'string' ) {
227- data = _ . toArray ( data )
228- }
229209 this . vms = this . diff ( data , this . vms )
230210 // update v-ref
231211 if ( this . refID ) {
@@ -399,8 +379,11 @@ module.exports = {
399379 }
400380 // sync back changes for two-way bindings of primitive values
401381 var type = typeof raw
402- if ( type === 'string' || type === 'number' ) {
403- var dir = this
382+ var dir = this
383+ if (
384+ this . rawType === 'object' &&
385+ ( type === 'string' || type === 'number' )
386+ ) {
404387 vm . $watch ( alias || '$value' , function ( val ) {
405388 dir . _withLock ( function ( ) {
406389 if ( dir . converted ) {
@@ -532,6 +515,48 @@ module.exports = {
532515 } else {
533516 this . cache [ data ] . pop ( )
534517 }
518+ } ,
519+
520+ /**
521+ * Pre-process the value before piping it through the
522+ * filters, and convert non-Array objects to arrays.
523+ *
524+ * This function will be bound to this directive instance
525+ * and passed into the watcher.
526+ *
527+ * @param {* } value
528+ * @return {Array }
529+ * @private
530+ */
531+
532+ _preProcess : function ( value ) {
533+ // regardless of type, store the un-filtered raw value.
534+ this . rawValue = value
535+ var type = this . rawType = typeof value
536+ if ( ! isPlainObject ( value ) ) {
537+ this . converted = false
538+ if ( type === 'number' ) {
539+ value = range ( value )
540+ } else if ( type === 'string' ) {
541+ value = _ . toArray ( value )
542+ }
543+ return value || [ ]
544+ } else {
545+ // convert plain object to array.
546+ var keys = Object . keys ( value )
547+ var i = keys . length
548+ var res = new Array ( i )
549+ var key
550+ while ( i -- ) {
551+ key = keys [ i ]
552+ res [ i ] = {
553+ $key : key ,
554+ $value : value [ key ]
555+ }
556+ }
557+ this . converted = true
558+ return res
559+ }
535560 }
536561
537562}
@@ -556,43 +581,6 @@ function findNextVm (vm, anchor) {
556581 return el . __vue__
557582}
558583
559- /**
560- * Attempt to convert non-Array objects to array.
561- * This is the default filter installed to every v-repeat
562- * directive.
563- *
564- * It will be called with **the directive** as `this`
565- * context so that we can mark the repeat array as converted
566- * from an object.
567- *
568- * @param {* } obj
569- * @return {Array }
570- * @private
571- */
572-
573- function objToArray ( obj ) {
574- // regardless of type, store the un-filtered raw value.
575- this . rawValue = obj
576- if ( ! isPlainObject ( obj ) ) {
577- this . converted = false
578- return obj
579- }
580- var keys = Object . keys ( obj )
581- var i = keys . length
582- var res = new Array ( i )
583- var key
584- while ( i -- ) {
585- key = keys [ i ]
586- res [ i ] = {
587- $key : key ,
588- $value : obj [ key ]
589- }
590- }
591- // `this` points to the repeat directive instance
592- this . converted = true
593- return res
594- }
595-
596584/**
597585 * Create a range array from given number.
598586 *
0 commit comments