Skip to content

OnEnter not called for initialState #35

@dariush-fathie

Description

@dariush-fathie

Thank you for your amazing library
I have a problem with onEnter at initialState.

It's my code :

   val machine = StateMachine.create<State, Event, SideEffect> {
   initialState(State.INIT)
   
   state<State.INIT> {
      onEnter {
         println("onEnter INIT")
      }
      
      on<Event.E1> {
         println("onE1 INIT")
         transitionTo(State.INITIALIZED)
      }
   }
   
   state<State.INITIALIZED> {
      onEnter {
         println("enter initialized")
      }
      
      on<Event.E1> {
         transitionTo(State.FINAL)
      }
      
      onExit {
         println("exit initialized")
      }
   }
   
   state<State.FINAL> {
      onEnter {
         println("onFinal")
      }
   }
   
   
}


machine.transition(Event.E1)
machine.transition(Event.E1)

sealed class State {
   object INIT : State()
   object INITIALIZED : State()
   object FINAL : State()
}

sealed class Event {
   object E1 : Event()
}

sealed class SideEffect {
   
}

Result:

onE1 INIT
enter initialized
exit initialized
onFinal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions