{"action":"created","issue":{"url":"https://api.github.com/repos/jakesgordon/javascript-state-machine/issues/121","repository_url":"https://api.github.com/repos/jakesgordon/javascript-state-machine","labels_url":"https://api.github.com/repos/jakesgordon/javascript-state-machine/issues/121/labels{/name}","comments_url":"https://api.github.com/repos/jakesgordon/javascript-state-machine/issues/121/comments","events_url":"https://api.github.com/repos/jakesgordon/javascript-state-machine/issues/121/events","html_url":"https://github.com/jakesgordon/javascript-state-machine/issues/121","id":237865388,"number":121,"title":"onInvalidTransition 'to' argument is undefined","user":{"login":"bjornhanson","id":2284699,"avatar_url":"https://avatars1.githubusercontent.com/u/2284699?v=3","gravatar_id":"","url":"https://api.github.com/users/bjornhanson","html_url":"https://github.com/bjornhanson","followers_url":"https://api.github.com/users/bjornhanson/followers","following_url":"https://api.github.com/users/bjornhanson/following{/other_user}","gists_url":"https://api.github.com/users/bjornhanson/gists{/gist_id}","starred_url":"https://api.github.com/users/bjornhanson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjornhanson/subscriptions","organizations_url":"https://api.github.com/users/bjornhanson/orgs","repos_url":"https://api.github.com/users/bjornhanson/repos","events_url":"https://api.github.com/users/bjornhanson/events{/privacy}","received_events_url":"https://api.github.com/users/bjornhanson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-06-22T14:30:37Z","updated_at":"2017-06-26T15:34:45Z","closed_at":null,"body":"It seems the `to` argument passed to `onInvalidTransition` is always undefined, unless I'm not understanding things correctly.  For example, if I create the following state machine:\r\n\r\n```\r\nvar fsm = new StateMachine({\r\n  init: 'A',\r\n\r\n  transitions: [\r\n    {name: 'one',   from: 'A', to: 'B'},\r\n    {name: 'two',   from: 'B', to: 'A'},\r\n    {name: 'three', from: 'B', to: 'C'}\r\n  ],\r\n\r\n  methods: {\r\n    onInvalidTransition: function(transition, from, to) {\r\n      console.log(arguments);\r\n    }\r\n  }\r\n});\r\n```\r\n\r\nand then try to fire the `three` transition (while in state A), I would expect `onInvalidTransition` to be called with `C` as the value of `to`, but it's `undefined`.\r\n\r\n```\r\n> fsm.three();\r\n\r\n(3) [\"three\", \"A\", undefined, callee: (...), Symbol(Symbol.iterator): function]\r\n```\r\n\r\nI didn't thoroughly examine the code, but it looks like the result of `this.seek` might only return a state to pass in to `transit` as `to` if it's a valid state to transition to:\r\n\r\n```\r\n  fire: function(transition, args) {\r\n    return this.transit(transition, this.state, this.seek(transition, args), args);\r\n  },\r\n\r\n  transit: function(transition, from, to, args) {\r\n\r\n    var lifecycle = this.config.lifecycle,\r\n        changed   = this.config.options.observeUnchangedState || (from !== to);\r\n\r\n    if (!to)\r\n      return this.context.onInvalidTransition(transition, from, to);\r\n\r\n    ...\r\n  }\r\n```"},"comment":{"url":"https://api.github.com/repos/jakesgordon/javascript-state-machine/issues/comments/311095717","html_url":"https://github.com/jakesgordon/javascript-state-machine/issues/121#issuecomment-311095717","issue_url":"https://api.github.com/repos/jakesgordon/javascript-state-machine/issues/121","id":311095717,"user":{"login":"bjornhanson","id":2284699,"avatar_url":"https://avatars1.githubusercontent.com/u/2284699?v=3","gravatar_id":"","url":"https://api.github.com/users/bjornhanson","html_url":"https://github.com/bjornhanson","followers_url":"https://api.github.com/users/bjornhanson/followers","following_url":"https://api.github.com/users/bjornhanson/following{/other_user}","gists_url":"https://api.github.com/users/bjornhanson/gists{/gist_id}","starred_url":"https://api.github.com/users/bjornhanson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjornhanson/subscriptions","organizations_url":"https://api.github.com/users/bjornhanson/orgs","repos_url":"https://api.github.com/users/bjornhanson/repos","events_url":"https://api.github.com/users/bjornhanson/events{/privacy}","received_events_url":"https://api.github.com/users/bjornhanson/received_events","type":"User","site_admin":false},"created_at":"2017-06-26T15:34:45Z","updated_at":"2017-06-26T15:34:45Z","body":"Yeah, I know what you're saying. It doesn't seem like state transitions should fire more than once. I don't think your example of adding a transition to stay on the same state would work. There's at least once case so far where I would want to fire a transition that I care about the first time (and get lifecycle events for), and then potentially ignore any after that. I may just have to add my own flags in my code to track the state and not rely on the state machine alone. There are events that occur that are out of my application's control (like messages coming in via websockets) where I would want to react to the first one and change state, but not every one after that. Right now I'm just evaluating if/where state machines may help clean up the code in our (already existing) application."}}
{"actor":{"display_login":"bjornhanson"}}