File tree 2 files changed +25
-9
lines changed
test/unit/specs/directives 2 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -386,12 +386,8 @@ module.exports = {
386
386
this . cacheVm ( raw , vm , index , this . converted ? meta . $key : null )
387
387
}
388
388
// sync back changes for two-way bindings of primitive values
389
- var type = typeof raw
390
389
var dir = this
391
- if (
392
- this . rawType === 'object' &&
393
- ( type === 'string' || type === 'number' )
394
- ) {
390
+ if ( this . rawType === 'object' && isPrimitive ( raw ) ) {
395
391
vm . $watch ( alias || '$value' , function ( val ) {
396
392
if ( dir . filters ) {
397
393
process . env . NODE_ENV !== 'production' && _ . warn (
@@ -740,3 +736,19 @@ function toRefObject (vms) {
740
736
}
741
737
return ref
742
738
}
739
+
740
+ /**
741
+ * Check if a value is a primitive one:
742
+ * String, Number, Boolean, null or undefined.
743
+ *
744
+ * @param {* } value
745
+ * @return {Boolean }
746
+ */
747
+
748
+ function isPrimitive ( value ) {
749
+ var type = typeof value
750
+ return value == null ||
751
+ type === 'string' ||
752
+ type === 'number' ||
753
+ type === 'boolean'
754
+ }
Original file line number Diff line number Diff line change @@ -669,19 +669,23 @@ if (_.inBrowser) {
669
669
'<div v-repeat="obj">{{$value}}</div>' +
670
670
'<div v-repeat="val:vals">{{val}}</div>' ,
671
671
data : {
672
- items : [ 'a' , 'b' ] ,
672
+ items : [ 'a' , true ] ,
673
673
obj : { foo : 'a' , bar : 'b' } ,
674
- vals : [ 1 , 2 ]
674
+ vals : [ 1 , null ]
675
675
}
676
676
} )
677
677
vm . $children [ 0 ] . $value = 'c'
678
+ vm . $children [ 1 ] . $value = 'd'
678
679
var key = vm . $children [ 2 ] . $key
679
- vm . $children [ 2 ] . $value = 'd '
680
+ vm . $children [ 2 ] . $value = 'e '
680
681
vm . $children [ 4 ] . val = 3
682
+ vm . $children [ 5 ] . val = 4
681
683
_ . nextTick ( function ( ) {
682
684
expect ( vm . items [ 0 ] ) . toBe ( 'c' )
683
- expect ( vm . obj [ key ] ) . toBe ( 'd' )
685
+ expect ( vm . items [ 1 ] ) . toBe ( 'd' )
686
+ expect ( vm . obj [ key ] ) . toBe ( 'e' )
684
687
expect ( vm . vals [ 0 ] ) . toBe ( 3 )
688
+ expect ( vm . vals [ 1 ] ) . toBe ( 4 )
685
689
done ( )
686
690
} )
687
691
} )
You can’t perform that action at this time.
0 commit comments