Skip to content

Instantly share code, notes, and snippets.

@wokalski
Last active January 10, 2019 22:32
Show Gist options
  • Save wokalski/a886a71953beed73dd8de7ec247ee6ca to your computer and use it in GitHub Desktop.
Save wokalski/a886a71953beed73dd8de7ec247ee6ca to your computer and use it in GitHub Desktop.
module type Component = {
type slots;
type nextSlots;
type render;
let handedOffInstance:
ref(
option(
instance(slots, nextSlots, syntheticElement, outputNodeGroup),
),
);
let render: Slots.t(slots, nextSlots) => render;
let createComponent:
((Slots.t(slots, nextSlots), unit) => syntheticElement) =>
component(slots, nextSlots, syntheticElement, outputNodeGroup);
};
let component =
(
type render_,
type slots_,
type nextSlots_,
render: Slots.t(slots_, nextSlots_) => render_,
)
: (module Component with
type render = render_ and
type slots = slots_ and
type nextSlots = nextSlots_) =>
(module
{
type slots = slots_;
type nextSlots = nextSlots_;
type render = render_;
let render = render;
let handedOffInstance = ref(None);
let createComponent = render => {
key: Key.none,
render,
handedOffInstance,
elementType: React,
};
});
let lowerCaseComponent =
component((slots, ~propa, ~propb, ()) => {
let ((a, _us), slots) = slots |> useState(propa);
let ((b, _us), _slots: Slots.t(unit, unit)) =
slots |> useState(propb);
a + b;
});
module M = (val lowerCaseComponent);
let x = M.render(~propa=1, ~propb=2);
let y = M.createComponent(x);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment