我需要每隔一段时间获取数据。我目前使用react组件来容纳我的逻辑,只渲染null,但我在我的应用程序中添加了redux-saga,我宁愿将流程转移到saga。我还不知道如何使用生成器回调或从回调中调用生成器。
以下是我到目前为止构建的内容:
// @flow
import { takeLatest, all, put, select } from 'redux-saga/effects';
import * as types from '../constants/ActionTypes';
let timers: Array<IntervalID>
因此,我试图使用jest从call中模拟redux-saga/effects函数,它似乎抛出了一个错误,说的是call is not declared configurable。
import * as mockreduxSagaEffects from 'redux-saga/effects';
test('calls all the appropriate actions', async () => {
const dispatchedActions = [];
jest.spyOn(mockreduxSagaEffects, &
我想在一个saga中引入一个延迟(使用redux-saga)。
我该怎么做呢?
如果redux-saga提供了API,我也会对如何手动实现它感兴趣。
function* save({ payload }) {
yield put(pending());
// I want to simply wait (non-blocking) here for say 2 seconds
yield put(complete());
}
我正在尝试理解redux-saga是如何工作的,用react,redux和react-redux实现了一个简单的例子(一个按钮,当点击这个按钮时,从一个API中获取一个用户,然后reducer将这个用户添加到存储中)。
这是我的传奇(使用console.logs进行调试):
import { take, call, put } from 'redux-saga/effects';
import { GET_USER, setUser } from './actions/actionCreators';
export default function * w
所以,我试着为我的Redux组件做一个小测试,在这个测试中,我只发送了空的obj {}。并尝试在我的测试文件中与之相等,如expect(get).toEqual(obj)。我在错误日志中得到的信息:
$ yarn test
yarn run v1.5.1
warning ..\..\..\..\package.json: No license field
$ react-scripts test --env=jsdom
FAIL src\saga\saga.test.js
● get new action value
expect(received).toEqual(expected
我正在尝试实现乘法传奇,但由于某种原因,它已经停止了对我的工作,我不知道为什么。
这是我的完整代码:
// store/sagas/sagas/auth.js
import { delay } from 'redux-saga';
import { put, call } from 'redux-saga/effects';
// When the client enter input on email / password textboxes on auth form.
export function* sagaFunction1(action) {