Skip to content

Instantly share code, notes, and snippets.

@tunjid
Created January 7, 2022 12:57
Show Gist options
  • Save tunjid/887bfe7deb11d9824640c8fe04ac0a72 to your computer and use it in GitHub Desktop.
Save tunjid/887bfe7deb11d9824640c8fe04ac0a72 to your computer and use it in GitHub Desktop.
fun archiveMutator(
scope: CoroutineScope,
route: ArchiveRoute,
repo: ArchiveRepository,
appMutator: AppMutator,
): Mutator<Action, StateFlow<State>> = stateFlowMutator(
scope = scope,
initialState = State(...),
started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 2000),
transform = { actions ->
merge(
appMutator.navRailStatusMutations(),
actions.toMutationStream {
when (val action = type()) {
is Action.Fetch -> action.flow.fetchMutations(repo = repo)
is Action.Navigate -> action.flow.map { it.navAction }.consumeWith(appMutator)
is Action.UpdateListState -> action.flow.updateListStateMutations()
is Action.FilterChanged -> action.flow.filterChangedMutations()
is Action.ToggleFilter -> action.flow.filterToggleMutations()
is Action.GridSize -> action.flow.gridSizeMutations()
}
}
).monitorWhenActive(appMutator)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment