reactjs-flux

React.js - flux vs global event bus

北战南征 提交于 2019-12-03 12:29:16
What is the advantage of using Flux over a global event bus? I think the dispatcher is all that is needed: component publishes 'user event' with data to the dispatcher dispatcher executes handler of the subscribed store handler publishes 'update event' with the store's updated properties dispatcher executes handler of the subscribed component, and updates component state with the store's updated properties What am I missing here that I can't do without Flux? I think what others have said about application structure and the change event is important, but I should add this one thing: The

How to redirect after success from ajax call using React-router-component?

只愿长相守 提交于 2019-12-03 12:23:49
I am building a application using Facebook flux architecture of React JS . I have build the basic part of app where I have a login form. I am fetching the the result from node server to validate user at the store, I am getting the result from server, Now I got stuck that how can I redirect the user to home page after success. I have read about the react router component and I am able to redirect at the client side but not able to redirect at the time of fetching result from ajax in Store. Please help me. kulesa You need to use the transitionTo function from the Navigation mixin: http://git.io

Error Handler with Flux

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 08:53:57
问题 I have a React.js application that I am refactoring to use the Flux architecture, and am struggling to figure out how error handling should work while sticking to the Flux pattern. Currently when errors are encountered, a jQuery event 'AppError' is triggered and a generic Error Handling helper that subscribes to this event puts a Flash message on the user's screen, logs to the console, and reports it via an API call. What is nice is I can trigger an error for any reason from any part of the

Flux/React Complex Reusable Component

怎甘沉沦 提交于 2019-12-03 07:26:41
问题 I want to do something like this var App = React.createClass({ render: function() { return ( <CountryAutoComplete /> ) } }); Different app var App2 = React.createClass({ render: function() { return ( <CountryAutoComplete /> ) } }); Here is a simple Autocomplete (Not the entire file) var AutoComplete = React.createClass({ componentDidMount: function() { $(this.getDOMNode()).typeahead(this.props); }, render: function() { return ( <input type="text" class="typeahead" onChange={this.props

Is triggering an action in the store bad practice?

落爺英雄遲暮 提交于 2019-12-03 07:24:22
Stores are supposed to handle the events triggered by actions and emit the change to the listening view controllers. Is it ok for them to trigger actions as well, for example in the callback of a request or directly in the store's registered callback. For example: AppDispatcher.register(function(payload) { switch(payload.action.actionType) { case Constants.PAGE_CHANGED: ActionCreator.fetchNewData(); break; case Constants.FETCH_DATA: // save data Store.emitChange(); break; } }); Is code like this "correct" in the Flux architecture ? Thank you ! ====== UPDATE BASED ON COMMENTS: This is not a

React/Flux way to handle permission sensitive actions with login flows

佐手、 提交于 2019-12-03 06:36:38
I have been playing with React/Flux, and I am having trouble wrapping my head around the 'Flux Way' for handling permission-sensitive actions. Overarching question: When a non-logged in visitor attempts an action that requires he/she to be logged in, what is the Flux way of (a) checking if a user is logged in, (b) starting the login flow, (c) finishing the action on success? Take an example of a forum app, that requires users to be logged in to post: We have a comment form component (mostly taken from FB's React tut) as such: var CommentForm = React.createClass({ handleSubmit: function ( e ) {

Is it OK to call setState from within shouldComponentUpdate?

强颜欢笑 提交于 2019-12-03 05:53:46
In response to a state change, I want to trigger another state change. Is that inherently a bad idea? The specific sort of scenario is that the component is modeled as a state machine that renders different information according to the value of this.state.current_state . But external events can prompt it to experience a state transition, via changes to it's state through a flux store. Here's a contrived scenario to get the idea across: I think the correct lifecycle method to do this would be shouldComponentUpdate . Something to this effect: shouldComponentUpdate: function(nextProps, nextState)

Avoiding event chains with asynchronous data dependencies

不羁岁月 提交于 2019-12-03 05:36:28
The Facebook Flux dispatcher explicitly prohibits ActionCreators from dispatching other ActionCreators . This restriciton is probably a good idea since it prevents your application from creating event chains. This however becomes an issue as soon as you have Stores containing data from asynchronous ActionCreators that depend on each other. If CategoryProductsStore depends on CategoryStore there doesn't seem to be a way to avoid event chains when without resorting to deferring the follow-up action. Scenario 1: A store containing a list of products in a category needs to know from which category

Flux: How to make an action wait for a store?

有些话、适合烂在心里 提交于 2019-12-03 03:46:40
I'm tying myself in knots with a React problem which I'm sure can't be as difficult as it seems to me right now. I'm building a single page app against a RESTful server API that returns resources, together with links that describe what can be done with that resource. And I'm trying to ensure that my client's ajax calls only use URLs retrieved from the server in this way. So, for example, my LoggedInSessionStore contains the URL that allows me to fetch the list of all public documents, say. The problem I have is how to manage the dependencies between actions and stores. For example, when the

Redux state persistence with a database

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 02:48:35
问题 From the discussion here it seems that the state of Redux reducers should be persisted in a database. How does something like user authentication works in this instance? Wouldn't a new state object be created to replace the previous state in the database for every user (and their application state) created and edited? Would using all of this data on the front end and constantly updating the state in the database be performant? Edit: I've created an example Redux auth project that also happens