Created
June 19, 2020 09:19
-
-
Save atimca/04685edfc4429dd789f59882d2cfcf86 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
let appReducer: Reducer = { state, event in | |
var state = state | |
switch event { | |
case .newUserWasLoaded(let user): | |
state.user = user | |
default: | |
return state | |
} | |
return state | |
} | |
let combinedReducer = combine( | |
transform( | |
localReducer: NewsState.reduce(state:event:), | |
stateKeyPath: \AppState.newsState, | |
toLocalEvent: \AppEvent.newsEvent | |
), | |
appReducer | |
) | |
let firstMutation = combinedReducer(initialState, .newUserWasLoaded(User(id: 1))) | |
let secondMutation = combinedReducer(firstMutation, .newsEvents(.loadData)) | |
print(secondMutation.user.id) | |
print(secondMutation.newsState!.step) | |
// Console output: | |
// 1 | |
// loading |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment