質問

Ember Data's DS.RESTAdapter includes a bulkCommit property. I can't find any documentation about what this does/means, other than some vague references to batch committing vs bulk committing.

Initially I assumed it would mean I could only update a single record at a time, but I currently have it set to false, and I'm still able to update multiple records at the same time using:

this.get('store').commit();

So what is the difference between setting bulkCommit to false and setting it to true? In what situation would I use one instead of the other?

役に立ちましたか?

解決

The REST adapter supports bulk commits so that you can improve performance when modifying several records at once. For example, let's say you want to create 3 new records.

var tom = store.createRecord(Person, { name: "Tom Dale" });
var yehuda = store.createRecord(Person, { name: "Yehuda Katz" });
var mike = store.createRecord(Person, { name: "Mike Grassotti" });
store.commit();

This will result in 3 API calls to POST '/people'. If you enable the bulkCommit feature

set(adapter, 'bulkCommit', true);
var tom = store.createRecord(Person, { name: "Tom Dale" });
var yehuda = store.createRecord(Person, { name: "Yehuda Katz" });
var mike = store.createRecord(Person, { name: "Mike Grassotti" });
store.commit();

then ember-data will make just one API call to POST '/people' with details for all 3 records. Obviously not every API is going to support this, but if yours does it can really improve performance.

AFAIK there is not documentation for this yet but you can see it working in the following unit test: creating several people (with bulkCommit) makes a POST to /people, with a data hash Array

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top