What does this code do with the list of functions?
store = {};
mw = [f1, f2, f3];
ds = mw.map(function (fn) {
return fn.bind(null, store);
});
ds2 = ds.reduceRight(function (dispatch, fn) {
return fn.bind(null, dispatch);
});
it is combining it somehow, but I don't understand the goal. What are requirements for f* functions?
The original functions are curried twice with an argument value: once with store, and the second time with a callback function dispatch, which through reduceRight is a function that refers to the next curried function in the array.
So f* should be functions that take two arguments: the object that plays a role (for anything you want), and the callback function to be called next. The exception to this rule is the last function: it doesn't get a second argument.
Here is an example for those functions:
function f1(store, dispatch) {
store["f1"] = "I";
return dispatch();
}
function f2(store, dispatch) {
store["f2"] = "was";
return dispatch();
}
function f3(store) {
store["f3"] = "here";
return store;
}
var store = {};
var mw = [f1, f2, f3];
var ds = mw.map(function (fn) {
return fn.bind(null, store);
});
var ds2 = ds.reduceRight(function (dispatch, fn) {
return fn.bind(null, dispatch);
});
// ds2 is a function, that chains all given functions together
// through the callback system that they implement:
console.log(ds2());