vendredi 4 décembre 2015

ember computed alias breaks when getting first or last object

The goal was to have a computed property based on whether there was an existing object in the store or not... Based on this answer, I believe that it should be okay to get the first object (or last) in the context of a computed alias. So here is what I'm trying to do:

import Ember from 'ember';

export default Ember.Controller.extend({

    sessions: function () {
        return this.store.peekAll('session');
    }.property(),

    // this doesn't work... 
    currentSession: Ember.computed.alias('sessions.firstObject'),

    // this seems to work...
    lastSession: function () {
        return this.get('sessions.lastObject');
    }.property('sessions.lastObject'),

    ...

});

I'm using ember 1.13.8 and didn't know if this might be related to an existing ember issue or if it's a bug or just me trying to use ember in a way that it wasn't meant to...

Just to clarify, it would appear that once the alias is computed, that 'getter' becomes undefined for the sessions array. So after that point, (in the above example) calling this.get('sessions.firstObject') would return undefined, as would calling this.get('sessions').firstObject

Is this a bug? If not, what's happening behind the scenes here?

Thanks!




Aucun commentaire:

Enregistrer un commentaire