Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
model.save() with promise
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
You can’t perform that action at this time.