如何连接React Native Saga以响应Native Firebase

时间:2019-02-08 13:51:27

标签: firebase react-native google-cloud-firestore redux-saga react-native-firebase

我有这些麻烦,但是我每次都在频道和失败动作上退订。是什么原因?我正在使用React Native Firebase和RNFirestore

 function firebaseChannel(userId) {
  const ref = database
    .collection("chat_rooms")
    .where("metadata.members." + userId, ">", 0)
    .orderBy("metadata.members." + userId, "desc")

  const channel = eventChannel(emit => {
    const unsubscribe = ref.onSnapshot(emit)
    // Returns unsubscribe function
    return unsubscribe
  })
  return channel
}

export function* sync() {
  const userId = getUserId()
  const channel = yield call(firebaseChannel, userId)

  try {
    while (true) {
      const data = yield take(channel);
      yield fork(successActionCreator(data, userId));
    }
  } catch (err) {
    // yield fork(failureActionCreator(err))
    console.tron.log("Failure", err)
  }
  finally {
    // if (yield cancelled()) {
    //   channel.close();
    // }
  }
}

0 个答案:

没有答案