File tree 4 files changed +46
-11
lines changed
4 files changed +46
-11
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ var removeClass = _.removeClass
4
4
5
5
module . exports = {
6
6
7
+ deep : true ,
8
+
7
9
update : function ( value ) {
8
10
if ( value && typeof value === 'string' ) {
9
11
this . handleObject ( stringToObject ( value ) )
Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ module.exports = {
30
30
bind : function ( ) {
31
31
var attr = this . arg
32
32
var tag = this . el . tagName
33
+ // should be deep watch on object mode
34
+ if ( ! attr ) {
35
+ this . deep = true
36
+ }
33
37
// handle interpolation bindings
34
38
if ( this . descriptor . interp ) {
35
39
// only allow binding on native attributes
Original file line number Diff line number Diff line change @@ -325,19 +325,18 @@ Watcher.prototype.teardown = function () {
325
325
* getters, so that every nested property inside the object
326
326
* is collected as a "deep" dependency.
327
327
*
328
- * @param {Object } obj
328
+ * @param {* } val
329
329
*/
330
330
331
- function traverse ( obj ) {
332
- var key , val , i
333
- for ( key in obj ) {
334
- val = obj [ key ]
335
- if ( _ . isArray ( val ) ) {
336
- i = val . length
337
- while ( i -- ) traverse ( val [ i ] )
338
- } else if ( _ . isObject ( val ) ) {
339
- traverse ( val )
340
- }
331
+ function traverse ( val ) {
332
+ var i , keys
333
+ if ( _ . isArray ( val ) ) {
334
+ i = val . length
335
+ while ( i -- ) traverse ( val [ i ] )
336
+ } else if ( _ . isObject ( val ) ) {
337
+ keys = Object . keys ( val )
338
+ i = keys . length
339
+ while ( i -- ) traverse ( val [ keys [ i ] ] )
341
340
}
342
341
}
343
342
Original file line number Diff line number Diff line change @@ -313,4 +313,34 @@ describe('Misc', function () {
313
313
}
314
314
} )
315
315
} )
316
+
317
+ it ( 'deep watch for class, style and bind' , function ( done ) {
318
+ var el = document . createElement ( 'div' )
319
+ var vm = new Vue ( {
320
+ el : el ,
321
+ template : '<div :class="classes" :style="styles" v-bind="attrs"></div>' ,
322
+ data : {
323
+ classes : { a : true , b : false } ,
324
+ styles : { color : 'red' , fontSize : '14px' } ,
325
+ attrs : { a : 1 , b : 2 }
326
+ }
327
+ } )
328
+ var div = el . firstChild
329
+ expect ( div . className ) . toBe ( 'a' )
330
+ expect ( div . style . color ) . toBe ( 'red' )
331
+ expect ( div . style . fontSize ) . toBe ( '14px' )
332
+ expect ( div . getAttribute ( 'a' ) ) . toBe ( '1' )
333
+ expect ( div . getAttribute ( 'b' ) ) . toBe ( '2' )
334
+ vm . classes . b = true
335
+ vm . styles . color = 'green'
336
+ vm . attrs . a = 3
337
+ Vue . nextTick ( function ( ) {
338
+ expect ( div . className ) . toBe ( 'a b' )
339
+ expect ( div . style . color ) . toBe ( 'green' )
340
+ expect ( div . style . fontSize ) . toBe ( '14px' )
341
+ expect ( div . getAttribute ( 'a' ) ) . toBe ( '3' )
342
+ expect ( div . getAttribute ( 'b' ) ) . toBe ( '2' )
343
+ done ( )
344
+ } )
345
+ } )
316
346
} )
You can’t perform that action at this time.
0 commit comments