Created
December 4, 2017 15:19
-
-
Save arnarthor/41d5c79f3cc4fb601bb46fc1b40bc13a to your computer and use it in GitHub Desktop.
This file contains 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.module "react-router-dom"] external browserRouter : ReasonReact.reactClass = "BrowserRouter"; | |
[@bs.module "react-router-dom"] external route : ReasonReact.reactClass = "Route"; | |
[@bs.module "react-router-dom"] external link : ReasonReact.reactClass = "Link"; | |
[@bs.module "react-router-dom"] external navLink : ReasonReact.reactClass = "NavLink"; | |
[@bs.module "react-router-dom"] external _switch : ReasonReact.reactClass = "Switch"; | |
[@bs.module "react-router-dom"] external redirect : ReasonReact.reactClass = "Redirect"; | |
let fromOption = (default, option) => | |
switch option { | |
| Some(x) => x | |
| None => default | |
}; | |
type params = {. "domain": string, "storyId": string, "token": string, "trackId": string}; | |
type match = {. "params": params, "isExact": Js.boolean, "path": string, "url": string}; | |
type location = {. "key": string, "pathname": string, "search": string, "hash": string}; | |
type history = { | |
. | |
"length": int, "location": string, "action": string, "push": [@bs.meth] (string => unit) | |
}; | |
module BrowserRouter = { | |
type location = | |
| Object(Js.Json.t) | |
| String(string); | |
let make = | |
( | |
~basename: option(string)=?, | |
~getUserConfirmation: option((unit => unit))=?, | |
~forceRefresh: option(bool)=?, | |
~keyLength: option(int)=?, | |
children | |
) => | |
ReasonReact.wrapJsForReason( | |
~reactClass=browserRouter, | |
~props={ | |
"basename": Js.Null_undefined.from_opt(basename), | |
"getUserConfirmation": Js.Null_undefined.from_opt(getUserConfirmation), | |
"forceRefresh": Js.Null_undefined.from_opt(forceRefresh), | |
"keyLength": Js.Null_undefined.from_opt(keyLength) | |
}, | |
children | |
); | |
}; | |
module Route = { | |
type routeParams = {. "_match": match, "location": location, "history": history}; | |
let make = | |
( | |
~render: option((routeParams => ReasonReact.reactElement))=?, | |
~_children: option((routeParams => ReasonReact.reactElement))=?, | |
~path: option(string)=?, | |
~exact: option(bool)=?, | |
~strict: option(bool)=?, | |
~location: option(location)=? | |
) => | |
ReasonReact.wrapJsForReason( | |
~reactClass=route, | |
~props={ | |
"render": Js.Null_undefined.from_opt(render), | |
"children": Js.Null_undefined.from_opt(_children), | |
"path": Js.Null_undefined.from_opt(path), | |
"exact": Js.Null_undefined.from_opt(exact), | |
"strict": Js.Null_undefined.from_opt(strict), | |
"location": Js.Null_undefined.from_opt(location) | |
} | |
); | |
}; | |
module Link = { | |
let make = (~_to: string, ~replace: option(bool)=?, ~className: option(string)=?, children) => | |
ReasonReact.wrapJsForReason( | |
~reactClass=link, | |
~props={ | |
"to": _to, | |
"replace": Js.Null_undefined.from_opt(replace), | |
"className": Js.Null_undefined.from_opt(className) | |
}, | |
children | |
); | |
}; | |
module NavLink = { | |
let make = | |
( | |
~_to: string, | |
~replace: option(bool)=?, | |
~className: option(string)=?, | |
~activeClassName: option(string)=?, | |
children | |
) => | |
ReasonReact.wrapJsForReason( | |
~reactClass=navLink, | |
~props={ | |
"to": _to, | |
"replace": Js.Null_undefined.from_opt(replace), | |
"className": Js.Null_undefined.from_opt(className), | |
"activeClassName": Js.Null_undefined.from_opt(activeClassName) | |
}, | |
children | |
); | |
}; | |
module Switch = { | |
let make = (~location: option(location)=?, children) => | |
ReasonReact.wrapJsForReason( | |
~reactClass=_switch, | |
~props={"location": Js.Null_undefined.from_opt(location)}, | |
children | |
); | |
}; | |
module Redirect = { | |
let make = (~_to: string, children) => | |
ReasonReact.wrapJsForReason(~reactClass=redirect, ~props={"to": _to}, children); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment