pfgray / chainable-components Goto Github PK
View Code? Open in Web Editor NEWA composable API for reusable React code.
License: MIT License
A composable API for reusable React code.
License: MIT License
I'd like to have direct replacements for or at least an explanation of how one would emulate every hoc from recompose, as that library is so prevalent
I took a cursory glance at the documentation and came up with this graph:
emoji | meaning |
---|---|
โ | covered |
๐ง | feasible, not implemented yet |
๐ค | need to think on it |
๐ง | ๐ง |
hoc | explanation | |
---|---|---|
โ | mapProps() | this is just cc.map(a => b) |
โ | withProps() | this is just CC.of({}) |
๐ค | withPropsOnChange() | |
๐ค | withHandlers() | |
โ | defaultProps() | is just CC.of({}) |
โ | renameProp() | is just cc.map(a => b) |
โ | renameProps() | is just cc.map(a => b) |
โ | flattenProp() | is just cc.map(a => b) |
โ | withState() | |
๐ค | withStateHandlers() | |
๐ง | withReducer() | |
โ | branch() | is just fork() |
โ | renderComponent() | is just fork(true ), maybe could add a special case? |
โ | renderNothing() | is just fork(true, () => null |
๐ง | shouldUpdate() | |
โ | pure() | is just pure() โฆ not sure this is a good one to promote, though? |
โ | onlyUpdateForKeys() | is just pure() |
๐คทโโ๏ธ | onlyUpdateForPropTypes() | |
๐ง | withContext() | |
๐ง | getContext() | |
โ | lifecycle() | withLifecycle() |
๐ง | toClass() | |
โ | toRenderProps() | |
โ | fromRenderProps() |
For the "handlers" hocs, I think it makes the most sense to just implement something like the useCallback
hook, and then they are just different mappings/combinations of that chainable.
I just heard about this library on the react round up podcast.
It's awesome I really like what this library is doing.
I have one concern and that is the use of the ap method
ap from a functional programming perspective should have the type signature
ap :: F( A -> B ) -> F( A ) -> F( B )
So in a chainable component it should return a chainable
The ap defined in the library may make more sense being call renderWith
The applicative interface would also be an excellent addition to help combine two independant
Chainables
From:
const withTwoState = props => {
return (
<WithState initial={0}>
{outer => (
<WithState initial={42}>
{inner => (
props.children({inner, outer})
)}
</WithState>
)
</WithState>
);
}
With Chain:
const withTwoState =
withState({initial: 0}).chain(outer =>
withState({initial: 42}).map(inner =>
({inner, outer})
)
)
Using the the applicative interface you can tidy it up
With Ap:
Chainable.of( outer => inner => ({ outer, inner }))
.ap(withState({initial: 0}))
.ap(withState({initial: 42}))
Would it be possible for .Do to accept a generator function?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.