Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
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

Description

@dgieselaar

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions