File tree 2 files changed +30
-2
lines changed
test/unit/specs/directives
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -522,8 +522,9 @@ module.exports = {
522
522
uncacheVm : function ( vm ) {
523
523
var data = vm . _raw
524
524
var idKey = this . idKey
525
- if ( idKey || this . converted ) {
526
- var id = idKey ? data [ idKey ] : vm . $key
525
+ var convertedKey = vm . $key
526
+ if ( idKey || convertedKey ) {
527
+ var id = idKey ? data [ idKey ] : convertedKey
527
528
this . cache [ id ] = null
528
529
} else if ( isObject ( data ) ) {
529
530
data [ this . id ] = null
@@ -573,6 +574,7 @@ function objToArray (obj) {
573
574
// regardless of type, store the un-filtered raw value.
574
575
this . rawValue = obj
575
576
if ( ! isPlainObject ( obj ) ) {
577
+ this . converted = false
576
578
return obj
577
579
}
578
580
var keys = Object . keys ( obj )
Original file line number Diff line number Diff line change @@ -670,6 +670,32 @@ if (_.inBrowser) {
670
670
}
671
671
} )
672
672
673
+ it ( 'switch between object-converted & array mode' , function ( done ) {
674
+ var obj = {
675
+ a : { msg : 'AA' } ,
676
+ b : { msg : 'BB' }
677
+ }
678
+ var arr = [ obj . b , obj . a ]
679
+ var vm = new Vue ( {
680
+ el : el ,
681
+ template : '<div v-repeat="obj">{{msg}}</div>' ,
682
+ data : {
683
+ obj : obj
684
+ }
685
+ } )
686
+ expect ( el . innerHTML ) . toBe ( Object . keys ( obj ) . map ( function ( key ) {
687
+ return '<div>' + obj [ key ] . msg + '</div>'
688
+ } ) . join ( '' ) )
689
+ vm . obj = arr
690
+ _ . nextTick ( function ( ) {
691
+ expect ( el . innerHTML ) . toBe ( '<div>BB</div><div>AA</div>' )
692
+ // make sure it cleared the cache
693
+ expect ( vm . _directives [ 0 ] . cache . a ) . toBeNull ( )
694
+ expect ( vm . _directives [ 0 ] . cache . b ) . toBeNull ( )
695
+ done ( )
696
+ } )
697
+ } )
698
+
673
699
} )
674
700
}
675
701
You can’t perform that action at this time.
0 commit comments