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

Add Switch and Link components #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

remithomas
Copy link

@remithomas remithomas commented Dec 20, 2017

  • Add Switch and Link components
  • Add some documentation
  • Upgrade some packages

@bassjacob I have added some components

Copy link
Contributor

@emmenko emmenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. I also did some more improvements in #7 and left out some that you did here (to avoid conflicts).

README.md Outdated
npm install --save bs-react-router
```

Then add bs-react-router to bs-dependencies in your bsconfig.json:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: formatting with backticks

Add `bs-react-router` to your `bs-dependencies`: **bsconfig.json**

}
```

## Example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: we can move the examples to actual *.re files, you know for sure then if it compiles ;)

E.g. https://github.com/reasonml-community/bs-downshift/tree/master/examples

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a very good point ! Good catch !

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "bs-react-router",
"version": "1.1.1",
"version": "1.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I would avoid bumping the version in a PR, it should be done separately
  2. it should be a minor bump, not a patch

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely !! @bassjacob this is not a patch, this is a minor version cause of this change from this comment #6 (comment)

package.json Outdated
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can leave those out, I've done this in my PR #7 and have a couple more changes (just to avoid conflicts 😉)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a quick update, I remove them. You can add them in PR #7

[@bs.module "react-router-dom"] external _switch : ReasonReact.reactClass = "Switch";
let make = (children) =>
ReasonReact.wrapJsForReason(
~reactClass=_switch,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: you can simply name the external reactClass, then you can avoid passing the variable

[@bs.module "react-router-dom"] external reactClass : ReasonReact.reactClass = "Switch";

ReasonReact.wrapJsForReason(~reactClass, ~props=Js.Obj.empty(), children);

[@bs.module "react-router-dom"] external link : ReasonReact.reactClass = "Link";
let make =
(
~_to: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use _to or to_? Do you know if there is a convention for such cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a good question ! My guess is to_ because _to looks like a non-used variable so I change uses.

@chenglou
Copy link
Contributor

Hello! Sorry for the churn, but we've made a router today, so I'm planning to move this into the reasonml-old org. Though maybe some of you would like to maintain it?


<Switch>
<Route path="/" exact=true component=(() => <HomePage />) />
<Route path="/user" component=(() => <UserPage />) />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: provide a comment that explain why you wrap the component into a function.

For example: https://github.com/emmenko/flopflip/blob/7007a4b9a2b0ab689edba20a1f4945b528154769/packages/reason-bindings/src/FlopFlip__Types.re#L3-L11

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also be careful that if you keep it like this the UserPage component won't receive the router props (match, location, ...).

However we could do a little trick:

module UserPage = {
  let component = ...;
  let make = ...;
};
let userPageComponent =
  UserPage.(
    ReasonReact.wrapReasonForJs(~component, jsProps =>
      make(~match=jsProps##_match, ~location=jsProps##location, [||])
    )
  );

<Route component=userPageComponent />

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emmenko The wrapReasonForJs returns a type of ReactClass and the component attributes of the router requires a ReactElement type. Should I use this method or transform another way ?

For the moment, I just fixed some comments you advised rebase on master.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. Actually I think it's easier to use ReactClass (I also use it in one of my projects).

~component: option(ReasonReact.reactClass)=?,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants