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/dynamic element #71

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Feature/dynamic element #71

wants to merge 9 commits into from

Conversation

wokalski
Copy link
Member

@wokalski wokalski commented Dec 17, 2019

Imagine there's no key
It's so yum yum if you try
No conflicts upon us
Elements side by side

Imagine all the components
With typed identities

This PR removes keys and removes lists as the container for sequences of elements. Instead of keys you can use constant identity like so:

let%component reorder = (~flipped=false, ()) => {
  open Components;
  let%hook text1 =
    <movableStateContainer> <Text title="x" /> </movableStateContainer>;
  let%hook text2 =
    <movableStateContainer> <Text title="y" /> </movableStateContainer>;
  flipped ? <> <text1 /> <text2 /> </> : <> <text1 /> <text2 /> </>;
};

Dynamic list API is not done yet but it will be amazing. Believe me.

Btw, if you use the component returned by movableStateContainer multiple times the result is undefined but in the future I'll make it so that all resulting instances will share state but won't share the view.

let%component reorder = (~flipped=false, ()) => {
  open Components;
  let%hook text1 =
    <movableStateContainer> <Text title="x" /> </movableStateContainer>;
   /* Three texts but they share the internal state */
   <> <text1 /> <text1 /> <text1 /> </>;
};

They will be essentially cloned.

@glennsl
Copy link
Collaborator

glennsl commented Jul 10, 2020

Would it be possible to add a phantom type variable to the element type, so that "compound" elements can be distinguished from "simple"/"single" elements? I believe that would allow components to restrict themselves to only accepting a single child. E.g.:

let make = (~children: element(single), ()) => ...

And listToElement, for example, would then be: list(element(_)) => element(compound)

@wokalski
Copy link
Member Author

@glennsl I'm afraid no.

let fragment = <> <ImSingle /> <ImSingle /> </>
<IJustWantOneChild> {fragment} </IJustWantOneChild>

OOps

@glennsl
Copy link
Collaborator

glennsl commented Jul 11, 2020

Couldn't fragment just be element(compound) outright? While that would exclude the possibly valid use of a fragment with a single child, that doesn't seem like a big deal.

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

Successfully merging this pull request may close these issues.

2 participants