-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On Action start a sub statemachine #300
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gabrielittner
approved these changes
May 20, 2022
..._code/src/commonMain/kotlin/com/freeletics/flowredux/sample/shared/PaginationStateMachine.kt
Outdated
Show resolved
Hide resolved
…dux/sample/shared/PaginationStateMachine.kt Co-authored-by: Gabriel Ittner <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
First implementation for #269
It adds the possibility to start a (sub) state machine from an action. Most of the code changes in this PR are actually on updating the sample app 🙈
public api will look very similar to
stateMachine()
Internally FlowRedux keeps track of the Action that has started the sub Statemachine. if the same action (checked with
==
equals operator) is received and a substatemachine is currently running, then the previous sub statemachine will be stopped and a new instance starts again with initial state (so the behavior is kind ofFlatMap.Latest
orExecutionPolicy.CANCEL_PREVIOUS
). It was an intentional decision to not useExecutionPolicy
because it not only makes the internal implementation quite complex but it also is confusing for the consumer if multiple actions with same==
are received and how it should then work in this case. Thus for now at least I would keep it simple with just aFlatMap.Latest
orExecutionPolicy.CANCEL_PREVIOUS
behavior. Please note that since it uses==
equals to check against actions the type of an action only is not the deciding factor.example:
then
MyAction(1)
andMyAction(2)
are for FlowRedux 2 different actions that start 2 different StateMachines but if you dispatchMyAction(3)
followed by anotherMyAction(3)
then the first state machine started byMyAction(3)
will be canceled because the secondMyAction(3)
stars a new sub statemachineNext steps but out of scope of this PR:
stateMachine()
should be renamed toonEnterStartStateMachine()
stopCondition
will be invoked on every state change from parent and sub statemachine. By returning true the SubStatemachine will be stoped. Otherwise theSubStateMachine
will only be stopped when surroundinginState<State>
condition doesn't hold anymore. I could think of use cases where an additionalstopCondition
could be useful but doesn't necessary need to be implemented right now.