redux

Composing and sequencing multiple epics in redux-observable

我与影子孤独终老i 提交于 2019-12-21 05:57:01
问题 I have a problem that I don't know how to resolve. I have two epics that do requests to api and update the store: const mapSuccess = actionType => response => ({ type: actionType + SUCCESS, payload: response.response, }); const mapFailure = actionType => error => Observable.of({ type: actionType + FAILURE, error, }); const characterEpic = (action$, store) => action$.ofType(GET_CHARACTER) .mergeMap(({ id }) => { return ajax(api.fetchCharacter(id)) .map(mapSuccess(GET_CHARACTER)) .catch

Angular Forms with Redux

≯℡__Kan透↙ 提交于 2019-12-21 05:22:25
问题 Looking for some advice when working with Redux, and Angular. I've been researching Redux for the past couple of days and really think its a great way to store application data. The part I'm having trouble with is whether to persist everything within the store or only certain parts. Ideally, I think the entire application should be running through the store, but for forms this seems very tedious. For example, lets say I'm working with a form to add a new product. Here are some of my pain

Use react-redux connect in typescript

孤人 提交于 2019-12-21 04:39:23
问题 I try to build a react app in typescript using redux and react-router-dom. I ran into typing issues when I added redux to my app. Thus I created the following minimal example with only one page test-page : App.jsx import * as React from 'react'; import { Route, Redirect } from 'react-router-dom' import Test from './containers/test-page' import './App.css'; class App extends React.Component { render() { return ( <div className="ui container" id="main"> <Route exact path="/" render={() =>

React Redux - Why mapStateToProps is called before constructor?

强颜欢笑 提交于 2019-12-21 04:35:16
问题 Two questions: Why mapStateToProps is called before constructor? As a side-effect of 1 constructor (props) { base(props) // props already have values from "mapStateToTprops" } why that is being done automagically? Not every mapStateToProps invokes ComponentWillReceiveProps (this is the case when it loads first time) See this link enter link description here Update 1 If I want to write a condition like: if (props.isAuthenticated) { browserHistory.push("/admin/dashboard") } Which method will be

Use of boilerplate actions and reducers in redux

荒凉一梦 提交于 2019-12-21 04:09:06
问题 I have been following the widely given advice of learning React development by first mastering component props , encapsulating UI state in component level this.state and passing it down selectively through the component tree. It's been an enlightening experience. I've come to appreciate the power of the stateless view design pattern and I feel that I've been able to achieve robust and well organized results using these techniques. Moving on, I am now trying to incorporate more sophisticated

Where to put API calls in React/Redux architecture?

我们两清 提交于 2019-12-21 03:53:27
问题 I am trying to retrieve some data from an API and pass it into my application. Being new to React/Redux however, I am wondering where to make these calls from and how to pass it into my application? I have the standard folder structure (components, reducers, containers, etc.) but I'm not sure where to place my API calls now. 回答1: The easiest way to get started with this is to just add it into your actions, using a function called a thunk along with redux-thunk. All you need to do is add thunk

Should I use one or several action types to represent this async action?

守給你的承諾、 提交于 2019-12-21 03:43:28
问题 I'm building a front-end for a search system where almost all user actions need to trigger the same async action to re-fetch search results. For example, if a user enters a keyword, then we need to fetch /api/search?q=foo , and if they later select a category we fetch /api/search?q=foo&categoryId=bar . I originally had separate action types for FETCH_RESULTS , SELECT_CATEGORY , DESELECT_CATEGORY , etc. I created one asynchronous action creator for FETCH_RESULTS , but the others are

ReactJS: How to wrap react-select in redux-form field?

情到浓时终转凉″ 提交于 2019-12-21 03:36:09
问题 I am working on react-select library and facing some issues, I am using redux-form library and importing <Field /> component from it. So that I can submit the values via form to service. Below mentioned code works fine, when I use default <Select> from react-select. I can able to select the values from the drop down and the value will be selected even on focus out the value will remain. But selected value is not submitting via form due to redux-form that's why I am wrapping <Select />

Redux; accessing other parts of the state when using composed reducers via combineReducers

三世轮回 提交于 2019-12-21 03:33:04
问题 Update Thanks to @Dominic Tobias and @gabdallah for spotting my embarrassing mistake. The correct answer is of course; so try checking action.payload . The other comments regarding the switch statement and the action object we're referring to errors I made in my example, which I've since corrected. Imagine I've combined the the following two reducers; import { combineReducers } from 'redux' import { routerStateReducer } from 'redux-router' import entries from './entries' export default

How to unit test async Redux actions to mock ajax response

梦想与她 提交于 2019-12-21 01:11:28
问题 I am creating a middleware for making ajax requests using async actions. The middleware intercepts original action, performs ajax request, and re- dispatch es the original action along with the response from the url . So, my Component would merely dispatch an action like this onClick() { dispatch(ActionCreator.fetchUser()); } Rest will be taken care by the middleware as shown here. My question is, what should I do for unit testing? Should I mock the onClick itself? or I should write a mocked