parse / toJSON applied inconsistent #111
Comments
Yes, this is a known issue. #53 was open to address this, but I'll keep this open instead as you have described the problem rather nicely. I am tied up working on another feature now, but I would happily review and merge a pull request from you that addresses this problem. |
I'll try to have a look tomorrow. And someone needs to rewrite it in coffee script... |
Feel free to ask about anything you find confusing. On Sat, May 31, 2014 at 3:58 PM, DatenMetzgerX notifications@github.com
|
Coffee Script is confusing ;) One question, when should parse be invoked... From my point of view we should only use parse and toJSON. This means, when we store to localStorage we use toJSON for localStorage and the server backend. When we read from localStorage or from the server we use parse to parse the "persisted" state from the remote site or the offline cached state. In both situation the result is the same. This makes Backbone.dualStorage transparent and doesn't need any additional considerations from the developer.... Have I missed a special case that needs to be handled? Or for what is the additional parseBefore... method? Why would I have two different schema (and parsing logic). |
Issue #2 discusses the rationale for |
Ok, i see the use of the method now.... I think the behavior should be:
The point is, we should never call parse in the dualStorage code, because backbone calls parse itself. If we call it too, its invoked multiple times. This means, we should only work with plain javascript objects when we work with the response and not with models. But we need models to be able to call the localSync "update" method... So I think it's not so easy to fix this... The issue is in the core and not only on the surface. |
I think you're right. For your understanding, I'll explain our previous rationale for working with the model instead of the JSON/attributes object. In order to know what attribute is the id to use as a storage key, we must know the model prototype's Right now we call As you point out, we then take these parsed attributes and save them locally, which then later get parsed a 2nd time when they get fetched from localstorage. Also as you point out, I think that moving away from using the model instance and toward using the attributes object paired with the idAttribute would allow us to solve the double parse problem. |
Using Backbone.Model instead of the model type, for compatibility with Backbone-relational
The parse and toJSON methods are not applied consistent.
I would expect:
The text was updated successfully, but these errors were encountered: