如何在side回调中使用yield call()putt()回调

时间:2017-09-22 02:23:48

标签: react-native redux mqtt redux-saga

我有像

这样的生成器功能
function* subscribe(action) {
  const topic = action.payload;

  client.subscribe(topic);
  yield put(MqttActions.onConnect(connected));
  client.onMessageArrived = (message) => {

    console.log('MESSAGE==',message.payloadString);
   //yield put(MqttActions.onMessageArrived(message));

  };
     yield put(MqttActions.onMessageArrived(client.onMessageArrived));

  client.onConnectionLost = (responseObject) => {
    console.log({ responseObject });
    //yield put(MqttActions.onConnectionLost(responseObject));


  };
}

export default function* mSagas() {
  yield all([fork(takeLatest, MqttActions.CONNECTING, connection)]);
  yield all([fork(takeLatest, MqttActions.SUBSCRIBE, subscribe)]); 

}

我的问题在这里我无法在side client.onMessageArrived =(message)=>中产生put(MqttActions.onMessageArrived(message))。 {}如何使用yield这里可以在client.onMessageArrived发生时调度动作,这是怎么做的

0 个答案:

没有答案