Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Last active June 1, 2018 01:32
Show Gist options
  • Select an option

  • Save joshuakfarrar/70e515bfc2f512d34bf21250d7995303 to your computer and use it in GitHub Desktop.

Select an option

Save joshuakfarrar/70e515bfc2f512d34bf21250d7995303 to your computer and use it in GitHub Desktop.
[%bs.raw {|require('./App.css')|}];
[@bs.module] external logo : string = "./logo.svg";
type action = Hello | Goodbye | Whatever;
type state = {
greeting: string
};
let component = ReasonReact.reducerComponent("App");
let make = (~message, _children) => {
...component,
initialState: () => { greeting: "hi" },
reducer: (action, _state: state) =>
switch (action) {
| Hello => ReasonReact.Update({..._state, greeting: "hello" })
| Goodbye => ReasonReact.Update({..._state, greeting: "goodbye" })
| Whatever => ReasonReact.Update({..._state, greeting: "whatever" })
},
didMount: self => {
let watcherID = ReasonReact.Router.watchUrl(url => {
Js.log(url.path)
switch (url.path) {
| ["hello"] => self.send(Hello)
| ["goodbye"] => self.send(Goodbye)
| ["whatever"] => self.send(Whatever)
| _ => self.send(Hello)
}
});
self.onUnmount(() => ReasonReact.Router.unwatchUrl(watcherID));
},
render: _self =>
<div className="App">
<div className="App-header">
<img src=logo className="App-logo" alt="logo" />
<h2> (ReasonReact.string(message)) </h2>
</div>
<p className="App-intro">
(ReasonReact.string("To get started, edit"))
(ReasonReact.string(_self.state.greeting))
<code> (ReasonReact.string(" src/App.re ")) </code>
(ReasonReact.string("and save to reload."))
</p>
</div>
};
/* self.send is not called when visiting /hello or /goodbye */
let watcherID = ReasonReact.Router.watchUrl(url => {
switch (url.path) {
| ["hello"] => self.send(Hello)
| ["goodbye"] => self.send(Goodbye)
}
});
/* self.send is called when visiting /#hello or /#goodbye */
let watcherID = ReasonReact.Router.watchUrl(url => {
switch (url.hash) {
| "hello" => self.send(Hello)
| "goodbye" => self.send(Goodbye)
}
});
@joshuakfarrar

joshuakfarrar commented Jun 1, 2018 •

Copy link
Copy Markdown
Author
type thing = {
  path: list(string)
};

let x = { path: ["hello", 5] };

let d = switch (x.path) {
| ["hello", _] => true
| _ => false
};

Js.log(d);

This obviously fails to compile, but let x = { path: ["hello", "world"]}; obviously does not.

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