无法在SwiftUI中更新Redux流的全局状态

问题描述

我正在尝试在SwiftUI中实现Redux状态,并且在执行动作创建者之后一直坚持更新全局状态。我不知道在商店调度功能中该做什么。

// Store.swift 

typealias ActionCreator = (_ dispatch: @escaping (Action) -> ()) -> ()

func getMovies() -> ActionCreator {
    return { dispatch in
        
        dispatchQueue.main.asyncAfter(deadline: .Now() + 2.0) {
            dispatch(.populateMovies([Movie(title: "ABC")]))
        }
    
    }
}

class Store: ObservableObject {
    
    var reducer: Reducer
    @Published private (set) var appState: AppState
    
    init(appState: AppState,reducer: Reducer) {
        self.appState = appState
        self.reducer = reducer
    }
    
    func dispatch(_ dispatch: ActionCreator) {
        // how to send the movies to the reducer to update the state 
        //self.reducer.update(&appState,dispatch)
    }
}



// ContentView: 

store.dispatch(getMovies()) 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)