Skip to content

can() with unexpected event #60

@kakawait

Description

@kakawait

I could be nice to support error when using can with unexpected even:

var fsm = StateMachine.create({
  initial: 'hungry',
  events: [
    { name: 'eat',  from: 'hungry',                                to: 'satisfied' },
    { name: 'eat',  from: 'satisfied',                             to: 'full'      },
    { name: 'eat',  from: 'full',                                  to: 'sick'      },
    { name: 'rest', from: ['hungry', 'satisfied', 'full', 'sick'], to: 'hungry'    },
]})

fsm.can('sleep');

produces the following error:

.can     = function(event) { return !this.transition && (map[event].hasOwnProp
                                                                    ^
TypeError: Cannot call method 'hasOwnProperty' of undefined

It may be possible to return false instead of getting an error?

I'm writting a parser using state machine mechanism, so all my transitions depend on the input source that I cannot control that why I can stay in this use case :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions