compose in recompose

Ivan Starkov
Apr 23, 2017 · 1 min read

Recompose is the library I use now in every project of mine.

When I first saw recompose, I immediately had one question — why does a library use the compose function for enhancers composition?

All my previous knowledge about compose told me that evaluation order of composed functions will be unnatural, not the same as code flow.

As an example:

gives the result 4 not 6 because evaluation order is 1 * 2 then 2+ 2

Before writing an issue that usage of flow will be better, I created a fast check, something like:

And got the result on the screen equal to 6 not 4, so the order was natural even compose was used. It was strange and was not expected by me.

At first I decided that library author uses his own handwritten version of compose which is some kind of lodash flow. I was wrong he used lodash/function/compose.

I wrote what I see on the paper in simplified form.

So I got the “right” natural order of operations (x + 2) and then *2, just because Recompose uses composition of enhancers and not the composition of property transformers.

That example somehow changed my mind and because of such “magic” of non magic things I love being a developer ;-).

Big thanks to Anton Shain for looking over this document draft.

Ivan Starkov

Written by

github.com/istarkov