redux-saga

React Redux with Router Location, Pagination / Sorting and Fetch

人盡茶涼 提交于 2019-12-22 12:09:27
问题 I'm writing some generic Todo-List component, with the following features Pagination / Sorting Keep a part of the state within the URL (page, sort) Fetching the Data asynchronously using HTTP Requests (using redux-saga) Now I'm trying to find a pattern for the "best" sequence of redux actions to get this working without problems. I want the following behavior: When Todo Component loads: Read URL Query Parameters and use this to fetch the data. When the user clicks sort by name (or next page

Using redux-saga with react-router

六眼飞鱼酱① 提交于 2019-12-22 10:27:39
问题 I have a question about react-router: for example, I want to redirect from Create form to Edit form after called to create api (using redux-saga) successfully. How should I use react-router in this case? 回答1: If you include also react-router-redux you can simply treat the page change as another redux action to call from saga (using the new push API). Something like... yield put(push('your/route')) 来源: https://stackoverflow.com/questions/45878719/using-redux-saga-with-react-router

redux saga and history.push

风格不统一 提交于 2019-12-21 17:05:09
问题 Backgrond: I am creating a Login component. saga.js is composed by 3 functions 1. rootSaga . It will execute the list of sagas inside 2. watchSubmitBtn . It will watch the click on the submit button and dispatch an action. 3. shootApiTokenAuth will receive dispatched action and process axios.post the return value is promise object In action: Backend returns 400 to the React . This case no problem I can read the payload and display in the render() easily. But when 200 is returned. I need to

Redux05 Redux-Saga

旧巷老猫 提交于 2019-12-21 01:44:23
简介 redux-saga 是用来管理应用程序副作用的库,可以认为,一个saga就像是应用程序中一个单独的线程,独自负责处理副作用。 redux-saga 是一个Redux中间件,也就意味着这个线程可以通过正常的Redux的Action从主应用启动暂停和取消,它能够访问完整的Redux的State,也可以进行 dispatch redux-saga 使用了 Generator ,让异步流程看起来像是同步代码,有更强大的异步流程控制能力。 Hello Saga 安装: npm install --save redux-saga # 或者 yarn add redux-saga 创建 sagas.js 文件,我们的异步逻辑都会包含在这个文件中: // sagas/index.js export default function* helloSaga() { console.log('Hello Sagas!'); } Redux-Saga是一个中间件,我们需要建立它与Redux Store的联系,在 store/configureStore.js 中对 store 进行配置,注入中间件: // store/configureStore.js import { createStore, applyMiddleware } from 'redux'; import rootReducer

Redux Saga async/await pattern

跟風遠走 提交于 2019-12-20 09:28:24
问题 I'm using async/await throughout my codebase. Because of this my api calls are defined by async functions async function apiFetchFoo { return await apiCall(...); } I would like to call this function from my saga code. It seems like I can not do this: // Doesn't work function* fetchFoo(action) { const results = await apiFetchFoo(); yield put({type: "FOOS_FETCHED_SUCCESSFULLY", foos: results}); } However, this does work, and matches the redux saga documentation: // Does work function* fetchFoo

redux saga, throttle/debounce conditionally?

◇◆丶佛笑我妖孽 提交于 2019-12-19 04:14:31
问题 I'm logging banner impressions when it is visible on screen. When a user scrolls, the same banner can be made visible multiple times in short time period. And I'd like to prevent that. On first thought, throttle is perfect way of preventing it. But then when you have multiple banners in one page, throttle would not log the 2nd banner in screen if throttled. So how can I throttle per key? (banner id as a key in this example) ie, I want to throttle banner impression per banner_id. (it's like

How to dispatch Redux action from stateless component when route is loaded?

戏子无情 提交于 2019-12-18 12:46:01
问题 Goal : when loading a react-router route, dispatch a Redux action requesting asynchronic Saga worker to fetch data for the underlying stateless component of that route. Problem : stateless components are mere functions and don't have lifecycle methods, such as componentDidMount, so I can't(?) dispatch Redux action from inside the function. My question is partly related to Converting stateful React component to stateless functional component: How to implement "componentDidMount" kind of

How to get something from the state / store inside a redux-saga function?

穿精又带淫゛_ 提交于 2019-12-18 09:58:41
问题 How do I access the redux state inside a saga function? Short answer: import { select } from 'redux-saga'; ... let data = yield select(stateSelectorFunction); 回答1: As @markerikson already says, redux-saga exposes a very useful API select() to invoke a selector on the state for getting some part of it available inside the saga. For your example a simple implementation could be: /* * Selector. The query depends by the state shape */ export const getProject = (state) => state.project // Saga

redux-saga细说

旧街凉风 提交于 2019-12-18 03:04:27
参考: https://blog.csdn.net/sinat_17775997/article/details/103524043 https://www.jianshu.com/p/6f96bdaaea22 redux-saga 中常见的几种模式(翻译)https://www.jianshu.com/p/c3425f9ef6b7 take([...]) 和 race 的比较重要的语境区别是: take([...]) 是等待第一个相匹配的action的到达 race 是等待第一个 racing-effect 的完成 1.概述 Redux-saga是一个用于管理 Redux 应用异步操作的中间件(又称异步action) 本质都是为了解决异步action的问题 Redux Saga可以理解为一个和系统交互的常驻进程,这个线程可以通过正常的Redux Action从主应用程序启动, 暂停 和 取消 ,它能访问完整的Redux state,也可以dispatch Redux Action。 一个 Saga 就像是应用程序中一个单独的线程,它独自负责处理副作用。 其中,Saga可简单定义如下的公式: Saga = Worker + Watcher 2.简单使用 redux-saga本质是一个可以自执行的generator。 在 redux-saga 中,UI 组件自身从来不会触发任务

Redux-saga not able to read react-native

帅比萌擦擦* 提交于 2019-12-13 21:17:03
问题 I am trying a read a Image File using react-native-fs in react-native. Below is my generator function in saga.js: function* uploadCardLogo(logo, userId) { console.log("uploading card logo"); //being logged const storageRef = firebase.storage().ref('${userId}').child("mycards/logos/"); console.log("storage ref fetched " + logo.uri); //being logged const cardLogo = yield call(RNFS.readFile, logo.uri); // Not throwing any errors console.log("reading file done") // Not being logged const