-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix laws and simplify implementation #25
base: v1
Are you sure you want to change the base?
Conversation
Right. The obvious name for the method is |
maybe you want to lift the component to another type where map works from Component to Component rather than from Element to Element? a = ReactDream(props => </div>)
b = HOC(a)
b.map(hoc1).map(hoc2) |
Right. 🤦♂️ 🤦♀️ this is Applicative, but on the identity functor implementation of |
API plan update: import ReactDream, { ReactBox } from 'react-dream'
ReactDream.Stateless(({ title }) => <h1>{title}</h1>)
.map(element => <div>{element}</div>)
.contramap(({ language }) => ({
title: language === 'en' ? 'Hello' : 'Hola'
}))
.enhance(
withState('updateTitle', 'title', 'Hola')
)
.name('Header')
ReactDream.Stateful(class extends Component {})
.map() // not optimal!
ReactDream.Stateful(class extends Component {})
.toStateless()
.map() // optimal but verbose
const withChildren = (Parent, Up, Down) =>
ReactDream.Stateless(({ parent, up, down }) =>
<Parent.Component {...parent}>
<Up {...up} />
<Down {...down} />
</Parent.Component>
)
withChildren(
Header,
Title,
Tagline
)
.contramap()
// will build a Stateful
ReactDream(class extends Component {})
// will build a Stateless
ReactDream(props => <br />)
ReactDream(props => <hr />)
.asBox()
.map()
ReactBox(props => <hr />)
.asDream()
.map()
// Equivalences
ReactDream(x).enhance(f) == ReactDream(x).asBox().map(f).asDream()
ReactBox(x).map(f).asDream() == ReactDream(x).enhance(f)
ReactBox.of(f).ap(x) == ReactBox(x).map(f)
ReactBox.of(f).ap(ReactDream(x).asBox()) == ReactBox.of(f).apDream(ReactDream(x)) Keys:
|
I’m not sure about the names |
Change roadmap:
|
And for the next iteration:
|
.promap
was not following Profunctor laws because.map
was acting on the component as-ifReactDream
was the identity Functor, without any extra insights into the type. This is now fixed, but the consequence is that there are two breaking changes 💥:.map
acts on the result of running the component, so the React element it outputs..promap
’s second argument acts on the element as well.Another effect of this is that there now no helper to apply regular higher-order components to the component inside the ReactDream. So we need a new one.
Since it is still an implementation of Functor, it could be called
.map2
. It’s not a fantastic name, but it’s accurate. It could probably have an alias. Quick alias brainstorm:.hoc
.wrap
.update
Quick realization: it might be that HoCs need their own Fantasy Land type, since they do form a Category / Arrow.