Let's say there is a route with capabilities to update it's data when requested by the user (assume the backend returns different data for the same call, maybe it's stock data, or just random numbers).
export default Ember.Route.extend({
model() {
return this.get('store').findAll('foo');
},
actions: {
invalidateModel() {
this.refresh();
}
}
});
Now, a component consuming this model directly will update its view as expected.
Model: {{#each model as |m|}}{{m.bar}}{{/each}}
<button {{action "refreshModel"}}>Refresh model</button>
But, if the component is using a computed property observing the model, then the updates do not carry through.
Template
Model: {{#each computedModel as |m|}}{{m}}{{/each}}
<br>
<button {{action "refreshModel"}}>Refresh model</button>
Component
computedModel: Ember.computed('model', function() {
return this.get('model').map(function(m) {
return `Computed: ${m.data.bar}`;
});
}),
For a full repro, you can check out: https://github.com/myartsev/ember-computed-properties-on-data-model
The latest commit is the non-working computed properties case.
The previous commit is when everything is still working correctly when using the model directly.
What am I missing?