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

Try to improve initial example of a reducer comp #187

Closed
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@slorber

slorber commented Feb 22, 2018

Because it was not clear to me that the initial example was not a valid code snippet. I expected it to compile after pasting it in my editor.

slorber added some commits Feb 22, 2018

Try to improve initial example of a reducer comp
Because it was not clear to me that the initial example was not a valid code snippet. I expected it to compile after pasting it in my editor.
@slorber

This comment has been minimized.

slorber commented Feb 22, 2018

I tried to make it more clear, but as I'm new to Reason I don't really know what I'm doing ;)

let component = ReasonReact.reducerComponent("Greeting");
let make = (~name, _children) => {
...component,
initialState: () => 0, /* here, state is an `int` */
initialState: () => 42, /* here, state is an `int` */
reducer: (action,state) => { ... },

This comment has been minimized.

@yawaramin

yawaramin Feb 23, 2018

Contributor

This won't compile either after you paste it into your project, right? :-)

This comment has been minimized.

@slorber

slorber Feb 23, 2018

sure it does not but at least it's explicit it won't compile :)

@yawaramin

I think you have the right idea but I recommend making this compilable. I can see that it's frustrating when doc examples don't work and you're left holding the bag trying to figure out why. A complete minimal example would really help.

As a bonus you could even put in some comments about what kind of errors you'd see if you left out certain parts of the code, like the reducer itself or the calls to self.send.

@sanderhahn

This comment has been minimized.

sanderhahn commented Feb 24, 2018

With some help on Discord i got to this working Greeting example:

type state = int;

type action =
  | Increment;

let component = ReasonReact.reducerComponent("Greeting");

let text = ReasonReact.stringToElement;

let make = (~name, _children) => {
  ...component,
  initialState: () => 0,
  reducer: (action, state) =>
    switch action {
    | Increment => ReasonReact.Update(state + 1)
    },
  render: self => {
    let greeting =
      "Hello "
      ++ name
      ++ ". You've clicked the button "
      ++ string_of_int(self.state)
      ++ " time(s)!";
    <div>
      (text(greeting))
      <button onClick=(_event => self.send(Increment))>
        (text("Click Me"))
      </button>
    </div>;
  }
};
@yawaramin

This comment has been minimized.

Contributor

yawaramin commented Mar 11, 2018

Sébastien, looks like @chenglou has updated the example in 7eed357

@slorber

This comment has been minimized.

slorber commented Mar 12, 2018

great I'm closing this then

@slorber slorber closed this Mar 12, 2018

@chenglou

This comment has been minimized.

Collaborator

chenglou commented Mar 12, 2018

Thanks for the contribution! Yeah we've received similar feedback from others so we decided to just sync this snippet with the one in the bsb boilerplate, etc.

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