0
votes

I have an EmberData snapshot which I'd like decorate with a few additional attributes before handing over to the UI for presentation. This decoration will be setting "properties" of the Ember-Data record not actual attributes. It looks like this:

let foo = Ember.computed.oneWay(this.get('store').find('activity')); 
foo.map(item => {
    item.set('foobar', 'baz');
    return item;
}

I would then hope that foo would be the beneficiary of the promised record (it is) and the setting of the foobar property would be localized to the foo property (it's not, it seems to be globally scoped to the record's properties).

2

2 Answers

0
votes

As for me this is expected behavior.

1) OneWay means only you are not bind set method on foo. It used to work between properties of objects, but this.get('store').find('activity') is a just promise.

2) foo is store.find() result of DS.RecordArray type (assuming promise is resolved). So you are iterating on records returned and set foobar property on them.

Achieving your goal, you could decorate activity record by component (Ember 2.0 way) for UI presentation.

0
votes

So far the only way I've been able to do this is using Ember's ObjectProxy like so:

const FooDecorator = Ember.ObjectProxy.extend({
    foobar: 'baz'
});    
let foo = Ember.computed(function() {
    return this.get('store').find('activity').map(item => {
        FooDecorator.create({content: item});
    });
}

This works but I thought I'd been hearing things about Object proxies not being a welcome part of Ember 2.0 roadmap so not sure if this approach is best. I'll keep this open for a few days before closing.