首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Redux产量产卵takeEvery呼叫无过载

Redux产量产卵takeEvery呼叫无过载
EN

Stack Overflow用户
提问于 2021-02-25 11:15:19
回答 1查看 359关注 0票数 1

我使用redux-saga版本1.1.3,这里有以下内容:

代码语言:javascript
运行
复制
import {
  spawn,
  race,
  take,
  call,
  put,
  takeEvery,
  delay,
} from "redux-saga/effects";
import {
  MessageCenterActionTypes
} from "../types";

function remove(notification) {
  return {
    type: MessageCenterActionTypes.MESSAGECENTER_REMOVE,
    notification,
  };
}

export function* saga() {
  yield spawn(
    takeEvery,
    MessageCenterActionTypes.MESSAGECENTER_ENQUEUE,
    removeNotificationAfterElapsedTime,
    4000,
  );
}

export function* removeNotificationAfterElapsedTime(waitFor, {
  notification
}) {
  const {
    shouldBeRemoved
  } = yield race({
    shouldBeRemoved: call(delay, waitFor),
    _: take(
      (action) =>
      action.type === MessageCenterActionTypes.MESSAGECENTER_REMOVE &&
      action.notification.id === notification.id,
    ),
  });

  if (shouldBeRemoved) {
    yield put(remove(notification));
  }
}

export default saga;

但在yield spawn(takeEvery, MessageCenterActionTypes.MESSAGECENTER_ENQUEUE, removeNotificationAfterElapsedTime, 4000,);

上面写着:

代码语言:javascript
运行
复制
No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ <P extends ActionPattern<Action<any>>>(pattern: P, worker: (action: ActionMatchingPattern<P>) => any): ForkEffect<never>; <P extends ActionPattern<...>, Fn extends (...args: any[]) => any>(pattern: P, worker: Fn, ...args: HelperWorkerParameters<...>): ForkEffect<...>; <A extends Action<...>>(pattern: ActionPattern...' is not assignable to parameter of type '{ context: unknown; fn: (this: unknown, ...args: any[]) => any; }'.
      Type '{ <P extends ActionPattern<Action<any>>>(pattern: P, worker: (action: ActionMatchingPattern<P>) => any): ForkEffect<never>; <P extends ActionPattern<...>, Fn extends (...args: any[]) => any>(pattern: P, worker: Fn, ...args: HelperWorkerParameters<...>): ForkEffect<...>; <A extends Action<...>>(pattern: ActionPattern...' is missing the following properties from type '{ context: unknown; fn: (this: unknown, ...args: any[]) => any; }': context, fn

电话应该是什么样子的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-01 18:41:46

spawn函数可以接受单个生成器函数,在这个生成器函数中,您可以定义您的takeEvery逻辑。您的其余代码不需要任何更改。

代码语言:javascript
运行
复制
export function* saga() {
  yield spawn(function*() {
    yield takeEvery(
      MessageCenterActionTypes.MESSAGECENTER_ENQUEUE,
      removeNotificationAfterElapsedTime,
      4000,
    );
  });
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66367421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档