This repository was archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
parse / toJSON applied inconsistent #111
Copy link
Copy link
Open
Description
The parse and toJSON methods are not applied consistent.
- parseBeforeLocalSave should be defined on the model and is always invoked before the server response is saved in the local storage. This is not the case when a collection is fetched (the method is not invoked on the models).
- parse: Is always invoked when a record has been read from the local storage. It is not applied when the record has not bean read from localStorage. When a new model has been created, then the new model (initialized from it's default) value is passed to the parse method. But this is neither a server response nor a result from the local storage
I would expect:
- parseBeforeLocalSave: Is always invoked when we get a result from the server and before we write it to the localStorage. Maybe we should define this method as "static" so it's not based on an instance and you can invoke it using collection.model.parseBeforeLocalSave. The result of this method should be passed to the new collection.model(parsedAttributes)
- parse: Should always be invoked if we read something fron localStorage. In all other cases it should not be invoked (e.g. create new model from defaults)
- toJSON: Should only be invoked when we write a model to the localStorage or the server. It might be appropriate that we have here an additional overload toJSONBeforeRemote to allow the adoption of the server schema...