Skip to content

Instantly share code, notes, and snippets.

@twittemb
Created July 15, 2018 18:23
Show Gist options
  • Select an option

  • Save twittemb/db59e0a54c40abfbe7b3c50143b59fb5 to your computer and use it in GitHub Desktop.

Select an option

Save twittemb/db59e0a54c40abfbe7b3c50143b59fb5 to your computer and use it in GitHub Desktop.
func userReducer (state: AppState?, action: Action) -> AppState {
var currentState = state ?? AppState(userState: UserState.empty,
contactsState: ContactsState.empty)
// according to the action we create a new state
switch action {
case let action as LoadUserAction:
currentState.userState = UserState.loaded(User(firstname: action.firstname,
lastname: action.lastname))
return currentState
default:
return currentState
}
}
func contactsReducer (state: AppState?, action: Action) -> AppState {
var currentState = state ?? AppState(userState: UserState.empty,
contactsState: ContactsState.empty)
// according to the action we create a new state
switch action {
case let action as LoadContactsAction:
currentState.contactsState = ContactsState.loaded(action.contacts)
return currentState
default:
return currentState
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment