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

State Machine Docs: Syntax Error in Example #64

Closed
xaviervalarino opened this issue Apr 11, 2018 · 2 comments · Fixed by #65
Closed

State Machine Docs: Syntax Error in Example #64

xaviervalarino opened this issue Apr 11, 2018 · 2 comments · Fixed by #65

Comments

@xaviervalarino
Copy link
Contributor

xaviervalarino commented Apr 11, 2018

I've been reading over the docs for Choo and decided to work through the State Machine article—after watching davidkpiano's talk on the subject I wanted to get a better feel for how it works.

In the code example the constructor's method is named next, but then further down is called as transition().

export class StateMachine {
  constructor (initialState, transitions) {
    this.state = initialState
    this.transitions = transitions
  }

  next (transition) {
    var nextState = this.transitions[this.state][transition]
    if (!nextState) throw new Error(`invalid: ${this.state} -> ${transition}`)
    this.state = nextState
  }
}
machine.transition('timer')

After getting the names to match, I also had to remove export and turn the timer values into strings to get the example to work (with Node.js).

@goto-bus-stop
Copy link
Member

Good finds! Would you like to open a PR that fixes those problems? The state machine documentation is in /content/docs/state-machines/index.md.

@xaviervalarino
Copy link
Contributor Author

xaviervalarino commented Apr 11, 2018

@goto-bus-stop Sure thing! I was considering it when I was submitting the issue, but wasn't sure what the export statement was doing. I am not familiar with ES6, but it looks like module.exports, so I imagine it is there to illustrate that the state machine should be used as a module?

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 a pull request may close this issue.

2 participants