store.findAll keeps updating when model is added into store


#1

Hi, I would like to load all data from the server, but then stop auto updating UI when user starts to edit some models. Currently with store.findAll it automatically pickups all newly created records. What’s the proper way to force that collections stop changing on updates?

Documentation states this

When creating a new record using any of the above methods Ember Data will update DS.RecordArrays such as those returned by store#peekAll() or store#findAll(). This means any data bindings or computed properties that depend on the RecordArray will automatically be synced to include the new or updated record values.

but there is no mention how to disable/workaround around this behaviour.

Thanks for help.


#2

One way is to filter out new records with something like:

import Controller from '@ember/controller';
import { filterBy } from '@ember/object/computed';

export default Controller.extend({
  users: filterBy('model', 'isNew', false)
});

Another approach is to call createRecord only on save, as opposed to in the model hook for a new user page. If the save results in an API error response, it will still show up in the list because you called createRecord, so it would still be a good idea to filter out new records.