Skip to content
This repository was archived by the owner on Jul 5, 2023. It is now read-only.

Commit 95c8819

Browse files
committed
Fix undefined 'equals' reference when registering watchers with
equality set to true.
1 parent fb03f44 commit 95c8819

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

scalyr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ defineScalyrAngularModule('gatedScope', [])
784784
// circuit it with === operator, only when === fails do we use .equals
785785
if (watch && (value = watch.get(current)) !== (last = watch.last) &&
786786
!(watch.eq
787-
? equals(value, last)
787+
? areEqual(value, last)
788788
: (typeof value == 'number' && typeof last == 'number'
789789
&& isNaN(value) && isNaN(last)))) {
790790
dirty = true;

src/js/lib/gatedScope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ defineScalyrAngularModule('gatedScope', [])
8686
// circuit it with === operator, only when === fails do we use .equals
8787
if (watch && (value = watch.get(current)) !== (last = watch.last) &&
8888
!(watch.eq
89-
? equals(value, last)
89+
? areEqual(value, last)
9090
: (typeof value == 'number' && typeof last == 'number'
9191
&& isNaN(value) && isNaN(last)))) {
9292
dirty = true;

src/tests/lib/gatedScopeTest.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,26 @@ describe('GatedScope', function() {
256256
$rootScope.$digest();
257257
expect(counter).toEqual(4);
258258
});
259+
260+
it('should evaluate watchers registered with equality equal to true', function() {
261+
var objectToWatch = { value: 5 };
262+
263+
var counter = 0;
264+
function watcher() {
265+
++counter;
266+
return objectToWatch;
267+
}
268+
269+
// Add a gate so that all future watchers are evaluated using our version of $digest.
270+
var scope = $rootScope.$new();
271+
scope.$addWatcherGate(function() {
272+
return true;
273+
});
274+
275+
scope.$watch(watcher, function(newValue) {
276+
}, true);
277+
278+
// When both gates are down, the watcher should not be evaluated.
279+
$rootScope.$digest();
280+
});
259281
});

0 commit comments

Comments
 (0)