undefined 不是一个对象(评估'_effects.buffers.expanding')

undefined is not an object (evaluating '_effects.buffers.expanding')

尝试在我的应用程序中复制和粘贴 this 解决方案时出现错误。

undefined 不是对象(正在计算 'effects.buffers.expanding')

我的代码非常相似:

export function* handleBleState() {
  const {
    bleConnections: { manager },
  } = yield select()

  const stateChannel = yield eventChannel((emit) => {
    const subscription = manager.onStateChange((state) => {
      emit(state)
    }, true)
    return () => {
      subscription.remove()
    }
  }, buffers.expanding(1))

  try {
    for (;;) {
      const newState = yield take(stateChannel)
      const power = newState === 'PoweredOn'
      yield put(BLEActions.updateBleState(power))
    }
  } finally {
    if (yield cancelled()) {
      stateChannel.close()
    }
  }
}

但比较奇怪的是,我从redux-saga的documentation中提取了代码,错误也是类似的。 我用这个替换了部分代码:

  const stateChannel = yield eventChannel((emitter) => {
    const iv = setInterval(() => {
      secs -= 1
      if (secs > 0) {
        emitter(secs)
      } else {
        // this causes the channel to close
        emitter(END)
      }
    }, 1000)
    // The subscriber must return an unsubscribe function
    return () => {
      clearInterval(iv)
    }
  })

我得到:

undefined 不是一个函数(计算 '(0, _effects.eventChannel)')

我正在使用另一个版本的 redux-saga:

    "redux-saga": "^1.0.2",

但我试过他使用的相同版本

    "redux-saga": "0.16.2"

然后是另一个问题:

console.error: "unchaught at root", "at root at takeLatest" 在 handleBleState 等

欢迎任何帮助,提前致谢。

PD:

    "react": "16.6.1",
    "react-native": "0.57.5",
    "react-native-ble-plx": "^1.0.1",

eventChannel 也不是 effects 的一部分,而是直接在主模块中定义,参见相关 API doc。因此,如果您使用的是 ES6 import/export,则可以使用以下语句导入它:

import { eventChannel } from 'redux-saga'

require 等价物应该是:

const eventChannel = require('redux-saga').eventChannel