reduce(action: Action, state: ProductListState?) -> ProductListState { var nextState = state ?? ProductListState() switch action { case let action as ProductListState.LoadingStart: nextState.loadingType = action.loadingType case let action as ProductListState.LoadingSuccess: if action.loadingType == .add { nextState.list += action.response } else { nextState.list = action.response } case is UpdateFavoriteStart: nextState.isUpdatingFavoriteSucceeded = nil case is UpdateFavoriteSuccess: nextState.isUpdatingFavoriteSucceeded = true default: break } return nextState } }
nil ) @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { [...] } To maintain our state and delegate the actions to the reducers, we need a store. Let's call it mainStore and define it as a global constant, for example in the app delegate file:
String var todayViewState: TodayViewState? // or todayViewState = TodayViewState() var gameViewState: GameViewState? var appViewState: AppViewState? var updateViewState: UpdateViewState? var searchViewState: SearchViewState? var appDetailViewState: [AppIdentifier: AppDetailViewState] = [:] }