Skip to content
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

Additional condition for on<Action> construct #311

Closed
sockeqwe opened this issue Jun 4, 2022 · 3 comments
Closed

Additional condition for on<Action> construct #311

sockeqwe opened this issue Jun 4, 2022 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@sockeqwe
Copy link
Collaborator

sockeqwe commented Jun 4, 2022

We already have inState<S>(additionalCondition = { ... }) and maybe it would be useful to add additionalCondition also to on<Action>.

Use case:

private fun resetErrorState(action: RetryToggleFavoriteAction, state: State<GithubRepository>): ChangeState<GithubRepository> {
return if (action.id != state.snapshot.id) {
// Since all active MarkAsFavoriteStateMachine receive this action
// we need to ignore those who are not meant for this state machine
state.noChange()
} else {
state.mutate { copy(favoriteStatus = FavoriteStatus.OPERATION_IN_PROGRESS) }
}
}

Where the on<Action> block should actually only be triggered when action.id == someId

Just leaving it here for a potential future addition / improvement.

@sockeqwe sockeqwe added enhancement New feature or request good first issue Good for newcomers labels Jun 4, 2022
@gabrielittner
Copy link
Member

Wouldn't it be better to have the check inside the method for testability?

@gabrielittner
Copy link
Member

@sockeqwe Any objections against closing this since we are adding the condition block and also are deprecating the additional condition overload from isInState?

@sockeqwe
Copy link
Collaborator Author

sockeqwe commented May 31, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Development

No branches or pull requests

2 participants