Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Revert syncDirtyAndDestroyed ignoring local/remote options from #65
Browse files Browse the repository at this point in the history
This was ineffective for its purpose and caused local/remote to be
ignored at uninteded times, as in #62, #70.

Revert 25b890f "syncDirty disregards local/remote options too".
Revert 48fb695 "syncDirtyAndDestroyed is not affected by local/remote options"

Conflicts:
	backbone.dualstorage.amd.js
	backbone.dualstorage.coffee
	backbone.dualstorage.js
	spec/backbone.dualstorage.js
  • Loading branch information
nilbus committed Nov 24, 2013
1 parent cd17ff2 commit 22d124a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 58 deletions.
4 changes: 0 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
### master / unreleased

* syncDirtyAndDestroyed disregards local/remote options, because this must be a dualsync operation to act as expected

### 1.1.0 / 2013-11-10

* Add support for RequireJS / AMD
Expand Down
24 changes: 9 additions & 15 deletions backbone.dualstorage.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ Backbone.Collection.prototype.syncDirty = function() {
model = id.length === 36 ? this.where({
id: id
})[0] : this.get(id);
_results.push(model != null ? model.save({
dualsync: true
}) : void 0);
_results.push(model != null ? model.save() : void 0);
}
return _results;
};
Expand All @@ -50,9 +48,7 @@ Backbone.Collection.prototype.syncDestroyed = function() {
id: id
});
model.collection = this;
_results.push(model.destroy({
dualsync: true
}));
_results.push(model.destroy());
}
return _results;
};
Expand Down Expand Up @@ -315,15 +311,13 @@ dualsync = function(method, model, options) {
options.storeName = result(model.collection, 'url') || result(model, 'url');
options.success = callbackTranslator.forDualstorageCaller(options.success, model, options);
options.error = callbackTranslator.forDualstorageCaller(options.error, model, options);
if (!options.dualsync) {
if (result(model, 'remote') || result(model.collection, 'remote')) {
return onlineSync(method, model, options);
}
local = result(model, 'local') || result(model.collection, 'local');
options.dirty = options.remote === false && !local;
if (options.remote === false || local) {
return localsync(method, model, options);
}
if (result(model, 'remote') || result(model.collection, 'remote')) {
return onlineSync(method, model, options);
}
local = result(model, 'local') || result(model.collection, 'local');
options.dirty = options.remote === false && !local;
if (options.remote === false || local) {
return localsync(method, model, options);
}
options.ignoreCallbacks = true;
success = options.success;
Expand Down
19 changes: 10 additions & 9 deletions backbone.dualstorage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Backbone.Collection.prototype.syncDirty = ->

for id in ids
model = if id.length == 36 then @where(id: id)[0] else @get(id)
model?.save dualsync: true
model?.save()

Backbone.Collection.prototype.syncDestroyed = ->
url = result(@, 'url')
Expand All @@ -25,7 +25,7 @@ Backbone.Collection.prototype.syncDestroyed = ->
for id in ids
model = new @model({id: id})
model.collection = @
model.destroy dualsync: true
model.destroy()

Backbone.Collection.prototype.syncDirtyAndDestroyed = ->
@syncDirty()
Expand Down Expand Up @@ -226,16 +226,17 @@ dualsync = (method, model, options) ->
options.success = callbackTranslator.forDualstorageCaller(options.success, model, options)
options.error = callbackTranslator.forDualstorageCaller(options.error, model, options)

unless options.dualsync
# execute only online sync
return onlineSync(method, model, options) if result(model, 'remote') or result(model.collection, 'remote')
# execute only online sync
return onlineSync(method, model, options) if result(model, 'remote') or result(model.collection, 'remote')

# execute only local sync
local = result(model, 'local') or result(model.collection, 'local')
options.dirty = options.remote is false and not local
return localsync(method, model, options) if options.remote is false or local
# execute only local sync
local = result(model, 'local') or result(model.collection, 'local')
options.dirty = options.remote is false and not local
return localsync(method, model, options) if options.remote is false or local

# execute dual sync
options.ignoreCallbacks = true

success = options.success
error = options.error

Expand Down
24 changes: 9 additions & 15 deletions backbone.dualstorage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions spec/backbone.dualstorage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 22d124a

Please sign in to comment.