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.

$animate tallying should account for no-ops #8946

Closed
@jonrimmer

Description

@jonrimmer

So if I have a directive that does the following...

scope.$watch('property', function(value) {
  if (value) {
    $animate.addClass(element, 'has-value');
  }
  else {
    $animate.removeClass(element, 'has-value');
  }
});

...and during the initial digest, the value of property is initially null, but is then populated from some data store. Then the watch will be called twice, resulting in a removeClass() call (when the class isn't actually present), followed by an addClass() call. The end result would be the class is not added, which is not what I want.

Prior to to RC0, this pattern was simple, obvious, and it worked. It's a little wasteful to have the redundant removeClass() call, but since the class isn't actually present at that point, it's basically a no-op.

In RC0, $animate's tallying breaks this pattern. I presume it is counting the two calls as (-1) + 1, equalling 0, so performing no animation. However, since the the first removeClass() call is a no-op, the subsequent addClass() call should still run.

More generally, any call to addClass() and removeClass() that wouldn't actually result in a change should not be considered for tallying. If, during a digest cycle, the following series of operations was performed:

removeClass() -> No-op
addClass()
addClass() -> No-op
addClass() -> No-op
removeClass()

It should be logically equivalent to the following:

addClass()
removeClass()

With the result being that no class is added.

Without this, the developer is forced to manually do the same de-duping everywhere such class toggling is applied using an extra state variable.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions