Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Reproduce modifier recalculation issue #647

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sukima
Copy link

@sukima sukima commented Mar 23, 2022

These tests are a starting point to discuss a strange behavior I only see with Changesets and Modifiers.

My best understanding is that the interaction between changesets and modifiers causes them to recalculate even when unrelated properties of the changeset are modified.

This might seem expected at first till you realize that this behavior does not happen with helpers and also with non-changeset objects.

This PR had to add ember-modifier and ember-functions-as-modifiers-polyfill addons to show the expected use case for these two modifier addons.

The simplest code example I have is this:

import { modifier } from 'ember-modifier';

export default modifier(function countModifierUpdates() {
  // NOTE there is no consuming any tracked properties here
  console.count('count-modifier-updates updated');
});
{{#with (changeset
  (hash foo="foo will not change" bar="bar will change")
) as |changesetObj|}}

  {{! NOTE changesetObj.foo never changes }}
  <div {{count-modifier-updates changesetObj.foo}}></div>

  <button id="submit-btn" {{on "click"
    (fn (changeset-set changesetObj "bar") "bar has changed")
  }}>Click</button>

{{/with}}

Screen Shot 2022-03-23 at 15 09 02

These tests are a starting point to discuss a strange behavior I only
see with Changesets and Modifiers.

My best understanding is that the interaction between changesets and
modifiers causes them to recalculate even when unrelated properties of
the changeset are modified.

This might seem expected at first till you realize that this behavior
does not happen with helpers and also with non-changeset objects.

This PR had to add `ember-modifier` and
`ember-functions-as-modifiers-polyfill` addons to show the expected use
case for these two modifier addons.

The simplest code example I have is this:

```js
import { modifier } from 'ember-modifier';

export default modifier(function countModifierUpdates() {
  // NOTE there is no consuming any tracked properties here
  console.count('count-modifier-updates updated');
});
```

```hbs
{{#with (changeset
  (hash foo="foo will not change" bar="bar will change")
) as |changesetObj|}}

  {{! NOTE changesetObj.foo never changes }}
  <div {{count-modifier-updates changesetObj.foo}}></div>

  <button id="submit-btn" {{on "click"
    (fn (changeset-set changesetObj "bar") "bar has changed")
  }}>Click</button>

{{/with}}
```
@sukima
Copy link
Author

sukima commented Mar 23, 2022

@NullVoxPopuli This is the reproduction I was talking about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant