如何解决无法在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 举报,一经查实,本站将立刻删除。