facebookexperimental/Recoil

Implement native map and bind functions for RecoilState

Open

#317 opened on Jun 12, 2020

View on GitHub
 (13 comments) (2 reactions) (1 assignee)JavaScript (19,428 stars) (1,151 forks)batch import
enhancementhelp wanted

Description

Having a correctly implemented map and bind for a type allows for very powerful abstractions and data transformations.

I have an implementation that given a recoil value it creates a selectorFamily that accepts a lifted function (via constSelector), which then fetches the dependencies, and then returns the new value.

Bind we somewhat get for free as recoil automatically flattens recoil values, so it's the same logic as map.

I'm not terribly confident that this can't somehow cause name conflicts at some point, and having a native implementation of these functions would be great.

I think this also ties in a bit with #314 as ideally the mapped value wouldn't cause a re-render when the parent changes if the resulting output didn't change (such as a simple number atom that had something like this applied: myAtom.map(x => x * 0)

Contributor guide