question-mark

Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Derived properties don't listen to change events from collections

See original GitHub issue

Issue Description

Simplified 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:open
  • Created 8 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tnguyen14commented, Jul 24, 2015

Has there been any progress/ fix for this issue?

0reactions
jdiaz5513commented, Jan 16, 2015

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found