Skip to content

Instantly share code, notes, and snippets.

@scull7
Created January 21, 2018 18:10
Show Gist options
  • Save scull7/6d9c820a571c618ca5ee67b8e2daad8f to your computer and use it in GitHub Desktop.
Save scull7/6d9c820a571c618ca5ee67b8e2daad8f to your computer and use it in GitHub Desktop.
module ClassNameList = {
type param = option(string);
let join = (cur: string, x: param) : string =>
switch x {
| None => cur
| Some(s) => cur ++ " " ++ s
};
let make = (classList: list(param)) : string =>
classList |> List.fold_left(join, "");
};
module Basic = {
type param = option(string);
module LoadingIndicator = {
let component = ReasonReact.statelessComponent("WidgetLoadingIndicator");
let make = _children => {
...component,
render: _self =>
<div
className="widget-content"
style=(ReactDOMRe.Style.make(~height="30px", ()))>
<div className="influential-loading-widget" />
</div>
};
};
module WidgetContent = {
let component = ReasonReact.statelessComponent("WidgetContent");
let make = (~padding=?, ~overflow=?, children) => {
...component,
render: _self =>
ReasonReact.createDomElement(
"div",
~props={
"className": ClassNameList.make([Some("widget-content"), padding]),
"style": ReactDOMRe.Style.make(~overflow?, ())
},
children
)
};
};
let component = ReasonReact.statelessComponent("BasicWidgetContainer");
let make =
(
~className=?,
~float=false,
~heading=?,
~loading=true,
~overflow=?,
~padding=?,
~readOnly=false,
~width=?,
children
) => {
...component,
render: _self => {
let widgetHeader = Js.Option.getWithDefault("Widget", heading);
let classList =
ClassNameList.make([
Some("widget"),
loading ? Some("loading") : None,
readOnly ? Some("read-only") : None,
float ? None : Some("no-float"),
className,
width
]);
<div className=classList>
<div className="widget-header">
<h3> (ReasonReact.stringToElement(widgetHeader)) </h3>
</div>
(
loading ?
<LoadingIndicator /> :
<WidgetContent overflow> ...children </WidgetContent>
)
</div>;
}
};
};
@scull7
Copy link
Author

scull7 commented Jan 21, 2018

I'm completely lost on 2 things.

  1. When I use <WidgetContent overflow> the compiler complains that overflow has the type option('a) but somewhere wanted string. Where is that somewhere?
  2. When I use <WidgetContent padding> the compiler, similarly, complains that padding has the type option('a) but somewhere wanted string. Where is that somewhere?

Compiler Output

overflow

[2/2] Building src/Widget.mlast.d
[1/1] Building src/Widget-ReasonReactPrototype.cmj
FAILED: src/Widget-ReasonReactPrototype.cmj /~~project-path~~/reason-react-prototype/src/Widget.bs.js src/Widget-ReasonReactPrototype.cmi 
/~~user-home~~/global/node_modules/bs-platform/lib/bsc.exe -bs-package-map reason-react-prototype  -bs-package-output commonjs:src -bs-assume-no-mli -bs-no-builtin-ppx-ml -bs-no-implicit-include -I /~~project-path~~/reason-react-prototype/node_modules/reason-react/lib/ocaml -I . -I src  -w -30-40+6+7+27+32..39+44+45+101 -bs-suffix -nostdlib -I '/~~project-path~~/reason-react-prototype/node_modules/bs-platform/lib/ocaml' -bs-no-version-header -bs-super-errors -no-alias-deps -color always -bs-re-out -bs-super-errors -o src/Widget-ReasonReactPrototype.cmj -c  src/Widget.mlast

  We've found a bug for you!
  /~~<redacted>~~/reason-react-prototype/src/Widget.re 73:28-35
  
  71 ┆     loading ?
  72 ┆       <LoadingIndicator /> :
  73 ┆       <WidgetContent overflow> ...children </WidgetContent>
  74 ┆   )
  75 ┆ </div>;
  
  This has type:
    option('a)
  But somewhere wanted:
    string
  
ninja: build stopped: subcommand failed.
>>>> Finish compiling(exit: 1)

padding

[2/2] Building src/Widget.mlast.d
[1/1] Building src/Widget-ReasonReactPrototype.cmj
FAILED: src/Widget-ReasonReactPrototype.cmj /~~project-path~~/client/app/reason-react-prototype/src/Widget.bs.js src/Widget-ReasonReactPrototype.cmi 
/~~user-home~~/global/node_modules/bs-platform/lib/bsc.exe -bs-package-map reason-react-prototype  -bs-package-output commonjs:src -bs-assume-no-mli -bs-no-builtin-ppx-ml -bs-no-implicit-include -I /~~project-path~~/reason-react-prototype/node_modules/reason-react/lib/ocaml -I . -I src  -w -30-40+6+7+27+32..39+44+45+101 -bs-suffix -nostdlib -I '/~~project-path~~/reason-react-prototype/node_modules/bs-platform/lib/ocaml' -bs-no-version-header -bs-super-errors -no-alias-deps -color always -bs-re-out -bs-super-errors -o src/Widget-ReasonReactPrototype.cmj -c  src/Widget.mlast 

  We've found a bug for you!
  /~~<redacted>~~/reason-react-prototype/src/Widget.re 73:28-34
  
  71 ┆     loading ?
  72 ┆       <LoadingIndicator /> :
  73 ┆       <WidgetContent padding> ...children </WidgetContent>
  74 ┆   )
  75 ┆ </div>;
  
  This has type:
    option('a)
  But somewhere wanted:
    string
  
ninja: build stopped: subcommand failed.
>>>> Finish compiling(exit: 1)

@scull7
Copy link
Author

scull7 commented Jan 21, 2018

After reading the docs on prop forwarding I was able to get this to compile by changing line 73 to the following:

<WidgetContent ?padding ?overflow> ...children </WidgetContent>

Hopefully someone can explain why this works, because right now I'm even more lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment