Created
September 9, 2014 17:32
-
-
Save kixxauth/e41e6d0ae9e15972fcd5 to your computer and use it in GitHub Desktop.
model.save() with promise
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
save: (data, options = {}) -> | |
entity = @ | |
isNew = @isNew() | |
success = _.bind(@saveSuccess, @, isNew, options.collection, options.callback) | |
error = _.bind(@saveError, @) | |
promise = new Promise (resolve, reject) -> | |
_.defaults options, | |
wait: true | |
success: -> | |
success.apply(@, arguments) | |
resolve(entity) | |
error: (entity, response) -> | |
App.log.error('API Sync Error in loadRelations():', response) | |
error.apply(@, arguments) | |
#reject(new Error('API Sync Error in relations')) | |
err = new Error('API Sync Error ') | |
err.response = response | |
reject(err) | |
@unset('_errors') | |
super(data, options) | |
return promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment