This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -300,6 +300,14 @@ function $RootScopeProvider(){
300
300
watcher . fn = function ( newVal , oldVal , scope ) { listenFn ( scope ) ; } ;
301
301
}
302
302
303
+ if ( typeof watchExp == 'string' && get . constant ) {
304
+ var originalFn = watcher . fn ;
305
+ watcher . fn = function ( newVal , oldVal , scope ) {
306
+ originalFn . call ( this , newVal , oldVal , scope ) ;
307
+ arrayRemove ( array , watcher ) ;
308
+ } ;
309
+ }
310
+
303
311
if ( ! array ) {
304
312
array = scope . $$watchers = [ ] ;
305
313
}
Original file line number Diff line number Diff line change @@ -99,6 +99,14 @@ describe('Scope', function() {
99
99
expect ( spy ) . wasCalled ( ) ;
100
100
} ) ) ;
101
101
102
+ it ( 'should not keep constant expressions on watch queue' , inject ( function ( $rootScope ) {
103
+ $rootScope . $watch ( '1 + 1' , function ( ) { } ) ;
104
+ expect ( $rootScope . $$watchers . length ) . toEqual ( 1 ) ;
105
+ $rootScope . $digest ( ) ;
106
+
107
+ expect ( $rootScope . $$watchers . length ) . toEqual ( 0 ) ;
108
+ } ) ) ;
109
+
102
110
103
111
it ( 'should delegate exceptions' , function ( ) {
104
112
module ( function ( $exceptionHandlerProvider ) {
@@ -119,10 +127,14 @@ describe('Scope', function() {
119
127
var log = '' ;
120
128
$rootScope . $watch ( 'a' , function ( ) { log += 'a' ; } ) ;
121
129
$rootScope . $watch ( 'b' , function ( ) { log += 'b' ; } ) ;
130
+ // constant expressions have slightly different handling,
131
+ // let's ensure they are kept in the same list as others
132
+ $rootScope . $watch ( '1' , function ( ) { log += '1' ; } ) ;
122
133
$rootScope . $watch ( 'c' , function ( ) { log += 'c' ; } ) ;
134
+ $rootScope . $watch ( '2' , function ( ) { log += '2' ; } ) ;
123
135
$rootScope . a = $rootScope . b = $rootScope . c = 1 ;
124
136
$rootScope . $digest ( ) ;
125
- expect ( log ) . toEqual ( 'abc ' ) ;
137
+ expect ( log ) . toEqual ( 'ab1c2 ' ) ;
126
138
} ) ) ;
127
139
128
140
You can’t perform that action at this time.
0 commit comments