Skip to content

Instantly share code, notes, and snippets.

@kishanio
Created April 20, 2017 06:05
Show Gist options
  • Save kishanio/03decb070cd46d2f225f2d5f085c2e23 to your computer and use it in GitHub Desktop.
Save kishanio/03decb070cd46d2f225f2d5f085c2e23 to your computer and use it in GitHub Desktop.
Parse : Chaining Promises in Series
// 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