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

Feature: Express single child components in the type system #36

Open
bryphe opened this issue May 11, 2019 · 1 comment
Open

Feature: Express single child components in the type system #36

bryphe opened this issue May 11, 2019 · 1 comment

Comments

@bryphe
Copy link
Contributor

bryphe commented May 11, 2019

(Related to the nesting-reconcilers discussion in #30, and the compositional component discussion in revery: revery-ui/revery#489) Also inspired by @jordwalke 's exploration on statically typed React trees: https://github.com/reasonml/reason-react/tree/StaticReactExperiment/explorations

There have been cases that have come up where it'd be nice to make some constraints on the tree at compile-time:

Based on discussion with @wokalski , this seems doable with a PPX

  • Constraints between parent <-> children - Another useful case would be to express that only certain components can be children of a specific parent. An example might be a FlexLayout widget, that can only take Row, Column as first-level children. Other examples could be a <Menu> that only allows <MenuItem /> as children, etc. Fixed in Defunctorize Brisk_reconciler #46.

I think this may be something that could be supported via nested reconcilers - @wokalski mentioned that perhaps we could model this as a type constraint where element('a) is generic, element(menuComponent) is specific to a menu, etc.

@wokalski
Copy link
Member

@bryphe Single child components can only work sensibly with full blown static react. If you use any other approximation it still produces invalid states. i.e.

let customComponent = () => <> <one/> <two/> </>

<Transform>
  <customCompnent />
</Transform>

The second one will be solved with #30

@wokalski wokalski changed the title Feature: Static constraints on children / hierarchy Express single child components in the type system Oct 29, 2019
@wokalski wokalski changed the title Express single child components in the type system Feature: Express single child components in the type system Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants