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

5.0.0-beta.1 Fragment Array model updates don't work with did-update #393

Open
mike-engel opened this issue Feb 1, 2021 · 2 comments
Open

Comments

@mike-engel
Copy link

I've been in the middle of updating our ember app from 3.12 to 3.24 now that this beta is available, and for the most part it's been smooth sailing! I've run into one issue though, which is that updates to a fragment array model don't seem to trigger a change, or at least one recognized by ember-modifiers' did-update modifier.

Here's an example.

// models/webhook.js
export default class Webhook extends Model {
  @fragmentArray('header') headers
  @attr body
}

// models/header.js
export default class Header extends Fragment {
  @attr name
  @attr value
}

Then, if I have a glimmer component with a did-update modifier like this

{{! template.hbs }}
<div {{did-update this.validateHeaders @webhook.headers}}>
  ...
</div>

then this.validateHeaders only runs when the headers property changes length (i.e. header fragments are added or removed, but not modified).

It's possible that this is intended behavior, and that a custom computed property needs to be set up to track this (which is what I did, below) but it feels like this should work.

// controller.js
export default class WebhookComponent extends Component {
  @computed('args.webhook.headers.@each.{name,value}')
  get headers() {
    return this.args.webhook.headers.serialize();
  }
}
{{! template.hbs }}
<div {{did-update this.validateHeaders this.headers}}>
  ...
</div>

Thanks!

@patocallaghan
Copy link
Contributor

@mike-engel I'm unsure of the correct behaviour here but out of curiosity do you know what happens with regular Ember Data hasMany relationships? Do they trigger did-update to run?

@runspired
Copy link
Contributor

I hit a very similar sounding issue when landing the refactor of @ember-data/model to native classes. It resulted in one failure in this library for array changes not dirtying the parent owner. After investigating it seemed likely the issue was with the array code. I'll try to find some time soon to poke at a fix here.

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

No branches or pull requests

3 participants