Last active
December 15, 2016 23:11
-
-
Save k-fish/03ea632094173eba4ce03b81ce05991f to your computer and use it in GitHub Desktop.
Example Waterfall + no generators
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
import Ember from 'ember'; | |
const { RSVP } = Ember; | |
function waterfallWrapper(objectArray = [], wrappingFunction) { | |
return new RSVP.Promise((resolve, reject) => { | |
let index = 0; | |
function promiseNext(promise) { | |
//maybe do an assert that it's a promise | |
promise.then((result) => { | |
if (index == objectArray.length - 1) { | |
return resolve(result); | |
} | |
index = index + 1; | |
const promise = wrappingFunction.call(this, objectArray[index]); | |
promiseNext(promise); | |
}).catch(reject); | |
}; | |
const promise = wrappingFunction.call(this, objectArray[index]); | |
promiseNext(promise); | |
}); | |
}; | |
const vars = ['red', 'banana', 'roger']; | |
const requestbin = "http://requestb.in/1j3mooh1"; | |
export default Ember.Controller.extend({ | |
doSomething(someData) { | |
}, | |
actions: { | |
startWaterfall() { | |
waterfallWrapper(vars, (someData) => { | |
return new RSVP.Promise((resolve, reject) => { | |
setTimeout(() => { | |
this.set('display', someData); | |
resolve(); | |
}, 500); | |
}); | |
}); | |
} | |
} | |
}); |
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
{ | |
"version": "0.10.6", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.9.0", | |
"ember-data": "2.9.0", | |
"ember-template-compiler": "2.9.0", | |
"ember-testing": "2.9.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment