Skip to content

@Raynos /flow.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Flow - Sequential control flow
// 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)
})
}
})()
}
// 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" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.