This class can be used on a DS.Model to add a saveBulk functionality.

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 Model, { attr } from '@ember-data/model';
import { ModelBulkSaver } from 'ember-indexeddb/utils/model-bulk-saver';

export default class extends Model {
  @attr('string') title;
  modelBulkSaver = new ModelBulkSaver(this);
}

Now, you can bulk save this model like this:

let promise1 = model1.modelBulkSaver.saveBulk();
let promise2 = model2.modelBulkSaver.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.

Show:
_markAsError () private

Manually mark the model as having an error.

_markAsSaved () private

Manually mark the model as saved.

cloneDeep
(
  • obj
)
Object
public

Provided by the Services module.

Defined in addon/utils/clone-deep.js:15

Deep-clone an object.

Parameters:

  • obj Object

    An object to clone deeply

Returns:

Object:

The cloned object

saveBulk
(
  • modelName
  • model
)
Promise
public

Save this model, but try to save it together with other objects

Parameters:

Returns: