Ember Data v1.0.0-beta.14 released


Due to a problem in the release step when beta.13 was released, we have removed beta.13 from npm and released beta.14 instead. You can use this version whether you are using npm and ember-cli, rubygems or bower.Note that the build is always available as a static file in emberjs.com/builds.

Improve

Igor Terzic, David Hamilton, with Stephen Penner A lot of progress has been made in improving performance around how the relationships in Ember Data work together. These performance changes have a broad impact on everything you do in Ember Data: query records, push records to storage, and create records. Since everyone on the Ember Data team is developing a real application, we tested these changes in our application and saw improvements in pushing and creating records to the store averaged 50% or more.

Major changes

store.update() Deprecated

Make a call store.update() Deprecated store.push()
Now process part of the payload:

var post = store.push('post', {
  id: 1,
  title: 'Ember.js is fantastic',
  author: 'Tomster'
});

post.get('title'); // => 'Ember.js is fantastic'
post.get('author'); // => 'Tomster'

store.push('post', { id: 1, author: 'Tom Dale' });

post.get('title'); // => 'Ember.js is fantastic'
post.get('author'); // => 'Tom Dale'

This also means that the missing attributes in the load will no longer be reset, but will remain unchanged.

If you need to reset the value to null, you should have your server explicitly send back the null value in the payload:

{
  "person": {
    "firstName": null,
    "lastName": null
    "role": "Computer Science Pioneer"
  }
}

If you cannot change your API and you want this behavior, you can create a serializer and execute the logic yourself:

// app/serializers/person.js
// or App.PersonSerializer if you aren't using Ember CLI
export default DS.RESTSerializer.extend({
  normalize: function(type, hash, prop) {
    hash = this._super(type, hash, prop);
    if (!hash.hasOwnProperty('firstName')){
      hash.firstName = null;
    }
    if (!hash.hasOwnProperty('lastName')){
      hash.lastName = null;
    }
    return hash;
  }
});

Or, if you want to restore the old behavior of all models:

// app/serializers/application.js
// or App.ApplicationSerializer
export default DS.RESTSerializer.extend({
  normalize: function(type, hash, prop) {
    hash = this._super(type, hash, prop);
    type.eachAttribute(function(key) {
      if (!hash.hasOwnProperty(key)) {
        hash[key] = null;
      }
    }, this);
    return hash;
  }
});

Special thanks to

Special thanks to shipyard Sponsor Igor in December!



Leave a Reply

Your email address will not be published. Required fields are marked *