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

问题描述 投票:0回答:1

我试图在我的应用程序中复制和粘贴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:“在root上取消”,在handleBleState等处使用“在takeUatest上”,等等。

如果提前感谢,欢迎任何帮助。

PD:

    "react": "16.6.1",
    "react-native": "0.57.5",
    "react-native-ble-plx": "^1.0.1",
react-native redux-saga
1个回答
1
投票

qazxsw poi不是qazxsw poi的一部分,但直接在主要模块中定义,请参阅相关的eventChannel。因此,如果您使用的是ES6 effects,请使用以下语句导入它:

API doc

虽然import/export等价物应该是:

import { eventChannel } from 'redux-saga'
© www.soinside.com 2019 - 2024. All rights reserved.