diff --git a/high-performance-react.org b/high-performance-react.org index 5e1ac60..7d5382d 100644 --- a/high-performance-react.org +++ b/high-performance-react.org @@ -1,3 +1,16 @@ +#+BEGIN_SRC emacs-lisp :exports results :results silent + (require 'ox-latex) + (add-to-list 'org-latex-packages-alist '("" "minted")) + (setq org-latex-listings 'minted) + (setq org-latex-pdf-process + '("xelatex -shell-escape -interaction nonstopmode -output-directory %o %f")) +#+END_SRC + +# #+latex_class: article +# #+latex_class_options: [a4paper,8pt] +# #+latex_header: \usepackage[a4paper,top=2.5cm,bottom=2.5cm,left=1.5cm,right=1.5cm]{geometry} +# #+latex_header:\renewcommand{\baselinestretch}{1.2} + #+TITLE: High-Performance React #+AUTHOR: Thomas Hintz @@ -87,7 +100,7 @@ Before baking is finished bread is a living organism. The way it grows and develops and flavors depend on what you feed it and how you feed it and massage it, care for it. If you have it grow and ferment at a higher temperature and more yeast it overdevelops producing too much -alcohol. If you give it too much time acidity will take over the +alcohol. If you give it too much time, acidity will take over the flavor. The recipes I used initially were missing a critical ingredient: the rising temperature. @@ -101,13 +114,14 @@ the other ingredients to complement the temperature. Now the bread can tell me what to do. While React isn't technically a living organism that can tell us what -to do it is, in its whole, a complex, abstract entity. We could learn basic -recipes for how to write high-performance React code but they wouldn't -apply in all cases and as React and things under it change our recipes -would fall out-of-date. So like the bread, to produce consistently -good results we need to understand how React does what it does. +to do, it is, in its whole, a complex, abstract entity. We could learn +basic recipes for how to write high-performance React code but they +wouldn't apply in all cases, and as React and things under it change +our recipes would fall out-of-date. So like the bread, to produce +consistently good results we need to understand how React does what it +does. -** React, made of +** Components of React Conceptually React is very simple. It starts by walking a tree of components and building up a tree of their output. Then it compares @@ -128,41 +142,43 @@ questions with solid answers. React is centered around the ~render~ method. The ~render~ method is what walks our trees, diffs them with the browser's DOM tree, and updates the DOM as needed. But before we can look at the ~render~ -method me have to understand its input. The input comes from +method we have to understand its input. The input comes from ~createElement~. While ~createElement~ itself is unlikely to be a -bottleneck it's a good to understand how it works so that we can have -a complete picture of the entire process. The more black-boxes we have +bottleneck it's good to understand how it works so that we can have a +complete picture of the entire process. The more black-boxes we have in our mental model the harder it will be for us to diagnose performance problems. -** Markup in Javascript: ~JSX~ +** Markup in JavaScript: ~JSX~ ~createElement~, however, takes as input something that is probably not familiar to us since we usually work in JSX, which is the last element of the chain in this puzzle and the first step in solving -it. While not strictly a part of React it is almost universally used +it. While not strictly a part of React, it is almost universally used with it. And if we understand it then ~createElement~ will be less of a mystery since we will be able to connect all the dots. -JSX is not valid HTML or Javascript but its own language compiled by a +JSX is not valid HTML or JavaScript but its own language compiled by a compiler, like Babel. The output of that compilation is valid -Javascript that represents the original markup. +JavaScript that represents the original markup. -Before JSX the normal way of injecting HTML into the DOM was via -directly utilizing the browser's DOM APIs. This was very cumbersome. -The code's structure did not match the structure of the HTML that it -output which made it hard to quickly understand what the output of -a piece of code would be. So naturally programmers have been endlessly -searching for better ways to mix HTML with Javascript. +Before JSX or similar compilers, the normal way of injecting HTML into +the DOM was via directly utilizing the browser's DOM APIs or by +setting ~innerHTML~. This was very cumbersome. The code's structure +did not match the structure of the HTML that it output which made it +hard to quickly understand what the output of a piece of code would +be. So naturally programmers have been endlessly searching for better +ways to mix HTML with JavaScript. And this brings us to JSX. It is nothing new; nothing complicated. Forms of it have been made and used long before React adopted it. Now let's see if we can discover JSX for ourselves. -To start with we need to create a data structure that both represents -a DOM tree and can also be used to insert one into the browser's -DOM. And to do that we need to understand what a tree of DOM nodes is -constructed of. What parts do you see here? +To start with, we need to create a data-structure -- let's call it +JavaScript Markup (JSM) -- that both represents a DOM tree and can +also be used to insert one into the browser's DOM. And to do that we +need to understand what a tree of DOM nodes is constructed of. What +parts do you see here? #+BEGIN_SRC html