data-point
data-point copied to clipboard
helper function for composing synchronous reducers
Problem description:
By design DataPoint transformations are asynchronous, this provides maximum flexibility for writing your code but it also means that there are some things we must take into account and some patterns to be avoided to provide the best performance.
Chaining multiple synchronous function reducers are considered an anti-pattern and should be avoided whenever possible.
We can/could use _.flow to achieve this, but we lose the Accumulator value because only the first parameter will be passed to the chain of functions.
Suggested solution:
Create/expose a helper function that will allow the developer to chain multiple functions and pass the output of F to the input of F +1 and carry on the Accumulator object across the execution as the second parameter to each reducer (as it should be expected).
Draft:
function composeReducers(reducers...) {
return (input, acc) {
return reducers.reduce((output, currentReducer) => {
return currentReducer(output, acc)
}, input)
}
}
AC:
- expose under require('data-point/helpers')
- do not support async code