Skip to content
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

Introduce differentiated constructors #23

Open
wants to merge 1 commit into
base: attempt-removal-of-duplication
Choose a base branch
from

Conversation

xaviervia
Copy link
Owner

Since stateless and stateful React components require different strategies when composing them, it seems reasonable to have different data constructors for the two types.

The proposal is to have

import { Stateless, Stateful } from 'react-dream'

const Pure = Stateless(props => <h1>Hello</h1>)
const ClassComponent = Stateful(class extends Component { ... })

Each constructor would have different implementations for contramap and any other function that requires discriminating between the two.

Additions

  • toStateless: that will be a no-op for Stateless, but will wrap the Stateful with a function and return a Stateless instance
  • cata and synonym either: case analysis, based on the Fantasy Land type proposals Add types fantasyland/fantasy-land#281 and Add polymorphic type catamorphisms fantasyland/fantasy-land#280 respectively
  • match for case analysis with tags (.match({ Stateless: x => x, Stateful: x => x }))
  • isStateless : ReactDream -> Boolean
  • The main ReactDream entrypoint will detect the component type and use the corresponding data constructor.

To do

  • Fully implement and test the data constructors
  • Test contramap for both implementations separately
  • Implement the detection of the React component type in the main ReactDream function
  • Implement toStateless
  • Implement cata + either
  • Implement match

@xaviervia xaviervia added this to the v1 milestone Jul 28, 2018
@xaviervia xaviervia added the wip label Jul 28, 2018
@xaviervia xaviervia changed the base branch from master to attempt-removal-of-duplication July 28, 2018 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant