MCPcopy
hub / github.com/jeromegn/Backbone.localStorage / create

Method create

src/localstorage.js:64–75  ·  view source on GitHub ↗

Add a new model with a unique GUID, if it doesn't already have its own ID * @param {Model} model - The Backbone Model to save to LocalStorage * @returns {Model} The saved model

(model)

Source from the content-addressed store, hash-verified

62 * @returns {Model} The saved model
63 */
64 create(model) {
65 if (!model.id && model.id !== 0) {
66 model.id = guid();
67 model.set(model.idAttribute, model.id);
68 }
69
70 this._setItem(this._itemName(model.id), this.serializer.serialize(model));
71 this.records.push(model.id.toString());
72 this.save();
73
74 return this.find(model);
75 }
76
77 /** Update an existing model in LocalStorage
78 * @param {Model} model - The model to update

Callers 2

syncFunction · 0.80

Calls 5

_setItemMethod · 0.95
_itemNameMethod · 0.95
saveMethod · 0.95
findMethod · 0.95
guidFunction · 0.90

Tested by

no test coverage detected