redux-saga

How do I create a leading debounce with redux-saga

陌路散爱 提交于 2020-01-03 15:52:07
问题 Is there a way to do a leading debounce? The example on the recipes only shows a trailing debounce. So below is trailing debounce example where we delay the logic fro 500ms: import { call, cancel, fork, take, delay } from 'redux-saga/effects' function* handleInput(input) { // debounce by 500ms yield delay(500) ... } function* watchInput() { let task while (true) { const { input } = yield take('INPUT_CHANGED') if (task) { yield cancel(task) } task = yield fork(handleInput, input) } } where as

Can I use redux-saga's es6 generators as onmessage listener for websockets or eventsource?

自闭症网瘾萝莉.ら 提交于 2019-12-31 21:33:10
问题 I'm trying to get redux-saga working with the onmessage listener. I don't know why what I have isn't working. I have the following set-up. // sagas.js import { take, put } from 'redux-saga'; import {transactions} from "./actions"; function* foo (txs) { console.log("yielding"); // appears in console yield put(transactions(txs)); // action *is not* dispatched console.log("yielded"); //appears in console } const onMessage = (event) => { const txs = JSON.parse(event.data); const iter = foo(txs);

make a HTTP Request from React-Redux from localhost

我们两清 提交于 2019-12-25 11:58:26
问题 I am new to React Redux, and All I already did: 1) activate my backend server (localhost:5000) 2) activate my front-end server using npm start (localhost:8080) 3) I tried to dispatch action by using this.props.dispatch({type: ActionTypes.FILE_UPLOAD_REQUEST, email: this.state.email, file: this.state.policyFile}); 4) Using atlas-saga, and call my service function associated with the dispatch : let result = yield call(Atlas.uploadFile, action.email, action.file); 5) define the function as :

How is multitasking achieved in Redux Middleware?

做~自己de王妃 提交于 2019-12-25 04:27:28
问题 Since preemptive multitasking is not available in a browser, and JavaScript is inherently single threaded, how does a Redux Middleware like redux-saga handle infinite loops not designed for cooperative multitasking without triggering the long-running script dialog? function* watchSaga() { while (true) { yield take(SOME_REQUEST); // do something } } Edit My statement "not designed for cooperative multitasking" was wrong. A generator function's code is executed only until the first yield

Redux-Saga Channel pass in variable for API call

会有一股神秘感。 提交于 2019-12-24 10:49:17
问题 Summary I'm using redux-saga-firebase and to listen for changes in Firestore and I want to pass in a variable from my redux store to my watcher function. I'm new to redux so I'm having some trouble. I think I should use a selector but I'm not 100% how to do so. I'm also open any other solutions! Code Watcher Saga export function* watchSquadChannel() { const userData = "345fgr45gdgdfdfe"; try { yield put(syncSquadLoading()); const channel = RSF.firestore.channel( `data/${userData}`, "document"

Redux-saga get data from action returns patternOrChannel is undefined

帅比萌擦擦* 提交于 2019-12-24 03:21:56
问题 I need to send dynamic data from my screen to action/reducer and fetch data from API with that data, but when i yield in my rootSaga i'll get an error like this: uncaught at check take(patternOrChannel): patternOrChannel is undefined uncaught at rootSaga at rootSaga at takeEvery Error: take(patternOrChannel): patternOrChannel is undefined Screen code: import { checkUserLoginStatus, userSignin } from '../actions/user'; class PreCheckout extends PureComponent { handleLogin = () => { this.props

how to test redux-saga all effect using jest

て烟熏妆下的殇ゞ 提交于 2019-12-24 01:15:57
问题 function* mySaga() { const [customers, products] = yield all([ call(fetchCustomers), call(fetchProducts) ]) } I want to test all effect in jest but I get: Invalid attempt to destructure non-iterable instance my code is: const generator = mySaga() expect(generator.next().value).toEqual(all([ call(fetchCustomers), call(fetchProducts) ])) 回答1: I want to test all effect in jest but I get To deal with an error, it is necessary to understand at first how function generator generally works,

How to access state from inside mapDispatchToProps

。_饼干妹妹 提交于 2019-12-24 00:12:39
问题 Need to dispatch an action based on state or presentaional component's props. const mapDispatchToProps = (dispatch) => { return { onClick: () => { if (state.someValue || this.props.someValue){ dispatch({type: DO_SOMETHING}) } } } } and this action is supposed to be intercepted by redux-saga to do some remote fetching tasks, so I can't move this condition into reducer like: const reducer = (state, action) => { switch (action.type){ case DO_SOMETHING: if(state.someValue){ return {...state, //do

每天一点面试题(14) ------------Redux-saga

末鹿安然 提交于 2019-12-23 21:38:21
Redux-saga Saga相关概念 1987年普林斯顿大学的Hector Garcia-Molina和Kenneth Salem发表了一篇Paper Sagas,讲述的是如何处理long lived transaction(长活事务)。Saga是一个长活事务可被分解成可以交错运行的子事务集合。其中每个子事务都是一个保持数据库一致性的真实事务。 redux-saga是一个用于管理redux应用异步操作的中间件 redux-saga通过创建sagas将所有异步操作逻辑收集在一个地方集中处理,可以用来代替redux-thunk中间件。 这意味着应用的逻辑会存在两个地方 (1) reducer负责处理action的stage更新 (2) sagas负责协调那些复杂或者异步的操作 sagas是通过generator函数来创建的 sagas可以被看作是在后台运行的进程。sagas监听发起的action,然后决定基于这个action来做什么 (比如:是发起一个异步请求,还是发起其他的action到store,还是调用其他的sagas 等 ) 在redux-saga的世界里,所有的任务都通过用 yield Effects 来完成 ( effect可以看作是redux-saga的任务单元 ) Effects 都是简单的 javascript对象,包含了要被 saga middleware

How to dispatch a thunk from a saga?

与世无争的帅哥 提交于 2019-12-23 14:02:24
问题 I know I shouldn't be trying to dispatch thunks from sagas, it goes against what redux-saga tries to do. But I'm working in a fairly large app and most of the code is made with thunks, we are migrating by bits and need to dispatch a thunk from inside a saga. The thunk can't be changed because it is used in other parts (a thunk that returns a promise), so it would break many things. configureStore: const store = createStore( rootReducer, initialState, compose(applyMiddleware(thunk,