Ember Data v1.0.0-beta.9 released


Since Ember Data v1.0.0-beta.8, many changes have taken place. Since we did not write a blog post for beta.8, this blog post will include the features in beta.8 and beta.9.

New release schedule

Since the first beta version of Ember Data 1.0 was released, Ember Data is usually released when we believe that key features or bug fixes have been merged. Due to the constantly changing nature of Ember Data, we hope to reward Ember Data users for keeping up with changes by providing more frequent versions until a candidate version appears.Starting from Monday, August 18, 2014, Ember Data will release a new beta version Every 3 weeks. These versions will be in Build the page, Bower, Rubygems and soon NPM.

Major changes

Need Object.create shim

Ember Data now needs one Object.create Environmental polyfill
Object.create Or incorrect Object.create Realize as Browser 8. Ember.js will provide Object.create polyfill in 1.8.0.If you are using the stable version of Ember, we recommend that you use
ES5 gasketof es5-sham.js The file is available on NPM and Bower.You can refer to Kangax compatibility table See if you need spacers.

Ember data usage Object.create Realize faster and collision-free caching under the hood.

Use ISO8601 serialized date by default

because Various ways Dates can be serialized through the network, Ember Data decided to use well-known, well-supported and accurate
ISO8601 format.Although the JavaScript programming language has supported ISO8601 strings since then ECMAScript5, Internet Explorer 8 and other environments are not supported Date.prototype.toISOstringHowever, Ember Data does include a shim, so in addition to ensuring that your backend supports ISO8601, you don’t need to work further here.

RESTAdapter.prototype.findMany changed the behavior and method signature

You should see Find many If you overwrite the document findMany The method in the adapter.

HasMany Coalescing now opt in

For more information, see the section on “Merge Find Requests” below. Previously, if you did not sideload the data of the hasMany relationship, but did provide an ID, Ember Data would try to get all records in one request.

E.g:

// Given this payload:
{
  "author": {
    "id": "1",
    "name": "Lon Ingram",
    "post_ids": ["1", "2", "3"]
  }
}

this.store.getById('author', '1').get('posts');

// $.ajax GET /posts?ids[]=1&ids[]=2&ids[]=3

Unless you choose to join, Ember Data will trigger 3 requests:

this.store.getById('author', '1').get('posts');

// $.ajax GET /posts/1
// $.ajax GET /posts/2
// $.ajax GET /posts/3

For more information, see the section on “Merge Find Requests” below.

New features and improvements

Embedded record mixing

Deserialization relationship

Thanks to Igor Terzic, Brendan Mcloughlin and Bill Heaton, DS.EmbeddedRecordsMixin Be extracted DS.ActiveModelSerializer In Ember Data v1.0.0-beta.8, JSONSerializer, RESTSerializer, with ActiveModelSerializer You can easily serialize and deserialize relationships.To use the code in your application, you can include EmbeddedRecordsMixin Enter your serialization program:

App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin);

It means your PostSerializer If they are embedded in the response instead of sideloading, they will now correctly introduce data for the relationship.

For example, here is the previous JSON data response Ember Data expected by the RESTAdapter:

// GET /posts/1
{
  "post": {
    "id": "1",
    "name": "The Mother We Share Lyrics",
    "authorId": "1"
  },
  "authors": [
    {
      "id": "1",
      "name": "CHVRCHES"
    }
  ]
}

this.store.find('post', '1').then(function(post){
  console.log(post.get('author.name')); // => CHVRCHES
});

Now, if you mix in EmbeddedRecordsMixin, EmbeddedRecordsMixin will understand the following payload:

// GET /posts/1
{
  "post": {
    "id": "1",
    "name": "The Mother We Share Lyrics",
    "author": {
      "id": "1",
      "name": "CHVRCHES"
    }
  }
}

this.store.find('post', '1').then(function(post) {
  console.log(post.get('author.name')); // => CHVRCHES
});

These settings are configurable. Please refer to the section on “Serialization Relationships” below.

Serialization relationship

EmbeddedRecordsMixin also supports sending information about the relationship to the server. To override the default value, you can configure EmbeddedRecordsMixin by defining one attrs The object on the serializer definition. For example, to serialize a complete record when serializing to the server:

App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    author: {
      serialize: 'records'
    }
  }
});

var post = this.store.getById('post', '1');
post.set('name', 'Recover Lyrics');
post.save();

// POST /posts/1
{
  "post": {
    "name": "Recover Lyrics",
    "author": {
      "id": "1",
      "name": "CHVRCHES"
    }
  }
}

To see more ways to customize serialization and deserialization behavior, please check file in order to EmbeddedRecordsMixin.

Merge search request

One feature we are particularly excited about is the ability to merge search requests of the same record type.

To introduce this feature, I will explain the basic concept behind Ember.js’ “Run Loop”. In JavaScript code that is usually re-rendered when the data changes, changing the data multiple times in the same round of the JavaScript event loop will result in multiple re-rendering. Ember uses a system called
Afterburner Reduce the number of writes by rendering only once per “run loop”. For more information, you can check the README on Backburner on the repository and check Ember.js Operating cycle guide.

If “Coalescing Find Requests” is not turned on, the previous code will cause multiple network requests:

this.store.find('post', '1');
this.store.find('post', '2');
this.store.find('post', '3');

// $.ajax GET /posts/1
// $.ajax GET /posts/2
// $.ajax GET /posts/3

On the server side, this is often referred to as N+1 query.

By merging (also known as batch processing) these requests, Ember Data will observe that you have requested multiple records of the same type and only send one request instead of three.

this.store.find('post', '1');
this.store.find('post', '2');
this.store.find('post', '3');

// $.ajax GET /posts?ids[]=1&ids[]=2&ids[]=3

Merge search requests are currently closed by default. To open it, you can use the following code:

DS.RESTAdapter.reopen({
  coalesceFindRequests: true
});

To overwrite the way the record was requested, you can overwrite findMany with
findHasMany The method on the adapter.

Ember Inflector is now a standalone package

Ember Inflector is a method of Ember that implements an API compatible with Rails and is used to inflate strings.This provides things like Ember.String.pluralize with
Ember.String.singularize, And hooks to define your own changes. Previously, the Ember Inflector package was included in Ember Data’s repository and was released with Ember Data.It has been pulled to a
Separate repositoryAlthough Ember Inflector is still included in the Ember Data version, you can now use it in projects that do not use Ember Data. Ember Inflector is currently released as a 1.0 semver package.

Ember Inflector string cache

Ember Inflector now caches string lookups by default.This means you should only pay the cost of converting the string (via pluralize with
singularize) Once, because the memory cache is now used to store these values.If you have memory problems, you may want to monitor to find and disable caching by calling Ember.Inflector.inflector.disableCache() At the beginning of the application code.

Improved the uncountable/irregular definition of Singularize

We want to express our deep gratitude Olivia Briggs
Add better support for uncountable/irregular singular words in Ember-Inflector.You should not need to define dasherized with
underscore Your inflection point version.

Turning Point’s Handle Assistant

You can now use pluralize with singularize In your handlebar template:

{{pluralize "octopus"}}
{{singularize "oxen"}}

The Handlebars helpers are bound, so if you bind to properties, they will stay up to date:

{{pluralize type}}

Performance improvement

Thank you Stephen Penner From the Ember.js core team, your application should be faster when used with Ember Data. We also hope that you will try the Ember 1.8 beta version in applications that use Ember Data 1.0.0-beta.9 to get additional performance improvements.

We are about to introduce more performance improvements!Pay close attention to some of Stef’s promises of improvement pushPayload Phone and a Committed to Backburner Improve many hot code paths in Ember Data.

Better support for nested records.

buildURL Now you need a record, if you need to build a nested URL, you can look up the relationship on that record. E.g:

App.CommentAdapter = DS.RestAdapter.extend({
  buildURL: function(type, id, record) {
    return '/posts/' + record.get('post.id') + '/comments/' + id;
  }
})

Added support for preloading records

For more information, please visit Store documents.

Special thanks to

We would like to thank the following members of the Ember.js community for their continued contributions to Ember Data:

  • Igor Terzic as the main contributor of the project (@terzicigor)
  • Brendan McLoughlin (@BezoMaxo) responds and categorizes issues, and contributes documentation, bug fixes and improvements.
  • Ilya Lachenko (@knownasilya)
  • Bradley Pastor (@bradleypriest)
  • Bill Heaton (@pixelhandler)
  • Paul Chavard (@tchak)
  • Sylvain Mina (GH @sly7-7)
  • Sato Ryunosuke (@tricknotes)
  • Excellent work by Alexander de Oliveira (@kurko)
    Embers Local Storage Adapter with
    ember-indexeddb-adapter.
  • Jonathan Collins (Github @jcollins1991)
  • Stefan Penner (@stefanpenner)
  • Tomdale (@tomdale)
  • Yehuda Katz (@wycats)

We would also like to thank Instructure and Precision Nutrition for sponsoring Igor’s development on Ember Data.



Leave a Reply

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