Skip to content

Instantly share code, notes, and snippets.

@mkozhukharenko
Created May 15, 2017 07:35
Show Gist options
  • Save mkozhukharenko/ee0681928304a8018fc345257327a3e1 to your computer and use it in GitHub Desktop.
Save mkozhukharenko/ee0681928304a8018fc345257327a3e1 to your computer and use it in GitHub Desktop.
let compose = (middlewares) => {
return function () {
return dispatch(0)
function dispatch(i) {
let fn = middlewares[i]
if (!fn) {
return
}
fn(function next() {
return dispatch(i + 1)
})
}
}
}
var app1 = (subapp) => {
console.log('start', 1);
subapp();
console.log('finish', 5);
}
var app2 = (subapp) => {
console.log(2);
subapp();
console.log(4);
}
var app3 = (subapp) => {
subapp()
console.log(3);
}
compose([app1, app2, app3])();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment