Last active
June 1, 2018 01:32
-
-
Save joshuakfarrar/70e515bfc2f512d34bf21250d7995303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [%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> | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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) | |
| } | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This obviously fails to compile, but
let x = { path: ["hello", "world"]};obviously does not.