adopted-ember-addons / ember-changeset

Ember.js flavored changesets, inspired by Ecto
http://bit.ly/ember-changeset-demo
MIT License
431 stars 141 forks source link

BUG: Reproduce modifier recalculation issue #647

Open sukima opened 2 years ago

sukima commented 2 years ago

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

sukima commented 2 years ago

@nullvoxpopuli This is the reproduction I was talking about.