Closed piefel closed 2 months ago
Hi, I will add more descriptive sample in docs. Your assumption is almost correct.
event.value
just means that you have some event like this class MyEvent(val value: Int): Event
choiceDataState
is used in this unit test.
https://github.com/KStateMachine/kstatemachine/blob/master/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ChoiceStateTest.kt#L130
choiceDataState
is actually necessary not for accessing data
field, but to be used as target of dataTransition
function (for type safety). It chooses between DataStates
of same type.
choiceDataState
s lambda does not provide guarantee that only DataEvent
can trigger it. It potentially can be called with any type of Event
, so explicit cast in users (your) code is necessary to access data
field of DataEvent
.
You can find more descriptive samples here https://kstatemachine.github.io/kstatemachine/#choice-state
Thank you, that was really quick and very helpful.
The choice states do not appear in any example. The unit test is very minimal, and it does not include actual choices. In
docs/index.md
, the example code includesevent.value
, which is not even valid.It seems a
choiceDataState
should have access to the data, but it appears that is not the case. Or perhaps it has access, but again there is no mention of it and the unit tests also do not use it.