2017-10-01 69 views

回答

0

例如,在AppDelegate中

var store = Store<AppState>(reducer: AppReducer(), state: nil) 

在AppReducer

func handleAction(action: Action, state: AppState?) -> AppState { 
    return AppState(
     dbState: DBReducer(state: state?.dbState, action: action) 
     //other states 
    ) 
} 

在DBReducer

func DBReducer(state: DBState?, action: Action) -> dbState { 
    var state = state ?? DBState() 
    //actions state change 
} 

在初始化DBState從數據庫

+0

這是如此非常錯誤的獲取數據.. reducer應該是純粹的func tions –

+0

來自ReSwift存儲庫的這個例子https://github.com/ReSwift/GitHubBrowserExample/blob/master/SwiftFlowGitHubBrowser – Dialogue

+0

可能是一個過時的例子,reducer應該總是純粹的函數,這是Redux非常基本的概念之一。 –