Comments (4)
Check out Store.clean
and the places where clean
is called, in localsync
update and delete. Once you figure out the scenario that creates this error condition, we can create a failing spec that reproduces it and fix the issue.
from backbone.dualstorage.
If I run syncDirtyAndDestroyed();
should I pass through localsync
function? Because it doesn't.
from backbone.dualstorage.
Backbone.Collection.prototype.syncDirty = (options) ->
store = localStorage.getItem("#{getStoreName(@)}_dirty")
ids = (store and store.split(',')) or []
for id in ids
@get(id)?.save(null, options)
For each id marked dirty, it tries to get the model from the collection by that id. If a model with that id exists, it will try to save it. Save should call sync, which is overridden to be dualsync.
dualsync = (method, model, options) ->
# ...
# execute only online sync
return onlineSync(method, model, options) if _.result(model, 'remote') or _.result(model.collection, 'remote')
# execute dual sync
# ...
If neither the model nor collection have a truthy remote
property, then it will continue to try to dualsync. Double-check this.
As dualsync executes, localsync
generally always gets called below backbone.dualstorage.coffee:283. Trace the execution to see what's actually happening.
from backbone.dualstorage.
Got it. The response on the PUT call is empty, but status is 200. Backbone handles this as an error but since the error is never logged I didn't know the call was not successful. I fixed this by adding
Backbone.ajax = function() {
var args = Array.prototype.slice.call(arguments, 0);
if (args[0].type === 'PUT') {
args[0].dataType = "text";
}
return Backbone.$.ajax.apply(Backbone.$, args);
};```
This is not a bug in this library. A bit of error feedback would be nice.
from backbone.dualstorage.
Related Issues (20)
- Save as dirty when Backbone model validation fails. HOT 2
- 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.