redux-saga,网络调用功能完成了吗?

redux-saga, call function on network complete?

我想在网络获取完成时调用组件的函数。

function callRestApi({config, schema}) {
   return axios(config).then((response) => {

     if (schema) {
       var data = normalize_json(response.data, schema)
       response.entities = data.entities
     }

     return response
   })
 }

 function* fetchEventList(action) {
   try {
     const response = yield call(callRestApi, action.payload);
     // here I want to call a component's method if possible
     yield put({type: action.response.action_type_success, response});
   } catch (e) {
   }
 }

我可以想到两种方法来做到这一点,想知道是否有一种方法优于另一种方法,或者是否有更好的方法?

第二个。您正在使用 redux-saga 来处理副作用,所以请保持这种状态。您可以将回调作为 method1 添加到操作中,但我不会混淆概念。

如果您成功更新商店,它将重新渲染组件,正如您所说,您可以在 componentWillReceiveProps 中检查新更新的道具并触发该功能,但是,检查 nextProps 而不是 this.props(但我打赌你已经知道了)。

这样一切都以一种方式进行,没有回调地狱 :) + 你可以通过传递一个 prop 轻松地测试组件。

虽然这本身不是一个坏模式,但传递回调将是双向流,这打破了通量的第一条规则:单向流。