ember install ember-data-filter
To use, you will need to add this mixin to the store. If you are also using another addon which extends the store, you will want to ensure that this mixin is applied to the store provided by that addon.
// app/services/store.jsimportStorefrom'ember-data/store';importFilterMixinfrom'ember-data-filter/mixins/filter';exportdefaultStore.extend(FilterMixin);We recommend that you refactor away from using this addon. Below
is a short guide for the three filter use scenarios and how to
best refactor each.
Why? Simply put, it's far more performant (and not a memory leak) for you to manage filtering yourself via a specialized computed property tailored specifically for your needs.
You can combine store.peekAll with a computed property, for instance:
// app/services/post-service.jsimportEmberfrom'ember';exportdefaultEmber.Service.extend({store: inject.service('store'),init(){this._super();this.posts=this.get('store').peekAll('post');},filteredPosts: Ember.computed('posts.@each.isPublished',function(){returnthis.get('posts').filterBy('isPublished');})});To resolve this you will want to separate your usage
of filter from your usage of query.
Replace
returnstore.filter(modelName,query,filter,options);with the following if you need to wait for the query
returnstore.query(modelName,query,options).then(()=>{returnstore.filter(modelName,filter);});or the below if you do not need to wait for the query
store.query(modelName,query,options);returnstore.filter(modelName,filter);Replace store.filter(modelName) with store.peekAll(modelName).
The only difference between these two is the filter returns a promisfied RecordArray
while peekAll returns a RecordArray. If during the transition you need to
preserve the promise behavior, you may do the below:
returnRSVP.Promise.resolve(store.peekAll(modelName));This project is licensed under the MIT License.
Copyright (c) 2015-2018