Created
July 15, 2018 18:23
-
-
Save twittemb/db59e0a54c40abfbe7b3c50143b59fb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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