Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Hooks with slots #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/dom/WebReconciler.re
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module Reconciler = {
};

/* Step 5: Hook it up! */
module JsooReact = Reactify.Make(Reconciler);
module JsooReact = Reactify__ReactifyExperimental.Make(Reconciler);
open JsooReact;

/* Define our primitive components */
Expand All @@ -152,14 +152,14 @@ let reducer = (state, action) =>
| Decrement => state - 1
};

let renderCounter = () =>
useReducerExperimental(reducer, 0, ((count, dispatch)) =>
<view>
<button title="Decrement" onPress={() => dispatch(Decrement)} />
<text> {"Counter: " ++ str(count)} </text>
<button title="Increment" onPress={() => dispatch(Increment)} />
</view>
);
let renderCounter = slots => {
let ((count, dispatch), _slots) = slots |> useReducer(reducer, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the example - made it easy to see the impact of the slots model in the API 👍

<view>
<button title="Decrement" onPress={() => dispatch(Decrement)} />
<text> {"Counter: " ++ str(count)} </text>
<button title="Increment" onPress={() => dispatch(Increment)} />
</view>;
};

module CounterButtons = (
val createComponent((render, ~children, ()) =>
Expand Down
4 changes: 1 addition & 3 deletions lib/Reactify.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ open Reactify_Types;

module Make = (ReconcilerImpl: Reconciler) => {
/* Module to give us unique IDs for components */
type renderedElement =
| RenderedPrimitive(ReconcilerImpl.node)
and elementWithChildren = (list(element), Effects.effects, Context.t)
type elementWithChildren = (list(element), Effects.effects, Context.t)
and render = unit => elementWithChildren
and element =
| Primitive(ReconcilerImpl.primitives, render)
Expand Down
Loading