Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 44ba349

Browse files
committed
Simplify checkMetaVars $watch statement.
Per the (angular documentation)[https://code.angularjs.org/1.2.26/docs/api/ng/type/$rootScope.Scope#$digest] the "magic" hack you are using to detect each digest cycles is unnecessary. Simply register a watch function with no watch expression. From the documentation: > If you want to be notified whenever `$digest()` is called, you can register a `watchExpression` function with `$watch()` with no listener.
1 parent f8ca2ec commit 44ba349

File tree

1 file changed

+1
-23
lines changed

1 file changed

+1
-23
lines changed

src/FirebaseObject.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -360,29 +360,7 @@
360360
}
361361
}
362362

363-
// Okay, so this magic hack is um... magic. It increments a
364-
// variable every 50 seconds (counterKey) so that whenever $digest
365-
// is run, the variable will be dirty. This allows us to determine
366-
// when $digest is invoked, manually check the meta vars, and
367-
// manually invoke our watcher if the $ prefixed data has changed
368-
(function() {
369-
// create a counter and store it in scope
370-
var counterKey = '_firebaseCounterForVar'+varName;
371-
scope[counterKey] = 0;
372-
// update the counter every 51ms
373-
// why 51? because it must be greater than scopeUpdated's debounce
374-
// or protractor has a conniption
375-
var to = $interval(function() {
376-
scope[counterKey]++;
377-
}, 51, 0, false);
378-
// watch the counter for changes (which means $digest ran)
379-
self.subs.push(scope.$watch(counterKey, checkMetaVars));
380-
// cancel our interval and clear var from scope if unbound
381-
self.subs.push(function() {
382-
$interval.cancel(to);
383-
delete scope[counterKey];
384-
});
385-
})();
363+
self.subs.push(scope.$watch(checkMetaVars));
386364

387365
setScope(rec);
388366
self.subs.push(scope.$on('$destroy', self.unbind.bind(self)));

0 commit comments

Comments
 (0)