File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,13 @@ p.run = function () {
151
151
var cbs = this . cbs
152
152
for ( var i = 0 , l = cbs . length ; i < l ; i ++ ) {
153
153
cbs [ i ] ( value , oldValue )
154
+ // if a callback also removed other callbacks,
155
+ // we need to adjust the loop accordingly.
156
+ var removed = l - cbs . length
157
+ if ( removed ) {
158
+ i -= removed
159
+ l -= removed
160
+ }
154
161
}
155
162
}
156
163
}
Original file line number Diff line number Diff line change @@ -359,4 +359,19 @@ describe('Watcher', function () {
359
359
config . async = true
360
360
} )
361
361
362
+ it ( 'handle a cb that triggers removeCb' , function ( ) {
363
+ var watcher = new Watcher ( vm , 'a' , spy )
364
+ watcher . addCb ( function ( ) {
365
+ watcher . removeCb ( spy )
366
+ } )
367
+ watcher . addCb ( function ( ) { } )
368
+ config . async = false
369
+ expect ( function ( ) {
370
+ vm . a = 2
371
+ } ) . not . toThrow ( )
372
+ config . async = true
373
+ expect ( spy ) . toHaveBeenCalled ( )
374
+ expect ( watcher . cbs . length ) . toBe ( 2 )
375
+ } )
376
+
362
377
} )
You can’t perform that action at this time.
0 commit comments