Skip to content

Instantly share code, notes, and snippets.

@CesarValiente
Last active May 23, 2017 03:44
Show Gist options
  • Save CesarValiente/51680295061f400dcb6aa3871251639b to your computer and use it in GitHub Desktop.
Save CesarValiente/51680295061f400dcb6aa3871251639b to your computer and use it in GitHub Desktop.
class StoreActionSubscriber(actionDispatcher: ActionDispatcher,
actionThread: ThreadExecutor? = null,
val stateDispatcher: StateDispatcher)
: ActionSubscriber(actionDispatcher, actionThread) {
override fun reduce(action: Action) {
val currentState = stateDispatcher.state
val newState = when (action) {
is CreationAction -> CreationReducer.reduce(action, currentState)
is UpdateAction -> UpdateReducer.reduce(action, currentState)
is ReadAction -> ReadReducer.reduce(action, currentState)
is DeleteAction -> DeleteReducer.reduce(action, currentState)
is NavigationAction -> NavigationReducer.reduce(action, currentState)
}
stateDispatcher.dispatch(newState)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment