flux

ReactJS findDOMNode and getDOMNode are not functions

余生颓废 提交于 2019-11-29 02:05:53
问题 I'm building a web-app with ReactJS and Flux and I'm trying to get the node of my current div using the method findDOMNode and I get the next error: Uncaught TypeError: React.findDOMNode is not a function So, I tried to use getDOMNode and I get the very same error: Uncaught TypeError: React.getDOMNode is not a function I'm using npm to build the JS, the code where I use these methods: var React = require('react'); var stores = require('../stores'); var MessagesUserContainer = require('.

how to cancel/abort ajax request in axios

北战南征 提交于 2019-11-29 01:55:46
问题 I use axios for ajax requests and reactJS + flux for render UI. In my app there is third side timeline (reactJS component). Timeline can be managed by mouse's scroll. App sends ajax request for the actual data after any scroll event. Problem that processing of request at server can be more slow than next scroll event. In this case app can have several (2-3 usually) requests that already is deprecated because user scrolls further. it is a problem because every time at receiving of new data

How to fire periodic actions using setTimeout and dispatcher in redux

柔情痞子 提交于 2019-11-29 01:25:57
How/Where can I dispatch actions periodically? Using recursive setTimeout to make a countdown. Taken from the example, something similar to this: // Can also be async if you return a function export function incrementAsync() { return dispatch => { (function _r() { setTimeout(() => { // Yay! Can invoke sync or async actions with `dispatch` dispatch(increment()); _r(); }, 1000); })(); }; } So is this a good idea, or there is a better approach to this problem, like using middlewares or creating actions from somewhere else? I prefer a generic version of this, where I can control start/stop of the

MVC vs. Flux ? Bidirectional vs. Unidirectional?

倖福魔咒の 提交于 2019-11-28 16:41:21
Looking at the following diagram (which explains MVC), I see unidirectional data flow. So why do we consider MVC to have bidirectional data flow while justifying Flux ? Because in Javascript frameworks the MVC does not work the way you depicted. The UI generally communicates bi-directionally with the model, as in: User types into View input MVC framework binds onchange() to update a model. Ajax request brings in new model data. MVC framework updates View input's value to match model. In Flux architecture, the UI would only fire an independent action with type and associated data to a

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

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 .

How to put methods onto the objects in Redux state?

有些话、适合烂在心里 提交于 2019-11-27 18:57:12
According to docs state of react app has to be something serializable. What about classes then? Let's say I have a ToDo app. Each of Todo items has properties like name , date etc. so far so good. Now I want to have methods on objects which are non serializable. I.e. Todo.rename() which would rename todo and do a lot of other stuff. As far as I understand I can have function declared somewhere and do rename(Todo) or perhaps pass that function via props this.props.rename(Todo) to the component. I have 2 problems with declaring .rename() somewhere: 1) Where? In reducer? It would be hard to find

How do I handle nested API responses in a Flux application?

烂漫一生 提交于 2019-11-27 16:40:48
问题 I'm porting an existing app to Flux and I'm a bit confused about one topic. Say I have several API endpoints that return two- or three-level nested objects. For example, GET /articles may return a JSON response of schema articles: article* article: { author: user, likers: user* primary_collection: collection? collections: collection* } collection: { curator: user } As you see, there are all kinds of users at different levels of nesting: articles[i].author articles[i].likers[i] articles[i]

Spring WebClient vs. RestTemplate

强颜欢笑 提交于 2019-11-27 16:37:21
1. 简介 本教程中,我们将对比 Spring 的两种 Web 客户端实现 —— RestTemplate 和 Spring 5 中全新的 Reactive 替代方案 WebClient 。 2. 阻塞式 vs 非阻塞式客户端 Web 应用中,对其他服务进行 HTTP 调用是一个很常见的需求。因此,我们需要一个 Web 客户端工具。 2.1. RestTemplate 阻塞式客户端 很长一段时间以来,Spring 一直提供 RestTemplate 作为 Web 客户端抽象。在底层, RestTemplate 使用了基于每个请求对应一个线程模型(thread-per-request)的 Java Servlet API。 这意味着,直到 Web 客户端收到响应之前,线程都将一直被阻塞下去。而阻塞代码带来的问题则是,每个线程都消耗了一定的内存和 CPU 周期。 让我们考虑下有很多传入请求,它们正在等待产生结果所需的一些慢服务。 等待结果的请求迟早都会堆积起来。**因此,程序将创建很多线程,这些线程将耗尽线程池或占用所有可用内存。**由于频繁的 CPU 上下文(线程)切换,我们还会遇到性能下降的问题。 2.2. WebClient 非阻塞式客户端 另一方面, WebClient 使用 Spring Reactive Framework 所提供的异步非阻塞解决方案。 当