Comments (9)
Thanks @evantishuk, I'll take a look.
from backbone.dualstorage.
Yes, there are definitely callback issues with the 0.9.10 changes, and maybe 0.9.9 too, even though the tests pass with 0.9.9 because of the tests' assumptions around Backbone not changing its API.
The discussion in jeromegn/Backbone.localStorage#63 makes it seem like 0.9.9 and 0.9.10 each send different callback arguments from the previous versions.
dualStorage is not currently consistent with the arguments it sends to its callbacks, varying on the method and storage backend. I think the way forward is to maintain compatibility with older versions of backbone and to follow Backbone and standardize the callback arguments this library sends back.
from backbone.dualstorage.
1.0.0 just came out. Let's shoot for compatibility with 1.0.0 and the earlier versions of backbone that we already support.
from backbone.dualstorage.
Yeah, good policy. Would not be surprised if compatibility with 1.0.0 will also bring it into line with 0.9.9 and 0.9.10 as well--possibly fewer version checks (a la https://github.com/phoey/Backbone.localStorage/commit/bd34c367442f6854c0d5664425ec04c8108a69fe).
from backbone.dualstorage.
@globexdesigns Backbone 0.9.2 is bundled with Backbone.dualStorage in lib/
from backbone.dualstorage.
I examined the callback code for 0.9.2, 0.9.9, 0.9.10, and 1.0.0. These are the changes:
- 0.9.2 starts with remote methods such as fetch, save, etc. that send the arguments (model, resp) to callbacks, and accept the standard $.ajax parameters (data, textStatus, jqXHR)/(jqXHR, textStatus, errorThrown) in its callbacks from sync.
- 0.9.9 sends a 3rd options argument to the success and error callbacks given to remote methods like fetch. This doesn't affect us since we do not implement the remote methods like fetch.
- 0.9.10 changes sync so that it calls the fetch(etc.) success/error callbacks with (model, resp/xhr, options), which allows those methods to call their callbacks with the same arguments. Sync gets resp/xhr from the first parameter in the $.ajax callback.
- 1.0.0 changes sync back to how it was in 0.9.2, passing the
$.sync callback parameters directly into the fetch(etc.) callbacks. However now the fetch(etc.) callbacks accept only the first argument (resp/xhr). This means that Backbone.sync (and its substitutes) no longer have have the responsibility of converting the $ .ajax callback params to the new 0.9.10 fetch callback args. Since sync sends the same first argument again that 0.9.2 and earlier expected in the remote methods, it's much more backward compatible than 0.9.10 was.
from backbone.dualstorage.
Thanks @evantishuk for reporting this
from backbone.dualstorage.
Don't thank me, you did all the work. Thanks for addressing it. I like your solution.
from backbone.dualstorage.
This code snippet causes the fix to fail on Backbone 0.9.10:
var Model = Backbone.Model.extend({
url: '/test',
remote: false,
local: true,
success: function() {},
error: function() {}
});
var model = new Model({name: 'test'});
model.save();
model.save({name: 'asd'});
model.save({name: 'asd3'});
model.save({name: '234234'});
console.log(model.attributes);
TypeError: Cannot call method 'call' of undefined at:
from backbone.dualstorage.
Related Issues (20)
- Save as dirty when Backbone model validation fails. HOT 2
- syncDirtyAndDestroyed() doesn't remove/clear ###_dirty in localStorage HOT 4
- If a collection has never had a model saved successfully to the server, it won't cache failed saves to localStorage HOT 8
- using .toJSON(options) instead of JSON.stringify in create()/update() store methods HOT 1
- "Uncaught TypeError: Cannot read property 'toString' of undefined" when saving without IDs HOT 1
- xhr 200 result of an error HOT 3
- Feature request: add a remote:"never" option per save HOT 4
- Fire event when syncDirtyAndDestroyed is finished HOT 1
- Offline changes with idAttribute seem to break page after refresh HOT 5
- Model.parse should not be called in dualsync HOT 3
- Parsing the string of ids for a collection each time a model updates blocks the main process HOT 1
- Would be better if syncDirty() returned a promise HOT 1
- model id not being set in Store.prototype.create HOT 5
- Destroyed model not being cleared after online sync HOT 2
- Dirty/Destroyed models not be cleared from localStorage after an online sync. HOT 1
- error function not defined HOT 5
- localForage support HOT 1
- QuotaExceededError HOT 1
- Model creation and modification race condition HOT 1
- Fetching remote changes before resolving dirty state HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone.dualstorage.