Switch ordering between life-cycle functions and state event #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The ordering in the transition functions previous was that first the 'state' event was emitted (to the outside), secondly the class-internal on life-cycle function was called. At the cybus software, that turned out to be the root cause of some problem, because there may be events that should immediately be followed by other class-internal action, even before any outside event listener is notified about the state change. In the previous ordering that was impossible. By switching this to first call the class-internal life-cycle functions and then emit the event, it ensures that the class stays in ownership of its own state and its own state interpretation.
How has this been tested?
We changed this to fix some remaining bug in the cybus software in CYB-3488 (2022-03-07, appearing in release 1.0.78), and it has been in active use since then, so I would conclude that it works fine.