Giter Club home page Giter Club logo

Comments (9)

nilbus avatar nilbus commented on September 18, 2024

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.

t3living avatar t3living commented on September 18, 2024

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.

nilbus avatar nilbus commented on September 18, 2024

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.

t3living avatar t3living commented on September 18, 2024

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.

t3living avatar t3living commented on September 18, 2024

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.

t3living avatar t3living commented on September 18, 2024

Could it be that
line 332 responseModel = modelUpdatedWithResponse(new collection.model, resp);

should be responseModel = modelUpdatedWithResponse(new collection.model, i);

from backbone.dualstorage.

nilbus avatar nilbus commented on September 18, 2024

@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.

nilbus avatar nilbus commented on September 18, 2024

@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.

t3living avatar t3living commented on September 18, 2024

This appears to fix the issue.

from backbone.dualstorage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.