Skip to content

Instantly share code, notes, and snippets.

@kkazuo
Created March 21, 2019 15:05
Show Gist options
  • Save kkazuo/801dec8810c8f8099a0847f705384c2b to your computer and use it in GitHub Desktop.
Save kkazuo/801dec8810c8f8099a0847f705384c2b to your computer and use it in GitHub Desktop.
ReasonReact binding of react-virtualized/List
[@bs.module "react-virtualized"]
external reactClass: ReasonReact.reactClass = "List";
[@bs.deriving abstract]
type cellProps = {
index: int,
isScrolling: bool,
isVisible: bool,
key: string,
style: ReactDOMRe.Style.t,
};
[@bs.deriving abstract]
type scrollProps = {
overscanStartIndex: int,
overscanStopIndex: int,
startIndex: int,
stopIndex: int,
};
[@bs.deriving abstract]
type props = {
width: int,
height: int,
rowCount: int,
rowHeight: int,
rowRenderer: cellProps => ReasonReact.reactElement,
/* optionals */
overscanRowCount: Js.nullable(int),
onRowsRendered: Js.nullable(scrollProps => unit),
};
let optional = (v, f) =>
switch (v) {
| Some(v) => Js.Nullable.return(f(v))
| None => Js.Nullable.undefined
};
let make =
(
~overscanRowCount=?,
~onRowsRendered=?,
~width,
~height,
~rowCount,
~rowHeight,
~rowRenderer,
children,
) =>
ReasonReact.wrapJsForReason(
~reactClass,
~props=
props(
~overscanRowCount=Js.Nullable.fromOption(overscanRowCount),
~width,
~height,
~rowCount,
~rowHeight,
~rowRenderer=
props =>
rowRenderer(
~index=props->indexGet,
~isScrolling=props->isScrollingGet,
~isVisible=props->isVisibleGet,
~style=props->styleGet,
~key=props->keyGet,
),
~onRowsRendered=
optional(onRowsRendered, (f, props) =>
f(
~startIndex=props->startIndexGet,
~stopIndex=props->stopIndexGet,
~overscanStartIndex=props->overscanStartIndexGet,
~overscanStopIndex=props->overscanStopIndexGet,
)
),
),
children,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment