jeudi 15 octobre 2015

Ember.js: let component observe value changes of store items

I am just starting to use Ember and came across the following problem. I want to observe whether or not there has been a change of value of an item within my store. As far as I understand, that is what the @each directive is for. Unfortunately, this does not trigger the respective method in my component.

My code is structured as follows. The current route returns a subset of my store and has an action that changes one of the items.

export default Ember.Route.extend({
    model: function() {                                                                                                                 
        this.store.push('node', {id: 1, x: 40, y:40});
        this.store.push('node', {id: 3, x: 50, y:50});
        return this.store.findAll("node");
    },
    actions: {
        move: function(x, y) {
            this.store.findRecord('node', 1).then(
                function(v) {
                    v.set("x", x); v.set("y", y);
                });
        }
    }   
});

I pass the model via a template directive to my component.

{{node-comp data=model}}

Now, I want to get a notification within the component, when a value in the model changes (i.e. in my example the action 'move' was called). My current approach looks like the following:

export default Ember.Component.extend({
    rerender: function() {
        console.log("rerender called");
    }.observes("data.@each")
};

I tried the 'data.[]' directive and 'data.@each.x' directive as well. But nothing led to the desired behaviour. Notice that the template of the component is notified, i.e., the list of the items of the model gets updates after a 'move' call.


My 'ember -v' output

Future versions of Ember CLI will not support v4.2.0. Please update to Node 0.12 or io.js. version: 1.13.8 Could not find watchman, falling back to NodeWatcher for file system events. Visit http://ift.tt/1PK1A1H for more info. node: 4.2.0 npm: 2.13.4 os: linux x64




Aucun commentaire:

Enregistrer un commentaire