Skip to content

Instantly share code, notes, and snippets.

@atimca
Created June 19, 2020 09:05
Show Gist options
  • Save atimca/847eeeabaa7d86ce8877f46d5a498762 to your computer and use it in GitHub Desktop.
Save atimca/847eeeabaa7d86ce8877f46d5a498762 to your computer and use it in GitHub Desktop.
extension AppEvent {
static func reduce(state: AppState, event: AppEvent) -> AppState {
var state = state
switch event {
case .newUserWasLoaded(let user):
state.user = user
case .newsEvents(let event):
if state.newsState == nil {
state.newsState = NewsState(user: state.user, step: .initial)
}
state.newsState = NewsState.reduce(state: state.newsState!, event: event)
}
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment