This mixin can be used on a DS.Model to add a saveBulk
function.
Saving a lot of data at the same time can be quite inefficient. To solve this issue, you can use the provided model-bulk-save
mixin on your ember-data models:
import DS from 'ember-data';
import ModelBulkSaveMixin from 'ember-indexeddb/mixins/model-bulk-save';
export default DS.Model.extend(ModelBulkSaveMixin, {
name: DS.attr('string')
});
Now, this model will have a new function bulkSave()
:
let promise1 = model1.saveBulk();
let promise2 = model2.saveBulk();
In the above example, promise1
and promise2
would actually be the same promise, and both of these items would be saved in one transaction. This waits for 100ms before resolving, * so every model that calls saveBulk
in this time period will be saved in the same transactions. Note that this function will resolve with all the saved objects.