Peek & Filter and live records


#1

My backend gathers all data and returns them in the one response. I have these data properly imported into store and I’m using combination of periodically downloading data and using peek functions.

Let assume that I wish to post these data to template:

model: function() {
 return this.store.peekAll('book');
}

This model will send all clusters to template and is updated when data in store are updated. Attempt to obtain a single record:

return this.store.peekRecord('book', 'book-id');

If required data are in cache, we are fine. If they are not in cache, the model will not be updated - becase it does not return ‘live array’ like peekAll(). How we will obtain a record that will be updated?

return this.store.filter('book', (item) => { return item.id === 'book-id'})

Live array is returned and we are fine. But store.filter() is deprecated and will be removed (it is possible to use ember-data-filter, now). This is quite simple case, so there should be simplier solution. What is the right way, to do it without using store.filter() ?

Solution proposed on https://github.com/ember-data/ember-data-filter does not work with live records what I need.


#2

The way that I’ve dealt with this is by setting a property to be the result of your live array this.set('liveBooks, this.store.peekAll('book')) you can create a CP that observes changes to it and use filter() in that CP.

filterBooks: Ember.computed('liveBooks.[]', function(){
    //filter code
}),