Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Freeze or manually/conditionally re-evaluate a scope #10904

Closed
dgieselaar opened this issue Jan 29, 2015 · 4 comments
Closed

Freeze or manually/conditionally re-evaluate a scope #10904

dgieselaar opened this issue Jan 29, 2015 · 4 comments

Comments

@dgieselaar
Copy link

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).

@petebacondarwin
Copy link
Contributor

@Plestik - Have you taken a look at @shahata's idea here #10658

@dgieselaar
Copy link
Author

@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.

@joshrtay
Copy link
Contributor

+1 for shouldevaluate method on scope

@Narretz
Copy link
Contributor

Narretz commented Jul 4, 2017

We are planning to add #10658 which obsoletes this feature proposed here

@Narretz Narretz closed this as completed Jul 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants