We have discovered some files in our app that are using the EOL React library recompose.
After looking into function composition, It sounds like something Javascript is able to do natively
Assuming foo
and bar
are Higher Order Functions(Components) that both return a function that takes another function.
Would someone be able to explain the difference between using a function to compose other functions like this:
compose(foo(arg), bar(arg2));
And just combining the functions without a library like this:
foo(arg)(bar(arg2))
The docs for compose
read:
Use to compose multiple higher-order components into a single higher-order component. This works exactly like the function of the same name in Redux, or lodash's flowRight().
And the docs for lodash/flowRight read:
Creates a function that returns the result of invoking the given functions with the this binding of the created function, where each successive invocation is supplied the return value of the previous.
So it sounds like the only difference is what this
binding is supplied to each function invocation - is there any other difference between the two?