Comments (9)
Hmm, this sounds like #6, which someone reported a long time ago but not many people run into.
You're only seeing the arrays when you examine your localstorage content in the browser inspector, but not when you fetch with Backbone?
from backbone.dualstorage.
Actually, with Backbone, nothing is stored in local store and the models all display as expected.
When I use DualStorage I see that each model is saved as an array, but the models still display as expected in the Backbone UI. Here is a sample of what I have with DualStorage when looking at the localstorage via the browser.
I have shortened the entries for clarity. The REST api is returning a JSON array of models in response to GET
api/facility [{model 1},{model 2}...etc]
Local Storage
UUID-1, UUID-2, UUID-3,... UUID-9
api/facilityUUID-1
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-1"}
api/facilityUUID-2
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-2"}
api/facilityUUID-3
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-3"}
api/facilityUUID-4
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-4"}
api/facilityUUID-5
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-5"}
api/facilityUUID-6
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-6"}
api/facilityUUID-7
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-7"}
api/facilityUUID-8
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-8"}
api/facilityUUID-9
{"0":{"id":"2","name":"Hospital",...},"1":{"id":"3","name":"Center"...}, ...,"7":{"name":"Medical Arts",..."id":"UUID-9"}
from backbone.dualstorage.
I'm thinking of ways this might happen. Tell me if you think any of these might be true. You might consider posting an abbreviated example of your API responses.
- The API response when fetching a facility collection is an object with index keys similar to what you're seeing, like
{"0":{"id":"2","name":"Hospital",...},"1":{...},...}
, rather than the expected array like[{"id":"2","name":"Hospital",...},{...},...]
. If this was the case, it would - The API response when saving a facility contains collection json data rather than only the saved facility json.
Also:
- Are you defining
parse
in either your model or collection? - What version/commit of the dualstorage source are you using?
from backbone.dualstorage.
I appreciate your thoughts on this. I just downloaded DualStorage yesterday, it's version 1.0.1 I'm using Backbone 1.0.0, Marionette 1.1.0 and use the following settings in Backbone.
Backbone.emulateHTTP = true;
Backbone.emulateJSON = false;
the raw API response for fetching a collection using api/facility is:
[{"id":"2","name":"Memorial Hospital Carbondale",.......,"updated_at":"2013-09-24T12:41:08.817Z"},{"id":"3","name":"Center for Medical Arts",.....,"updated_at":"2013-09-24T12:47:33.842Z"},
{"id":"4","name":"Heartland Regional Hospital",...,"updated_at":"2013-09-24T12:50:29.219Z"},
{"id":"5","name":"SI Podiatry",...,"updated_at":"2013-10-22T01:44:52.673Z"},
{"id":"7","name":"Logan Primary-Herrin",..,"updated_at":"2013-09-24T12:44:11.179Z"},
{"id":"8","name":"Herrin Hospital",..,"updated_at":"2013-10-20T22:11:55.915Z"},
{"id":"9","name":"Miners Memorial Hospital",...,"updated_at":"2013-09-24T12:46:54.295Z"},
{"id":"10","name":"Logan Primary - W. Frankfort",...,"updated_at":"2013-09-24T12:45:24.152Z"},{"id":"106","name":"Called & Delivered",...,"updated_at":"2013-10-21T14:51:36.487Z"}]
The raw API response for a PUT is simply the id of the record
I do not use any parse methods in either the collection or the models
from backbone.dualstorage.
Another bit of testing results.
I added a parse : function(response){console.log(response):} to the collection and ran it without dualStorage. The result was an array of objects. [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
I did the same by placing a console.log within parseBeforeLocalSave and ran it with dualStorage the result was also an array of objects. [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
the two arrays look identical from what I can see.
The other odd thing is that the arrays that are getting stored in localStorage are a little irregular they look like this
{"0":{"name":" ", ..},"1":{"name":" ",...},....."9":{"name":" ", ...}, "name":" ", ...., "id":GUID}
every entry is the same pattern with the last set of fields being the data associated with the GUID.
from backbone.dualstorage.
Could it be that
line 332 responseModel = modelUpdatedWithResponse(new collection.model, resp);
should be responseModel = modelUpdatedWithResponse(new collection.model, i);
from backbone.dualstorage.
@t3living yes, thank you! I didn't realize you were on the most recent commit rather than the released version. Pushing a fix shortly.
from backbone.dualstorage.
@t3living Please confirm that this fixes the problem for you, and let me know if you run into anything else. Thanks again!
from backbone.dualstorage.
This appears to fix the issue.
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.