reactjs-flux

Strategies for server-side rendering of asynchronously initialized React.js components

╄→尐↘猪︶ㄣ 提交于 2019-11-28 15:00:41
One of the biggest advantages of React.js is supposed to be server-side rendering . The problem is that the key function React.renderComponentToString() is synchronous which makes it impossible to load any asynchronous data as the component hierarchy is rendered on the server. Let's say I have a universal component for commenting which I can drop pretty much anywhere on the page. It has only one property, some kind of identifier (for example id of an article below which the comments are placed), and everything else is handled by the component itself (loading, adding, managing comments). I

In Flux architecture, how do you manage Store lifecycle?

廉价感情. 提交于 2019-11-28 14:56:23
I'm reading about Flux but the example Todo app is too simplistic for me to understand some key points. Imagine a single-page app like Facebook that has user profile pages . On each user profile page, we want to show some user info and their last posts, with infinite scroll. We can navigate from one user profile to another one. In Flux architecture, how would this correspond to Stores and Dispatchers? Would we use one PostStore per user, or would we have some kind of a global store? What about dispatchers, would we create a new Dispatcher for each “user page”, or would we use a singleton?

Having services in React application

浪尽此生 提交于 2019-11-28 13:51:59
问题 I'm coming from the angular world where I could extract logic to a service/factory and consume them in my controllers. I'm trying to understand how can I achieve the same in a React application. Let's say that I have a component that validates user's password input (it's strength). It's logic is pretty complex hence I don't want to write it in the component it self. Where should I write this logic? In a store if I'm using flux? Or is there a better option? 回答1: The first answer doesn't

What could be the downsides of using Redux instead of Flux [closed]

心已入冬 提交于 2019-11-28 13:09:57
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 7 months ago . I just recently discovered Redux. It all looks good. Are there any downsides, gotcha or compromises of using Redux over Flux? Thanks 回答1: Redux author here! I'd like to say you're going to make the following compromises using it: You'll need to learn to avoid mutations. Flux

Flux: waitFor specific event

早过忘川 提交于 2019-11-28 12:49:01
I'm trying to understand how to resolve dependencies among stores. The problem is I have a comprehensive data tree, which need to be fetched from server with the chain of request that depends one on another. PROBLEM: waitFor seams not to be supposed for async requests. Suppose next event chain: NEED_A (look at StoreA ) NEED_B (look at StoreB ) Here StoreB do AppDispatcher.waitFor([StoreA.dispatchToken]) . But actually we want to wait for GET_A SOME_OTHER_ACTION (look at StoreA ) The third step breaks waitFor from the second step since StoreA.dispatchToken was called for SOME_OTHER_ACTION .

Test a React Component function with Jest

╄→гoц情女王★ 提交于 2019-11-28 03:57:48
Original First of all, I am following the Flux architecture. I have an indicator that shows a number of seconds, ex: 30 seconds. Every one second it shows 1 second less, so 29, 28, 27 till 0. When arrives to 0, I clear the interval so it stops repeating. Moreover, I trigger an action. When this action gets dispatched, my store notifies me. So when this happens, I reset the interval to 30s and so on. Component looks like: var Indicator = React.createClass({ mixins: [SetIntervalMixin], getInitialState: function(){ return{ elapsed: this.props.rate }; }, getDefaultProps: function() { return { rate

Having services in React application

 ̄綄美尐妖づ 提交于 2019-11-28 02:54:35
I'm coming from the angular world where I could extract logic to a service/factory and consume them in my controllers. I'm trying to understand how can I achieve the same in a React application. Let's say that I have a component that validates user's password input (it's strength). It's logic is pretty complex hence I don't want to write it in the component it self. Where should I write this logic? In a store if I'm using flux? Or is there a better option? The first answer doesn't reflect the current Container vs Presenter paradigm. If you need to do something, like validate a password, you'd

How does react-router pass params to other components via props?

痞子三分冷 提交于 2019-11-27 11:09:14
问题 Thus far, the extent of my knowledge about how properties are passed from one component to another via parameters is as follows //start: extent of my knowledge Suppose there exists some state variable called topic in A.jsx. I want to pass this down to B.jsx, so I perform the following B = require('./B.jsx') getInitialState: function() {return {topic: "Weather"}} <B params = {this.state.topic}> In B.jsx I can then do stuff like module.exports = React.createClass({ render: function() { return

At what nesting level should components read entities from Stores in Flux?

淺唱寂寞╮ 提交于 2019-11-27 10:06:39
I'm rewriting my app to use Flux and I have an issue with retrieving data from Stores. I have a lot of components, and they nest a lot. Some of them are large ( Article ), some are small and simple ( UserAvatar , UserLink ). I've been struggling with where in component hierarchy I should read data from Stores. I tried two extreme approaches, neither of which I quite liked: All entity components read their own data Each component that needs some data from Store receives just entity ID and retrieves entity on its own. For example, Article is passed articleId , UserAvatar and UserLink are passed

In Flux architecture, how do you manage Store lifecycle?

这一生的挚爱 提交于 2019-11-27 08:56:11
问题 I'm reading about Flux but the example Todo app is too simplistic for me to understand some key points. Imagine a single-page app like Facebook that has user profile pages . On each user profile page, we want to show some user info and their last posts, with infinite scroll. We can navigate from one user profile to another one. In Flux architecture, how would this correspond to Stores and Dispatchers? Would we use one PostStore per user, or would we have some kind of a global store? What