This repository has been 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 #113
Open
MichaReiser
wants to merge
10
commits into
nilbus:master
Choose a base branch
from
kwsoft:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c7a36e5
parse / toJSON applied inconsistent #111
6cbbe2d
parse / toJSON applied inconsistent #111
5fbc1ba
Removed idea code style settings
b983cc2
parse / toJSON applied inconsistent #111 #113
974b60a
Fix typo
733241d
Set the id silently when a model is created
64468dc
Revert "Set the id silently when a model is created"
74e4753
Fix for success callbacks that have not been invoked
3ca7dc0
Delete idea files
836646d
Merge fix for destroyed models with tem pid
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,7 +212,9 @@ localsync = (method, model, options) -> | |
store.clean(model, 'dirty') | ||
else | ||
store.clean(model, 'destroyed') | ||
response = response.attributes if response?.attributes | ||
|
||
# Returne the serialized form of the model, this form is passed to parse | ||
response = response.toJSON() if response?.attributes | ||
|
||
unless options.ignoreCallbacks | ||
if response | ||
|
@@ -225,11 +227,13 @@ localsync = (method, model, options) -> | |
# Helper function to run parseBeforeLocalSave() in order to | ||
# parse a remote JSON response before caching locally | ||
parseRemoteResponse = (object, response) -> | ||
if not (object and object.parseBeforeLocalSave) then return response | ||
if _.isFunction(object.parseBeforeLocalSave) then object.parseBeforeLocalSave(response) | ||
if _.isFunction(object.parseBeforeLocalSave) | ||
object.parseBeforeLocalSave response | ||
else | ||
response | ||
|
||
modelUpdatedWithResponse = (model, response) -> | ||
modelClone = new Backbone.Model | ||
modelClone = new model.constructor | ||
modelClone.idAttribute = model.idAttribute | ||
modelClone.set model.attributes | ||
modelClone.set model.parse response | ||
|
@@ -278,18 +282,23 @@ dualsync = (method, model, options) -> | |
success localsync(method, model, options) | ||
else | ||
options.success = (resp, status, xhr) -> | ||
# for backwards compatiblity, should not be needed anymore | ||
resp = parseRemoteResponse(model, resp) | ||
|
||
if model instanceof Backbone.Collection | ||
collection = model | ||
|
||
# parse the model using the parse method of the collection | ||
# can be used to adjust the schema of collection elements (not for a single element) | ||
workingRespone = collection.parse(resp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine this should be |
||
idAttribute = collection.model.prototype.idAttribute | ||
localsync('clear', collection, options) unless options.add | ||
for modelAttributes in resp | ||
for modelAttributes in workingRespone | ||
model = collection.get(modelAttributes[idAttribute]) | ||
if model | ||
responseModel = modelUpdatedWithResponse(model, modelAttributes) | ||
else | ||
responseModel = new collection.model(modelAttributes) | ||
responseModel = new collection.model(modelAttributes, { parse: true }) | ||
localsync('update', responseModel, options) | ||
else | ||
responseModel = modelUpdatedWithResponse(model, resp) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Backbone.Model
here was intentional, because Backbone-relational has problems when there is more than one instance of the same model with the same id (see #75). This avoids that problem by not using the model's constructor which may inherit from the backbone-relational model prototype.