This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -717,6 +717,13 @@ function findConstantAndWatchExpressions(ast, $filter) {
717
717
if ( ! property . value . constant ) {
718
718
argsToWatch . push . apply ( argsToWatch , property . value . toWatch ) ;
719
719
}
720
+ if ( property . computed ) {
721
+ findConstantAndWatchExpressions ( property . key , $filter ) ;
722
+ if ( ! property . key . constant ) {
723
+ argsToWatch . push . apply ( argsToWatch , property . key . toWatch ) ;
724
+ }
725
+ }
726
+
720
727
} ) ;
721
728
ast . constant = allConstants ;
722
729
ast . toWatch = argsToWatch ;
Original file line number Diff line number Diff line change @@ -3119,6 +3119,39 @@ describe('parser', function() {
3119
3119
expect ( objB . value ) . toBe ( scope . input ) ;
3120
3120
} ) ) ;
3121
3121
3122
+ it ( 'should watch ES6 object computed property changes' , function ( ) {
3123
+ var count = 0 ;
3124
+ var values = [ ] ;
3125
+
3126
+ scope . $watch ( '{[a]: true}' , function ( val ) {
3127
+ count ++ ;
3128
+ values . push ( val ) ;
3129
+ } , true ) ;
3130
+
3131
+ scope . $digest ( ) ;
3132
+ expect ( count ) . toBe ( 1 ) ;
3133
+ expect ( values [ 0 ] ) . toEqual ( { 'undefined' : true } ) ;
3134
+
3135
+ scope . $digest ( ) ;
3136
+ expect ( count ) . toBe ( 1 ) ;
3137
+ expect ( values [ 0 ] ) . toEqual ( { 'undefined' : true } ) ;
3138
+
3139
+ scope . a = true ;
3140
+ scope . $digest ( ) ;
3141
+ expect ( count ) . toBe ( 2 ) ;
3142
+ expect ( values [ 1 ] ) . toEqual ( { 'true' : true } ) ;
3143
+
3144
+ scope . a = 'abc' ;
3145
+ scope . $digest ( ) ;
3146
+ expect ( count ) . toBe ( 3 ) ;
3147
+ expect ( values [ 2 ] ) . toEqual ( { 'abc' : true } ) ;
3148
+
3149
+ scope . a = undefined ;
3150
+ scope . $digest ( ) ;
3151
+ expect ( count ) . toBe ( 4 ) ;
3152
+ expect ( values [ 3 ] ) . toEqual ( { 'undefined' : true } ) ;
3153
+ } ) ;
3154
+
3122
3155
it ( 'should support watching literals' , inject ( function ( $parse ) {
3123
3156
var lastVal = NaN ;
3124
3157
var callCount = 0 ;
You can’t perform that action at this time.
0 commit comments