Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hooks update #38

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ node_modules/

lib
*.bs.js
.bsb.lock
.vscode
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module RouterConfig = {
type route =
| Admin
| Home;
let routeFromUrl = (url: ReasonReact.Router.url) =>
let routeFromUrl = (url: ReasonReactRouter.url) =>
switch url.path {
| ["admin"] => Admin
| [] => Home
Expand All @@ -42,11 +42,9 @@ module RouterConfig = {

module Router = ReRoute.CreateRouter(RouterConfig);

let component = ReasonReact.statelessComponent("App");
[@react.component]
let make = ()=> {

let make = _children => {
...component,
render: _self =>
<Router.Container>
...(
(~currentRoute) =>
Expand All @@ -69,11 +67,11 @@ Sections below are under construction.

## Rationale

ReasonReact comes with a router ([`ReasonReact.Router`](https://reasonml.github.io/reason-react/docs/en/router.html)) by default. It offers minimal yet powerful API that is suitable for applications at any scale. However, being just an API, it leaves the routing logic up to the developer. This library builds on top of it to provide an elegant interface for working with routes that is ready to use, predictable and consistent across apps you create.
ReasonReact comes with a router ([`ReasonReactRouter`](https://reasonml.github.io/reason-react/docs/en/router.html)) by default. It offers minimal yet powerful API that is suitable for applications at any scale. However, being just an API, it leaves the routing logic up to the developer. This library builds on top of it to provide an elegant interface for working with routes that is ready to use, predictable and consistent across apps you create.

## Credits

The concept of `reroute` has been highly influenced by [@thangngoc89](https://github.com/thangngoc89) and his [reference implementation](https://gist.github.com/thangngoc89/c9162c0263df5427fe9a36fc7f94ac94). Thank you for pushing this forward!
The concept of `reroute` has been highly influenced by [@thangngoc89](https://github.com/thangngoc89) and his [reference implementation](https://gist.github.com/thangngoc89/c9162c0263df5427fe9a36fc7f94ac94). Thank you for pushing this forward!

## License

Expand Down
16 changes: 12 additions & 4 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{
"name": "reason-reroute",
"bsc-flags": ["-bs-no-version-header", "-bs-super-errors"],
"refmt": 3,
"bs-dependencies": ["reason-react"],
"bsc-flags": [ "-bs-no-version-header", "-bs-super-errors" ],
"bs-dependencies": [ "reason-react" ],
"reason": {
"react-jsx": 2
"react-jsx": 3
},
"namespace": false,
"package-specs": {
"module": "es6",
"in-source": true
},
"suffix": ".bs.js",
"sources": [
{
"dir": "src",
"public": "all"
},
{
"dir": "examples",
"type": "dev"
}
]
}
26 changes: 0 additions & 26 deletions examples/.gitignore

This file was deleted.

7 changes: 7 additions & 0 deletions examples/Admin.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[@react.component]
let make = () => {
<div>
<h1> {React.string("Admin")} </h1>
<p> {React.string("This is an admin page")} </p>
</div>;
};
44 changes: 44 additions & 0 deletions examples/App.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module RouterConfig = {
type route =
| Admin
| Home
| NotFound;
let routeFromUrl = (url: ReasonReactRouter.url) =>
switch (url.path) {
| ["admin"] => Admin
| [] => Home
| _ => NotFound
};
let routeToUrl = (route: route) =>
switch (route) {
| Admin => "/admin"
| Home => "/"
| NotFound => ""
};
};

module Router = ReRoute.CreateRouter(RouterConfig);
open RouterConfig;
[@react.component]
let make = () => {
<Router.Container>
...{(~currentRoute) =>
<div>
<ul>
<h3> {React.string("Menu")} </h3>
<Router.Link route=Home>
<li> {React.string("Home")} </li>
</Router.Link>
<Router.Link route=Admin>
<li> {React.string("Admin")} </li>
</Router.Link>
</ul>
{switch (currentRoute) {
| RouterConfig.Admin => <Admin />
| RouterConfig.Home => <Home />
| RouterConfig.NotFound => <NotFound />
}}
</div>
}
</Router.Container>;
};
7 changes: 7 additions & 0 deletions examples/Home.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[@react.component]
let make = () => {
<div>
<h1> {React.string("Home")} </h1>
<p> {React.string("Welcome to the home page!")} </p>
</div>;
};
14 changes: 14 additions & 0 deletions examples/NotFound.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[@react.component]
let make = () => {
<div>
<h1> {React.string("We are sorry...")} </h1>
<p>
{React.string(
"Unfortunately we could not find the page you were looking for.",
)}
</p>
<p>
{React.string("Use the above menu to navigate to other pages :)")}
</p>
</div>;
};
6 changes: 0 additions & 6 deletions examples/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions examples/bsconfig.json

This file was deleted.

File renamed without changes.
3 changes: 3 additions & 0 deletions examples/index.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[%bs.raw {|require('./index.css')|}];

ReactDOMRe.renderToElementWithId(<App />, "root");
22 changes: 0 additions & 22 deletions examples/package.json

This file was deleted.

Binary file removed examples/public/favicon.ico
Binary file not shown.
40 changes: 0 additions & 40 deletions examples/public/index.html

This file was deleted.

15 changes: 0 additions & 15 deletions examples/public/manifest.json

This file was deleted.

10 changes: 0 additions & 10 deletions examples/src/Admin.re

This file was deleted.

50 changes: 0 additions & 50 deletions examples/src/App.re

This file was deleted.

10 changes: 0 additions & 10 deletions examples/src/Home.re

This file was deleted.

23 changes: 0 additions & 23 deletions examples/src/NotFound.re

This file was deleted.

3 changes: 0 additions & 3 deletions examples/src/index.re

This file was deleted.

Loading