-
Notifications
You must be signed in to change notification settings - Fork 108
Destroyed model not being cleared after online sync #146
Description
Let's say I have POSTed an item and am online.
I go offline and delete it, and then go back online.
The item is deleted from the server. So far so good.
Then I go offline and back online. A syncDirtyAndDestroyed is triggered and the server tries to delete the item that it already deleted.
So it looks like after the online sync, the destroyed model id isn't being cleared from the store.
I will post more info later today.
Edit:
syncDirtyAndDestroyed is called which in turn calls syncDestroyed. After the model has been destroyed on the server, I would expect storeName_destroyed to not exist.
syncDestroyed gets the destroyed models (local not online it seems) by calling localStorage.getItem((getStoreName(this)) + "_destroyed"); under Backbone.Collection.prototype.syncDestroyed.
This shouldn't find anything, but it does, suggesting that localStorage.removeItem is not called.
I found localStorage.removeItem in two places - once when Store.prototype.clear is called and once when Store.prototype.destroy(model) is called, the latter I think is the one that is important here.
So when is store.destroy being called?
I would expect this to be called after the online sync is complete. (delete offline - removed from localstorage; go online - syncDestroyed - finds a _destroyed item and deletes from server; that model is removed so no model belongs to storeName_destroyed anymore; offline; online - syncDestroyed - find nothing).
It is being called in two places: Backbone.LocalStorage.sync and localsync.
I don't quite understand why a local sync should remove that item rather than an online sync.
What am I missing?
Though I understand you're busy, comments in the code would help.