samedi 30 janvier 2016

How to unload a record in Ember 2.3.0?

I am upgrading an Ember 1.13.0 application to Ember 2.3.0 and I'm facing a little issue where I am unable to unload a record from the Data Store without causing Ember to make a HTTP request. I do not want to delete the record in the server. I simply want to remove it from Ember Data Store.

I was using the following Ember DS.Store API: http://ift.tt/1slRQha in Ember 1.13.0 and it worked fine. Sample:

this.store.find('post', 1).then(function(post) {
  this.store.unloadRecord(post);
});

After upgrading to 2.3.0, when I monitor the network tab in Chrome, Ember is making a GET request to find the record and then unload it. Because it fails to find (our server does not have an API to match this call), it doesn't unload the record and the changes don't appear in the UI.

I tried to fix this by instead doing something like:

this.store.peekAll('posts').findBy('id', 1).then(function(post) {
    this.store.unloadRecord(post);
});

but this doesn't seem to work. What is the right way to unload a record from Ember Data without making HTTP calls? Thanks.




Aucun commentaire:

Enregistrer un commentaire