Created
April 20, 2017 06:05
-
-
Save kishanio/03decb070cd46d2f225f2d5f085c2e23 to your computer and use it in GitHub Desktop.
Parse : Chaining Promises in Series
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
// File : utils/api.js | |
var Api = {}; | |
Api.NewNote = function(note,file) { | |
var file = new Parse.File(file.name, file); | |
return file.save().then(function(file) { | |
var promise = Parse.Promise.as(); | |
promise = promise.then( function() { | |
var NewNote = new Note(); | |
if ( file.name ) { | |
NewNote.set('file', file); | |
} | |
return NewNote.save(note); | |
}); | |
return promise; | |
}); | |
} | |
export default Api; | |
// Usage | |
import Api from 'utils/Api'; | |
Api.NewNote(newNote, this.state.file).then(function(note){ | |
this.resetState(); | |
this.props.onNewNote(note); | |
}.bind(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment