public
Last active

Flow - Sequential control flow

  • Download Gist
flow.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11
// After.flow https://github.com/Raynos/after.js#flow
function flow(array, context) {
array.reduce(function (memo, outer) {
return function (inner) {
memo.call(context, function () {
var args = [].slice.call(arguments).concat(inner)
outer.apply(context, args)
})
}
})()
}
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// http://jsfiddle.net/cxy4p/15/
var stack = [
function (next) {
console.log(1)
console.log(this.foo === "bar")
next("foo")
},
function (foo, next) {
console.log(2)
console.log(this.foo === "bar")
console.log(foo === "foo")
next("bar")
},
function (bar, next) {
console.log(3)
console.log(this.foo === "bar")
console.log(bar === "bar")
}
]
function runStack(context, stack) {
stack.reduce(function (memo, outer) {
return function (inner) {
memo.call(context, function () {
var args = [].slice.call(arguments).concat(inner)
outer.apply(context, args)
})
}
})()
}
 
runStack(stack, { foo: "bar" })
‚Äč

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.