Onenter event should not fire for pseudo states?
yarandoo opened this issue · 4 comments
We currently use the "onenter" event to save to the database every time we transition to a new state. We found that this event is being fired for the pseudo states that are created as part of the Conditional logic. So every time the FSM transition to this pseudo states an on enter event gets fired and we are saving this state that does not belong to our application domain logic.
We have a workaround to discard the "onenter" event if the TO field contains a string __
as this is the naming convention for pseudo events. This does not make our code base nicer and the use of the library is not as elegant as it could be.
- Do you think it would be nice to stop firing events for the pseudo states? Would the FSM still work or is it relying on this events for the internal implementation of conditionals?
The is an internal structure for the pseudo states. It would be better to check if the state is pseudo instead of sniffing to
strings.
onentered{pseudoState}
is important for the inner workings but the onenter(ed)
are not (to my knowledge). The conditional transitions are just sugar and can be decomposed into explicit transitions to the condition state, but having conditional transitions in the configuration object just changed that domain specific language... so it might be appropriate to not call the onenter(ed)
callbacks for the pseudo state if we define them as silent.
@yarandoo is this what you are looking after, right? https://github.com/vstirbu/fsm-as-promised/tree/feature/silent-pseudo-states
@vstirbu thanks for this change! I have tested within our solution and is working perfectly.
Our code base is cleaner as we dont need to filter for these specific states which did not belong to our domain!
very nice!
Now that you have experienced some friction, and considering that the whole eventing stuff is not documented, do you have any suggestions on how to improve the documentation? Thanks!