Skip to content

Commit

Permalink
Pass in the options map
Browse files Browse the repository at this point in the history
Otherwise events get fired even though `{silent: true}` was passed in
when creating an object
  • Loading branch information
jcbrand committed Oct 24, 2018
1 parent 3352b06 commit 03bfa13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.0.5 (2018-10-21)

- Pass along the `options` map. Otherwise events fire even though
`{silent: true}` was passed to the `Collection.prototype.create` method.

## 0.0.4 (2018-10-21)

- Don't return boolean on `update` and `create`, otherwise the `model.changed`
Expand Down
18 changes: 9 additions & 9 deletions backbone.browserStorage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Backbone localStorage and sessionStorage Adapter
* Version 0.0.3
* Version 0.0.4
*
* https://github.com/jcbrand/Backbone.browserStorage
*/
Expand Down Expand Up @@ -55,11 +55,11 @@ function _browserStorage (name, serializer, type) {
this.name = name;
this.serializer = serializer || {
serialize: function(item) {
return _.isObject(item) ? JSON.stringify(item) : item;
return _.isObject(item) ? JSON.stringify(item) : item;
},
// fix for "illegal access" error on Android when JSON.parse is passed null
deserialize: function (data) {
return data && JSON.parse(data);
return data && JSON.parse(data);
}
};

Expand Down Expand Up @@ -95,10 +95,10 @@ var _extension = {

// Add a model, giving it a (hopefully)-unique GUID, if it doesn't already
// have an id of it's own.
create: function(model) {
create: function(model, options) {
if (!model.id) {
model.id = guid();
model.set(model.idAttribute, model.id);
model.set(model.idAttribute, model.id, options);
}
this.store.setItem(this._itemName(model.id), this.serializer.serialize(model));
this.records.push(model.id.toString());
Expand Down Expand Up @@ -206,13 +206,13 @@ Backbone.BrowserStorage.sync = Backbone.localSync = function(method, model, opti
resp = model.id !== undefined ? store.find(model) : store.findAll();
break;
case "create":
resp = store.create(model);
resp = store.create(model, options);
break;
case "update":
resp = store.update(model);
resp = store.update(model, options);
break;
case "delete":
resp = store.destroy(model);
resp = store.destroy(model, options);
break;
}

Expand All @@ -225,7 +225,7 @@ Backbone.BrowserStorage.sync = Backbone.localSync = function(method, model, opti

if (resp) {
if (options && options.success) {
options.success(resp);
options.success(resp, options);
}
if (syncDfd) {
syncDfd.resolve(resp);
Expand Down

0 comments on commit 03bfa13

Please sign in to comment.