ember-data-model-fragments: Computed properties won't update on changes to nested model fragements
I have the following models:
// app/models/user.js
import Model from 'ember-data/model';
import {
fragment
} from 'model-fragments/attributes';
export default Model.extend({
family : fragment('family')
// other attrs
});
// app/models/family.js
import Model from 'ember-data/model';
import {
fragment
} from 'model-fragments/attributes';
export default Model.extend({
spouse : fragment('personal'),
mother : fragment('personal'),
father : fragment('personal')
// other attrs
});
// app/models/personal.js
import attr from 'ember-data/attr';
import Fragment from 'model-fragments/fragment';
export default Fragment.extend({
firstName : attr('string'),
lastName : attr('string'),
activeInsurance : attr() // This is not 'boolean' as it can be three-state: null, true & false
});
If I have an instance of the user.family
model (let’s say passed into a component), and I have a computed property which observes that model, cached result of the computed property won’t be updated when the nested fragments data is changed:
// This computed property won't react to changes on any family member
allFamilyHasInsurance: computed('myUser.family', function() {
//...
}),
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 4
- Comments: 17 (8 by maintainers)
@benoror I think you could also use defineProperty inside the fragment itself to create a single computed property with something like
@benoror you should be able to use a combination of the fields property and dynamically defined properties as a solution
it looks like you are hitting an exception resolved by https://github.com/lytics/ember-data-model-fragments/commit/debe667d72f560b34bda32aff90600e914c72b53. Unfortunately we still have to coordinate to get NPM publish permissions but for now installing the 2.3.3 tag from git should fix the issue.
@douglascofferi do you have an example of how the computed property is being consumed?