-
Notifications
You must be signed in to change notification settings - Fork 106
Add support for setting collection with a promise #103
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -274,13 +274,21 @@ dualsync = (method, model, options) -> | |
| collection = model | ||
| idAttribute = collection.model.prototype.idAttribute | ||
| localsync('clear', collection, options) unless options.add | ||
| for modelAttributes in resp | ||
| model = collection.get(modelAttributes[idAttribute]) | ||
| if model | ||
| responseModel = modelUpdatedWithResponse(model, modelAttributes) | ||
| else | ||
| responseModel = new collection.model(modelAttributes) | ||
| localsync('update', responseModel, options) | ||
|
|
||
| setResp = (resp, model) -> | ||
| for modelAttributes in resp | ||
| model = collection.get(modelAttributes[idAttribute]) | ||
| if model | ||
| responseModel = modelUpdatedWithResponse(model, modelAttributes) | ||
| else | ||
| responseModel = new collection.model(modelAttributes) | ||
| localsync('update', responseModel, options) | ||
|
|
||
| if resp?.done | ||
| do (model) -> resp.done (data) -> setResp(data, model) | ||
|
Owner
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 noticed you added a
Author
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. The closure is needed because |
||
| else | ||
| setResp(resp, model) | ||
|
Owner
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. This indentation also needs to be fixed. |
||
|
|
||
| else | ||
| responseModel = modelUpdatedWithResponse(model, resp) | ||
| localsync('update', responseModel, options) | ||
|
|
||
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.
This is a reminder to either one of us to remove the indentation on this blank line.