You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
I would love to see more control over whether a Scope's watchers should be re-evaluated. Currently, there's no way to 'freeze' a Scope as far as I can tell (without writing really weird brittle workarounds w/ private APIs). React has a shouldComponentUpdate method which is pretty nice and perhaps something could be of use to Angular.
Suppose a Scope has a $shouldEvaluate method, which accepts one parameter, which could either be:
'inherit' the default: re-evaluates if the Scope's parent is re-evaluated.
true: always re-evaluate a Scope in a $digest loop.
false: never re-evaluate (effectively freezes the Scope).
getEvalIdentifier: a function which is called before re-evaluating the Scope's watchers. Its result is compared to the previous result. If they're not equal, the Scope is re-evaluated. This, for example, could be an id of an object.
Additionaly, a Scope would have a $evaluateNow method, which (obviously) would immediately re-evaluate all watchers.
This approach does mean child directives could for example freeze parent scopes, which is pretty bad, so an alternative would perhaps be to set this through a DDO (in conjuction with a child or isolated scope).
The text was updated successfully, but these errors were encountered:
@petebacondarwin aye, thanks, didn't see that. That looks good. It's much simpler. My suggestion is perhaps a little too complex, but I think having a function that returns a value to compare is pretty useful. Without it you'd have to suspend/resume manually (in response to events? not sure).
I'd be happy to put in the work for a PR for this, but would like to gather some feedback on whether this is actually not a terrible idea first.
Hi all,
I would love to see more control over whether a Scope's watchers should be re-evaluated. Currently, there's no way to 'freeze' a Scope as far as I can tell (without writing really weird brittle workarounds w/ private APIs). React has a
shouldComponentUpdate
method which is pretty nice and perhaps something could be of use to Angular.Suppose a Scope has a
$shouldEvaluate
method, which accepts one parameter, which could either be:'inherit'
the default: re-evaluates if the Scope's parent is re-evaluated.true
: always re-evaluate a Scope in a $digest loop.false
: never re-evaluate (effectively freezes the Scope).getEvalIdentifier
: a function which is called before re-evaluating the Scope's watchers. Its result is compared to the previous result. If they're not equal, the Scope is re-evaluated. This, for example, could be an id of an object.Additionaly, a Scope would have a
$evaluateNow
method, which (obviously) would immediately re-evaluate all watchers.This approach does mean child directives could for example freeze parent scopes, which is pretty bad, so an alternative would perhaps be to set this through a DDO (in conjuction with a child or isolated scope).
The text was updated successfully, but these errors were encountered: