Closed toshi0383 closed 8 years ago
In your example, you are registering event-based routes but attaching state-based handler, so it doesn't react to any event-triggering.
To fix this, please replace:
// register handler for state-based transition, e.g. `machine <- .State0`
machine.addHandler(.Any => .Any) { ... }
to:
// register handler for event-based transition, e.g. `machine <-! .Event0`
machine.addHandler(event: .Event0) { ... }
I thought it was working in previous version, though ?
Yes, previous ver 3.x was working in that way (equal to addEventHandler()
).
From ver 4.0.0, you need to use machine.addHandler(event:)
instead.
P.S.
For reacting to any events, you can use machine.addHandler(event: .Any)
.
Updated README.md in 84d4b42511c06f5fed95aeb5644b5f23d447c204.
👏 I see that. Thanks !
Hello.
I find this behavior surprising. I was just playing with SwiftState, and wanted to model the state machine using a mix of events and states. The idea being that I would attach handlers to the states, but send events to the machine to transition.
I understand this is not possible—I would have to choose events or states, but not both.
I modified the basic test case as following and it's failing. Any ideas to get rid of ?