set("prop", value) do not trigger a propChanged event in collections

edited October 2013 in Enyo 2.4
no sure if this is by design or if this is bug but when I use myCollection.set("prop", value) the propChanged event is not triggered like in standard enyo components. If this is by design (collections not sending events), how can I make myCollection react to a change of one of its properity?
Note: I'm using the latest MVC struff from github.

thanks
Olivier

Comments

  • You need to use the new listener APIs to detect changes to collections and models. Look at the addListener method on both of those as the way to observe changes.
  • Can you let us know what the difference is between Observer and Listener? Thanks.
  • The listener model is a simple subscribe/notify system. Models emit "change" and "destroy" events to their listeners, while collections give "add", "remove" and "destroy" events.

    Observers are heavier and used to watch specific properties; they're the backbone of the bindings system, as well as implementing the fooChanged calls.
  • @unwiredben: yes I'm ok with using listener to detect changes to the content of a collection or to models but I would expect this to work: http://jsfiddle.net/DehEp/

    In this case what the recomended method to trigger the "usedChanged" method in the collection?
  • Collections are no longer based on enyo.Object, so they don't support a published block. There is no current way to observe properties of a collection, you can only watch for changes on the array owned by the collection.

    I'd suggest that you move any observed properties into a separate controller based on enyo.Controller which is a kind derived from enyo.Component. You could store your collection in that Controller if you wanted.



  • Update: latest code makes enyo.Collection a enyo.Component again... this was done so we could get rid of the duplicate concept in enyo.Application where "controllers" was doing the same thing that "components" does elsewhere.
  • Thanks for the update! Howewer it looks like collection still cannot send events directly (without using "triggerEvent()"). Not sure why as it's now an enyo component and afaik components can trigger events directly?
  • it's a component for nesting purposes, but it still uses its alternative event listener setup for speed.
  • ok. it look like the contructor of the collection doesn't hinerit from the component's contructor tha't why I cannot send events. (I was trying to understant why custom event where not send but couldn't find the relevant part in the code
  • edited October 2013
    ah, this was an oversight -- it's being fixed by the PR from Cole that I'm reviewing now, https://github.com/enyojs/enyo/pull/510
Sign In or Register to comment.