redux-saga

What is the idiomatic way of starting rootSaga?

霸气de小男生 提交于 2019-12-04 07:50:10
问题 redux-saga project has been existing for a pretty long time now, but still there are a lot of confusing things about this library. And one of them is: how to start your rootSaga. For example, in the beginner tutorial rootSaga is started by yeilding an array of sagas. Like this export default function* rootSaga() { yield [ helloSaga(), watchIncrementAsync() ] } However, in the using saga helpers section rootSaga consists of two forked sagas. Like this: export default function* rootSaga() {

[react] - 循环请求 redux-saga

廉价感情. 提交于 2019-12-03 23:53:40
//根据uuid 获取 apt报告信息 *getNotesByUid({ payload, callback }, { call, put }) { // payload 是个数组, 并发执行,参考redux-saga文档 let resArr = yield payload.map(item => { return call(getNotesByUuid,item.uuid) }) resArr = resArr.map((obj,index) => { if(obj.code === 0){ return { ...obj.data, uuid:payload[index].uuid } } return {...payload[index], nodata:true }; //获取失败 不显示 }) callback && callback(resArr); }, 来源: https://www.cnblogs.com/chengyunshen/p/11812038.html

MVVM architectural pattern for a ReactJS application

走远了吗. 提交于 2019-12-03 15:52:19
问题 I'm a semi-senior react and JavaScript developer, I've made several Universal react application. Today our CTO told me: Do you use a software architectural pattern for your application? I've no answer, He points to the Android team which use MVVM for their applications. I'm searching greedy but not found a trend methodology or example for this situation. I've used Redux , Redux-Saga , React-Context and etc. I don't know how to explain to our CTO or what is his answer? Hence: Does a react app

How to tie emitted events events into redux-saga?

痴心易碎 提交于 2019-12-03 12:10:59
问题 I'm trying to use redux-saga to connect events from PouchDB to my React.js application, but I'm struggling to figure out how to connect events emitted from PouchDB to my Saga. Since the event uses a callback function (and I can't pass it a generator), I can't use yield put() inside the callback, it gives weird errors after ES2015 compilation (using Webpack). So here's what I'm trying to accomplish, the part that doesn't work is inside replication.on('change' (info) => {}) . function *

How do i check for token expiration and logout user?

半世苍凉 提交于 2019-12-03 05:54:43
问题 The user can logout himself when he/she clicks on the logout button but if the token is expired he/she cant logout because in my application, the token is used in both server side and front end. When user clicks on the logout button, the token from both server and browser is cleared if token is valid. There is a chance that when user does not log out and his/her token expires but is not being cleared in the browser. For addressing this situation, how do i check for token expiration every time

MVVM architectural pattern for a ReactJS application

大憨熊 提交于 2019-12-03 05:26:12
I'm a semi-senior react and JavaScript developer, I've made several Universal react application. Today our CTO told me: Do you use a software architectural pattern for your application? I've no answer, He points to the Android team which use MVVM for their applications. I'm searching greedy but not found a trend methodology or example for this situation. I've used Redux , Redux-Saga , React-Context and etc. I don't know how to explain to our CTO or what is his answer? Hence: Does a react app really need a software architectural pattern? React itself is not particularly opinionated about

getState in redux-saga?

混江龙づ霸主 提交于 2019-12-03 03:51:14
问题 I have a store with a list of items. When my app first loads, I need to deserialize the items, as in create some in-memory objects based on the items. The items are stored in my redux store and handled by an itemsReducer . I'm trying to use redux-saga to handle the deserialization, as a side effect. On first page load, I dispatch an action: dispatch( deserializeItems() ); My saga is set up simply: function* deserialize( action ) { // How to getState here?? yield put({ type: 'DESERISLIZE

Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/await

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: There is a lot of talk about the latest kid in redux town right now, redux-saga/redux-saga . It uses generator functions for listening to/dispatching actions. Before I wrap my head around it, I would like to know the pros/cons of using redux-saga instead of the approach below where I'm using redux-thunk with async/await. A component might look like this, dispatch actions like usual. import { login } from 'redux/auth'; class LoginForm extends Component { onClick(e) { e.preventDefault(); const { user, pass } = this.refs; this.props.dispatch

redux-saga when to use fork?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: what would be the difference between the two approaches below? export function* watchLoginUser() { yield takeEvery(USER_LOGIN, loginUser) } export function* watchLogoutUser() { yield takeEvery(USER_LOGOUT, logoutUser) } export function* watchGetParties() { yield takeEvery(PARTIES_GET, getParties) } export default function* root() { yield [ fork(watchLoginUser), fork(watchLogoutUser), fork(watchGetParties) ] } export default function* root() { yield [ takeEvery(USER_LOGIN, loginUser), takeEvery(USER_LOGOUT, logoutUser), takeEvery(PARTIES_GET,

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

大城市里の小女人 提交于 2019-12-03 01:49:35
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); iter.next(); // do I really need to do this? }; function* getTransactions() { while(yield take('APP