Web applications move to another level | combing1のブログ

combing1のブログ

ブログの説明を入力します。

React is Air Max 2012 Black Navy Blue White to build a user interface library developed by Facebook. It will be designed from the start as a key performance. This article will show how diff algorithms and rendering process to work, you can learn to optimize their own applications. Before delving Diff algorithm implementation details React need to know about how it works. var MyComponent = React.createClass ({render: function () {if (this.props.first) {return \u0026 lt; div className = \u0026 quot; first \u0026 quot; \u0026 gt; \u0026 lt; span \u0026 gt; A Span \u0026 579756 403 Purple White Nike Black Mamba 24 Kobe Sale lt; / span \u0026 gt; \u0026 lt; / div \u0026 gt; ;} else {return \u0026 lt; div className = \u0026 quot; second \u0026 quot; \u0026 gt; \u0026 lt; p \u0026 gt; A Paragraph \u0026 lt; / p \u0026 gt; \u0026 lt; / div \u0026 gt ;;}}}); any time, you describe your UI looks what it was like. Need special attention, not really render the results of the implementation of DOM nodes obtained. The result is just a lightweight JavaScript objects, which we call virtual DOM. React from this form of expression which tries to find a previous rendering results after a minimum number of steps. For example, when we mounted the \u0026 lt; MyComponent first = {true} / \u0026 gt ;, then \u0026 lt; replace, then unmounted, DOM commands such a process is this; MyComponent first = {false} / \u0026 gt : From No to the first step in creating a node:? \u0026 lt; div className = \u0026 quot; first \u0026 quot; \u0026 gt; \u0026 lt; span \u0026 gt; A Span \u0026 lt; / span \u0026 gt; \u0026 lt; / div \u0026 gt; the first step to the second step to replace an attribute: className = ' first 'to className =' second 'Tihe node: \u0026 lt; span \u0026 gt; A Span \u0026 lt; / span \u0026 gt ;? to \u0026 lt; p \u0026 gt; A Paragraph \u0026 lt; / p \u0026 gt; the second step to not delete a node:?? \u0026 lt; div className = \u0026 quot ; second \u0026 quot; \u0026 gt; \u0026 lt; p \u0026 gt; A Paragraph \u0026 lt; / p \u0026 gt; \u0026 lt; / div \u0026 gt; minimal modifications between trees in a hierarchical find two courses in any of a complexity problem O (n ^ 3) a. As you can imagine, our case this is not easy to handle. React with a simple but powerful technique, reaching nearly O (n) complexity. React just try to put the tree in a hierarchical decomposition. This drastically simplifies the complexity, but also will not lose a lot, because there are few Web applications move to another level component to the tree. Most of them only move between adjacent child nodes. List Suppose we have a component, a loop rendered five component, in the middle of the list followed by the insertion of a new component. Only know this information, you want to find out a list of how two component corresponds hard. By default, before React first component will be a list and after a first associate, later also. You can write a key attribute to help React to handle correspondence between them. Century bell, only to find the key element in the New Nike Free Run 3 Shoes Silver 3 child is usually very easy. ComponentsReact app is usually a combination of a user-defined component together, the result is usually a major component of many div tree. This information is also taken into account React diff algorithm, 597806-400 Nike LeBron X EXT QS Denim-Pink Outlet New Nike Free 5.0 V4 Grey Blue Running Shoes React only match the same Nike Heels Boots class of the component. For example, if you have a \u0026 lt; Header \u0026 gt; is \u0026 lt; ExampleBlock \u0026 gt; replace lost, React will be deleted and then create a header example block. We do not need to match the precious time of two unlikely and similarities component. Acting on a DOM node event tied to popular events broken ah slow, and very cost memory. As an alternative, React deployed a popular technique called 'event Air Jordan Outlet broker.' React to go further, to re-implement it again W3C-compliant event system. Event processing means IE8 bug thing of the past, all Nike Air Max the time the name of the cross-browser consistent. Here to explain how to achieve. Event listener is bound to the root node of the entire document. When the event is triggered, the browser will give a departure target DOM node. In order to spread events in the DOM hierarchy, React not iteration of virtual DOM hierarchy. Instead, we rely on each separate id React component to encode this level. We pass a simple string manipulation to get the parent of the contents of all of the parent component. The event listener which is stored in the hash map, we found that the performance is even better than put virtual DOM. This example shows what happens when an event broadcast to the entire virtual DOM. // DispatchEvent ('click', 'abc', event) clickCaptureListeners ['a'] (event); clickCaptureListeners ['a.b'] (event); clickCaptureListeners ['abc'] (event); clickBubbleListeners [ 'abc'] (event); clickBubbleListeners ['a.b'] (event); clickBubbleListeners ['a'] (event); browser to create a new event object for each event and each listener. Air Max 2011 Womens Purple Grey The properties of the event object is very good, you can get a reference to the event, and even modify the swap. However, this also means high memory allocation. React at startup for those objects assigned a memory pool. Any time you need to use an event object, you can reuse this memory pool. This is very significantly reduce the garbage burden. Rendering Nike Jordan Melo B Mo the bulk of your call when component of setState method, React to mark it as dirty. To the end of each event loop, React check all mark the component dirty redrawn. Here the 'mass' is that, in an event loop which, DOM will only be updated once. This feature is critical to build an efficient app, and use JavaScript code generally difficult to achieve. In React application, you default realized. When Mens Nike Free Run 3 Shoes Black 3 the sub-tree rendering method call setState, component rebuild includes virtual DOM child nodes. 2015 Nike Free 5.0 If you are in the Air Jordan Heel root call setState, React entire application will be re-rendered. All the component, even if there is no update, they will call the render method. That sounds terrible, like a low performance, but in fact we will not touch the real DOM, Nike Free Run 3 running no problem. First of all, we are talking about is to show the user interface. Because of the limited screen space, usually you need a render success of thousands of instructions. JavaScript can handle the entire interface, business logic on fast enough. Another point, when writing React code, whenever and data updates, you do not have to call the root of setState. You will receive the corresponding update on the need to call the component, or in the above several component. You rarely have to be on the root. That update only appear in the user produce local interaction. Select temper tree rendering Finally, you may also re-rendered cut off some of the sub-tree. If you implement the following methods in the component words: boolean shouldComponentUpdate (object nextProps, object nextState) according to the previous and next props / state component, Nike Free Run 3 Women you can tell React this component is not updated, do not need to be redrawn. Realize well, it can bring significant performance gains. To use this method, you have to be able to JavaScript Object for comparison. There are many details of this factor, such as contrast should be shallow or deep, if you want deep, we are using immutable data structures, or in-depth copy. And you have to pay attention, really a function is called every time, so you want to make sure that running event spend less than React skills, as well as rendering component than the time required to redraw even if not essential. CONCLUSION help React faster technology is not new. For a long time, we have to know that touching DOM is time-consuming, you should merge processing read and write operations, the event broker will be faster. People still often discuss them, because in practice it is realized using JavaScript were quite hard. React to highlight one of the reasons is that these optimizing default started. This allows you to avoid accidentally app written off slowly. React consumption performance model is very simple, well understood: setState will recalculate the entire sub-tree of each call. If you want to improve performance, minimize call setState, as well as with shouldComponentUpdate reduce recalculated large subtree.React of diff algorithms