Derived properties don't listen to change events from collections
See original GitHub issueSimplified example:
var Model = require('ampersand-model');
var Collection = require('ampersand-collection');
var Room = Model.extend({
props: {
size: ['number', true, 10],
},
});
var Rooms = Collection.extend({
model: Room,
});
var House = Model.extend({
collections: {
rooms: Rooms,
},
derived: {
totalArea: {
deps: ['rooms'],
fn: function() {
return this.rooms.reduce(function(a, b) {
return a + b.size;
}, 0);
}
}
},
});
var house = new House({
rooms: [{size: 12}]
});
console.log(house.totalArea); // => 12
house.rooms.at(0).size = 15;
console.log(house.totalArea); // => 12
Seems like this should work?
Issue Analytics
- State:
- Created 9 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
INotifyPropertyChanged And derived properties on different ...
E.g.: You can have a centralized place where all ViewModels (ObservableObjects) register them self and start listening to change events.
Read more >Derived properties - No Magic Community Forum • View topic
I' m trying to add event listener to listen to related elements in hierarchy events (if we have elementA and elementB, elementA has...
Read more >props, derived, session for ampersand-collection · Issue #10 - GitHub
Was wondering if there was a way to have properties (props, derived, session) for ampersand-collection. Would be particularly useful to have a derived...
Read more >Handle Multiple Events Using Event Properties - Microsoft Learn
Learn how to handle many events by using event properties. Define delegate collections, event keys, & event properties.
Read more >Delegated properties | Kotlin Documentation
Lazy properties: the value is computed only on first access. · Observable properties: listeners are notified about changes to this property. · Storing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Has there been any progress/ fix for this issue?
It’s a tricky problem to solve. I use a mixin to deal with this for now…
https://gist.github.com/jdiaz5513/6716e23c4995711db020
Could publish this mixin if it proves to be useful to anyone else.