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
enum AppEvent { | |
case newUserWasLoaded(User) | |
case newsEvents(NewsEvent) | |
var newsEvent: NewsEvent? { | |
guard case .newsEvents(let event) = self else { return nil } | |
return event | |
} | |
} |
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 transform( | |
newsReducer: @escaping (NewsState, NewsEvent) -> NewsState, | |
stateKeyPath: WritableKeyPath<AppState, NewsState> | |
) -> Reducer { | |
return { appState, appEvent in | |
var appState = appState | |
appState[keyPath: stateKeyPath] = newsReducer(appState[keyPath: stateKeyPath], appEvent) | |
return appState | |
} | |
} |
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 transform(newsReducer: (NewsState, NewsEvent) -> NewsState) -> Reducer |
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 transform( | |
newsReducer: @escaping (NewsState, AppEvent) -> NewsState, | |
stateKeyPath: WritableKeyPath<AppState, NewsState> | |
) -> Reducer { | |
return { appState, appEvent in | |
var appState = appState | |
appState[keyPath: stateKeyPath] = newsReducer(appState[keyPath: stateKeyPath], appEvent) | |
return appState | |
} | |
} |
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 transform( | |
newsReducer: @escaping (NewsState, AppEvent) -> NewsState, | |
appStateIntoNews: @escaping (AppState) -> NewsState, | |
mutateAppStateWithNewsState: @escaping (AppState, NewsState) -> AppState | |
) -> Reducer { | |
return { appState, appEvent in | |
let newsState = appStateIntoNews(appState) | |
let newNewsState = newsReducer(newsState, appEvent) | |
return mutateAppStateWithNewsState(appState, newNewsState) | |
} |
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 transform( | |
newsReducer: @escaping (NewsState, AppEvent) -> NewsState, | |
appStateIntoNews: @escaping (AppState) -> NewsState | |
) -> Reducer { | |
return { appState, appEvent in | |
var appState = appState | |
let newsState = appStateIntoNews(appState) | |
let newNewsState = newsReducer(newsState, appEvent) | |
appState.newsState = newNewsState | |
return appState |
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 transform( | |
newsReducer: (NewsState, AppEvent) -> NewsState, | |
appStateIntoNews: (AppState) -> NewsState | |
) -> Reducer { | |
return { appState, appEvent in | |
let newsState = appStateIntoNews(appState) | |
return newsReducer(newsState, appEvent) | |
} | |
} |
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 transform(newsReducer: (NewsState, AppEvent) -> NewsState) -> Reducer { | |
return { appState, appEvent in | |
??? | |
} | |
} |
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 transform(newsReducer: (NewsState, AppEvent) -> NewsState) -> Reducer |
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 reduce(state: AppState, event: AppEvent) -> AppState |