This repository was archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
API: First-class modules for components #28
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: Currently, we have no way to distinguish whether a component came from the same 'component class' today. This is important when determining whether to reuse state/effects. #26 went a step forward but the API is a bit clunky:
I'm proposing moving to a new API for creating components, using first-class modules - a function that returns a module.
This allows us to do the following:
The new syntax would be:
module ComponentWrappingB =
(val component((render, ~x, ~children, ()) =>
render(() => {
}, ~children);
));
The
component
function creates the module (val
unpacks it), and there would be a render function passed to the component.And could be used as
<ComponentWrappingB x />
.The anatomy of the function would be:
I think this is a step in a better direction, but I'd be interested to see if there is a way we could scrap that
render
function. A potential point of confusion I could see is perhaps users putting hooks outside therender
block - we should make sure that throws.