File tree Expand file tree Collapse file tree 2 files changed +25
-9
lines changed
test/unit/specs/directives Expand file tree Collapse file tree 2 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -386,12 +386,8 @@ module.exports = {
386386 this . cacheVm ( raw , vm , index , this . converted ? meta . $key : null )
387387 }
388388 // sync back changes for two-way bindings of primitive values
389- var type = typeof raw
390389 var dir = this
391- if (
392- this . rawType === 'object' &&
393- ( type === 'string' || type === 'number' )
394- ) {
390+ if ( this . rawType === 'object' && isPrimitive ( raw ) ) {
395391 vm . $watch ( alias || '$value' , function ( val ) {
396392 if ( dir . filters ) {
397393 process . env . NODE_ENV !== 'production' && _ . warn (
@@ -740,3 +736,19 @@ function toRefObject (vms) {
740736 }
741737 return ref
742738}
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) {
669669 '<div v-repeat="obj">{{$value}}</div>' +
670670 '<div v-repeat="val:vals">{{val}}</div>' ,
671671 data : {
672- items : [ 'a' , 'b' ] ,
672+ items : [ 'a' , true ] ,
673673 obj : { foo : 'a' , bar : 'b' } ,
674- vals : [ 1 , 2 ]
674+ vals : [ 1 , null ]
675675 }
676676 } )
677677 vm . $children [ 0 ] . $value = 'c'
678+ vm . $children [ 1 ] . $value = 'd'
678679 var key = vm . $children [ 2 ] . $key
679- vm . $children [ 2 ] . $value = 'd '
680+ vm . $children [ 2 ] . $value = 'e '
680681 vm . $children [ 4 ] . val = 3
682+ vm . $children [ 5 ] . val = 4
681683 _ . nextTick ( function ( ) {
682684 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' )
684687 expect ( vm . vals [ 0 ] ) . toBe ( 3 )
688+ expect ( vm . vals [ 1 ] ) . toBe ( 4 )
685689 done ( )
686690 } )
687691 } )
You can’t perform that action at this time.
0 commit comments