[英]Redux Saga - yield spawn takeEvery call no overload
I use redux-saga version 1.1.3 and have this here:我使用 redux-saga 版本 1.1.3 并在这里:
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;
But in
yield spawn(takeEvery, MessageCenterActionTypes.MESSAGECENTER_ENQUEUE, removeNotificationAfterElapsedTime, 4000,);
但是在
yield spawn(takeEvery, MessageCenterActionTypes.MESSAGECENTER_ENQUEUE, removeNotificationAfterElapsedTime, 4000,);
it says:它说:
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
How should the call look like?通话应该是什么样子?
spawn
function can accept single generator function and inside of this generator function you can define your takeEvery
logic. spawn
function 可以接受单个生成器 function 并且在此生成器 function 内部,您可以定义您的takeEvery
逻辑。 The rest of your code doesn't require any changes.您的代码的 rest 不需要任何更改。
export function* saga() {
yield spawn(function*() {
yield takeEvery(
MessageCenterActionTypes.MESSAGECENTER_ENQUEUE,
removeNotificationAfterElapsedTime,
4000,
);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.