我们如何使用参数调用ReSwift的异步操作?
我创建了这个异步操作:
func searchItems(state: AppState, store: Store<AppState>) -> Action? {
var items = [Artwork]()
HttpHelper.post(url: serverApi.search.rawValue, params: ["term": ""]) { data in
if let data = data as? [[String: Any]] {
for row in data {
items.append(Artwork(data: row))
}
DispatchQueue.main.async {
store.dispatch(UpdateItems(items: items))
}
}
}
return nil
}
为了发送动作,我使用了
store.dispatch(searchItems)
但我不知道如何将搜索字词附加到操作中。
答案 0 :(得分:0)
想出来。这是一个例子:
import ReSwift
struct GetShowroom: Action {
let code: String
init(code: String) {
self.code = code
getIt()
}
func getIt() {
store.dispatch(UpdateLoading(loading: .Showroom(code: self.code)))
HttpHelper.post(to: .getShowroom, params: ["code": self.code]) { res in
if let data = res as? [String: Any] {
store.dispatch(UpdateShowroom(showroom: Showroom(code: self.code, data: data)))
}
}
}
}