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

DEFAULT_HANDLER returns undefined #29

Open
imdkva opened this issue Mar 1, 2019 · 1 comment
Open

DEFAULT_HANDLER returns undefined #29

imdkva opened this issue Mar 1, 2019 · 1 comment
Labels
question Further information is requested

Comments

@imdkva
Copy link

imdkva commented Mar 1, 2019

Value of data of a new state is undefined when machine.next(STATE) called without payload arguments. Reason is DEFAULT_HANDLER receives undefined as last arg

@antongolub antongolub added the question Further information is requested label Mar 2, 2019
@antongolub
Copy link
Member

Can not reproduce. Could you add a bit more details?

  • cyclone version
  • machine config

Any transition handler gets previously stored data as the first arg. If optional payload is empty, args length is still equal 1, and DEFAULT_HANDLER works like identity — returns the prev value.

Have a look:

export const DEFAULT_HANDLER: IHandler = (...args) => args.pop()
public next (state: IState, ...payload: Array<IAny>): IMachine {
    if (this.key) {
      throw new MachineError(LOCK_VIOLATION)
    }

    const handler = Machine.getHandler(state, this.history, this.transitions)
    const current = this.current()
    const data = handler(current.data, ...payload)
    const id = generateId()
    const date = generateDate()

    this.history.push({
      state,
      data,
      id,
      date
    })

    if (this.history.length > Machine.getHistoryLimit(this.opts.historySize)) {
      log.debug('history limit reached')
      this.history.shift()
    }

    return this
  }

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

No branches or pull requests

2 participants