dchambers / composerjs

The composable modelling library
1 stars 1 forks source link

Need structure change events on nodelists #28

Closed james-shaw-turner closed 9 years ago

james-shaw-turner commented 9 years ago

@dchambers

If a code external to the model retrieves an item in a nodelist. It needs to remove the listener if the nodelist item is removed. NodeLists need to support structure changed event listeners.

var myFunc = function (){};
model.legs.item(0).on('change:foo', myFunc);
function onLegsRemoved(){
   model.legs.item(0).off('change:foo', myFunc);
}
dchambers commented 9 years ago

In CJS we don't listen to specific items within a node-list, and instead listen to the entire node-list, so there is no need to add and remove listeners as items are added and removed from a node-list.

For example:

model.legs.on('change', function(legs) {
  // do stuff...
});
james-shaw-turner commented 9 years ago

@dchambers Just to be clear you are saying that the object returned by model.legs.item(0) has set() and get() methods but no on() method.
It's not currently documented (unless I'm missing it) so I assume you can listen to all properties in the nodelist as follows:

model.legs.p("foo").on("change", function(pValues, pOldValues){
...
});

However we still need structure change events on the nodelist (legs in this case) - so we can update any GUI appropriately.

dchambers commented 9 years ago

I've spoken to @james-shaw-turner and he's happy for this to be closed.