Skip to main content

ReactJS - Virtual DOM


So . . . How About React?

If we’re going to start talking about how it functions, I think we should start by talking about what it works with. Many are already used to the HTML commonly associated with static website design. In it’s more basic, it can look something like this, though <h1>Hello World</h1> by itself in the file would yield the same output; this is trying to imitate a larger-scale structure. With this basic structure, combined with CSS-aided styling, we can have all the static content we want (and a bit can even be hidden/reformatted on hover or focus, to boot). From this point, we need JavaScript . . . sort of.


How is JS usually

So, back to JavaScript. As mentioned before, the language is one of the three core technologies of the world wide web. Used commonly on the client side, you can manipulate the content of the HTML code, the DOM, to do just about anything. For some great interactive examples, check out the W3School’s JavaScript HTML DOM Events page [6]. This is great, but in the process of this, the browser must reload the DOM every time JavaScript edits it. In the context of a small application, this, of course, is generally insignificant. However, in larger modern websites, inefficient usage of this can stack up and cause major performance issues as complexity increases. In the example, let’s just say that we used JavaScript to change the h1 element in the DOM. That means that everything in the DOM gets updated. Not much in the example, I know, but imagine is the file had hundreds of intricate elements running both inside of it and alongside it [5, 7]. Would you want to reload all of them?


What does React do?

ReactJS uses the technique of Virtual DOMs to address this. The library creates a JavaScript object to mimic the real DOM, but a lightweight version with less complexity, known as a Virtual DOM. When changes occur during runtime, React makes a snapshot of the virtual DOM just prior to alteration and then applies said change to the original virtual DOM. It then uses a diffing algorithm to spot the difference between the snapshot and normal virtual DOM and isolate the changes, finding the dirty objects. With the changes found, React’s functions change the altered objects and only the altered objects to reflect the change on the real DOM, therefore being outputted on the screen [1, 3, 5, 7, etc.].

Courtesy of Learning React Native [8]

Why is this significant?

So, why does this matter, anyways? In computer science, efficiency is an important facet of design. It allows for complex computations to take less time, power, and resources, which thereby speeds up the process and allows for more computational features to be implemented and ran alongside this. Without progress in this regard, computing machines would not be able to advance in complexity at nearly the rate that they have been, and many systems would slow down at an increasing rates as more is added to them. With efficiency, speed is improved and additional insight and data can be derived or the user experience can be enhanced.


Bibliography

Of note, this includes both content that I have used and that which I intend to use for future posts

Comments

Post a Comment

Popular posts from this blog

ReactJS - What is it?

So . . . How About React? What happens when an impressive Facebook engineer gets assigned to port XHP - a PHP version primarily relied upon for data validation and scrubbing to combat XSS - to JavaScript and maybe gets a bit carried away with it [5] ? React! ReactJS (also known as React.js or simply React) is a library of Javascript, a programming language pivotal in the rendering of webpage elements alongside HTML and CSS . While some libraries generally try to incorporate and adapt ‘the wheel’ to make some specialized processes easier, React joins the ranks of the increasingly many that set out to completely reinvent it in many parts. Image courtesy of xpagexplorer.org [15] Basically, what is it? Basically speaking, Javascript is a programming language that can be used to alter the content of the website’s layout. ReactJS, like any library, utilizes its base language to ease and optimize complex sets of operations. Its features rework many elements consid...

ReactJS - Reactive Programming

What Is Reactive Programming? Reactive programming is a commonly-implemented practice in React implementations, but what does that actually mean? Well, Wikipedia's got our backs with the most basic of definitions: "In computing, reactive programming is an asynchronous programming paradigm concerned with data streams and the propagation of change." Who did what now? Yeah, it seems complicated, but not only is it necessary but, with the veil of jargon explained, it's actually pretty basic. Courtesy of innoq.com [10] Reactive Programming Fundamentals Complexities aside, you can think of reactive programming as programming with changing information. In basic Java programming, for example, int c = a + b; assigns c that sum of the two variables at the time of assignment , not a binding obligation to continuously reflect the sum of a and b as they change. With reactive programming, when a variable's value changes, values associated with said value als...

ReactJS - Immutability

Value vs. Reference Equality The mutation of data in computer science is something everybody who has studied a common programming language has done at some point. You create a variable and they you change it ! Magic! All of a sudden, you have a variable that is completely different, with a different value and everything! Well, actually, there's something that probably didn't change; the location of the data in memory. The variable is still pointing to the same place it always did; a little section it found specifically for the variable. The contents of the section had changed, but the reference - a sort of ID, if you would - is still the same. This is called mutating the value, and can therefore be seen as mutability. ReactJS's Spin ReactJS has an interesting method of making rendering more efficient, and it involves the way you alter data. Instead of changing the values of a set object every time you need it to change (mutating it), you can actually adopt a st...