From 54fff1d45c025cb029aa84072b4887a34bf43899 Mon Sep 17 00:00:00 2001 From: Edward Anderson Date: Sat, 28 Jul 2012 22:44:23 -0400 Subject: [PATCH] Fix ignoreCallback bug localsync was running callbacks when it was not intended. In ff828fc88, backbone.dualstorage.coffee:228 added: options.ignoreCallbacks = false Changing the options object also affects the other callbacks that use options (such as line 202: localsync('clear', model, options)) since multiple callbacks are defined in the same scope using the same options variable. In my case, the localsync('clear', ...) was called with ignoreCallbacks = false. Since clear doesn't return a response, the error callback would get called once for each collection item every time I would fetch on the collection. --- backbone.dualstorage.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backbone.dualstorage.coffee b/backbone.dualstorage.coffee index d656903..3e4a7f4 100644 --- a/backbone.dualstorage.coffee +++ b/backbone.dualstorage.coffee @@ -213,7 +213,6 @@ dualsync = (method, model, options) -> # remoteOptions.error = (resp) -> # after localsync loads, check to see if we should still remotesync - options.ignoreCallbacks = false options.success = (resp) -> # first fire the success callback which will populate the model success(resp) @@ -222,7 +221,8 @@ dualsync = (method, model, options) -> if _.isUndefined(model.shouldRemoteSync) or (_.isFunction(model.shouldRemoteSync) and model.shouldRemoteSync()) onlineSync(method, model, remoteOptions) - localsync(method, model, options) + optionsWithCallbacks = _(options).chain().clone().extend(ignoreCallbacks: false).value() + localsync(method, model, optionsWithCallbacks) when 'create' options.success = (resp, status, xhr) ->