Created
May 15, 2017 07:35
-
-
Save mkozhukharenko/ee0681928304a8018fc345257327a3e1 to your computer and use it in GitHub Desktop.
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
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