redux

Maintaining websocket connection in react router

ε祈祈猫儿з 提交于 2019-12-24 08:39:55
问题 I have a React/Redux app using React Router for routing. As part of this app I set up a websocket connection. An issue I'm facing is that when navigating directly to a url, the connection is dropped. For example: User lands on home page at www.app.com/ Websocket connection is established. User naviagtes to www.app.com/link via React Router browserHistory (there is no code to establish any connection on this page). Connection is maintained. This works as expected. However: User lands on home

ngrx updating state based on the angular2-router route

自作多情 提交于 2019-12-24 08:36:08
问题 So, continuing working on the redux-based Angular2 app with REST server. In the app I have the following reducers: AuthReducer -> AuthState UserReducer -> UserState UserListReducer -> UserListState ArticleReducer -> ArticleState ArticleListReducer -> ArticleListState The app uses many of those reducers in multiple places (i.e. pages/routes). The app state itself is composed the following way (app routes are in the comments): export interface AppState { localUser: AuthState //homePage with

Why do we need to create custom middleware as curried function in Redux

痴心易碎 提交于 2019-12-24 07:39:46
问题 I am new to Redux and was learning how to create middleware for React app. The question I would like to ask on the creation of custom middleware as CURRIED function, that is, why currying? what is the benefit of currying in the context of the creation of middleware. That is, instead of writing const middleware = store=>next=>action=>{} why not write const middleware = (store,next,action)=>{} . 回答1: Why Currying Actually Currying tries to minimize the number of changes to a program’s state

What's the best way to deal with a normalized response?

梦想的初衷 提交于 2019-12-24 07:34:53
问题 I'm using normalizr to normalize a response. My problem is that I don't know how to manage the normalized response. { result:[] entities: { words: { //... 1: { definitions: [1, 2, 3] } // other word objects... }, definitions: { 1: 'blah blah' 2: 'blah blah' 3: 'blah blah' // definition objects } } } I want to pass the words to a react component with definitions. How can I retrieve the words with nested definitions and render it to my component. 回答1: webpackbin DEMO assuming that your state

Redux state is being edited without dispatching any action

左心房为你撑大大i 提交于 2019-12-24 07:25:06
问题 I have an app with react + redux, and the problem is happening in the editing form. Description of the issue click "edit" to edit a document Show the edit form I edit/delete one of the values instead of saving (dispatching an action to save) I return to any other page without saving then comeback to the description page for this object (where the "edit" button is located) Result The document is edited. So, from the Portlets component, when I click on the edit button, I'll setState({isEditing:

Passing a click event to a function within a Promise tells me to use event.persist(), How?

末鹿安然 提交于 2019-12-24 07:17:20
问题 I have these 2 functions. I tried to pass the event "e" through to the promise, but in the "handleOnClick" function, e is null because it's out of the "this" scope. so I assigned the event to "this.clickEvent" and passed that instead, but now I get this long message about synethetic events and event.persist(). How do I fix this? handleClick( e ) { this.clickEvent = e; somePromise( param1, param2 ).then( result => { handleOnClick( this.clickEvent, param1, param2 ); }); } handleOnClick( e,

Redux: Call to action-creator returns 'Cannot read property 'props' of undefined'

假装没事ソ 提交于 2019-12-24 07:10:27
问题 I'm able to fetch the weather by a given city but can't figure how to delete it afterwards. Being still new to Redux I'm trying to figure which pieces am I missing on this puzzle. I'm leaving the FETCH_WEATHER code in just for context proposes. My issues is with the DELETE_CITY implementation. Bug: Steps: Add a button in each row that calls an action creator. Action creator takes the name of the 'city' and return an action of type 'DELETE_CITY'. Reducer, watches for that type and iterates

Filter array for angular2 + ngrx

我的梦境 提交于 2019-12-24 06:44:25
问题 I am trying to use this filter in an angular+ngrx app: fetchById(id: number): Document { return this.store.select( s => s.documents ).filter( obj => obj.id == id )[0] } documents is an array of Documents , and the latter have an id property. The idea is to filter the array to select one document. However, I get this error message: Property id does not exist on type Document[] . I don't understand the message, since obj is an element of the array, hence a certain object which has an id

mapDispatchToProps is not putting my function into props

大兔子大兔子 提交于 2019-12-24 06:41:55
问题 I am using React with Redux and following a tutorial, but I cannot for the life of me figure out this error. Uncaught TypeError: this.props.fetchPosts is not a function I have a src file with actions/index.js and I have a components/posts_index.js file. As far as I can tell, these are the only two files involved in this error, and I do not believe mapDispatchToProps is actually putting my function in this.props, but I don't know why. components/posts_index.js import React, { Component } from

React. New Router after login

旧街凉风 提交于 2019-12-24 06:39:26
问题 I have problem with Router in React, after login i change type state in Redux from 0 to 1, then i make switch in my App file, but i got error Warning: [react-router] You cannot change <Router routes>; it will be ignored This is my index.js, I want change all Route links if user is login (form with login work good and they change redux state type to 1): @connect((store)=>{ console.log(store) return { typeUser: store.app.type } }) class App extends React.Component{ render(){ switch(this.props