So, in the spirit of keeping the party going, here we are throwing another one at you: Immutable.js, another member of the growing family of JavaScript frameworks.
To understand why Immutable.js is necessary, and when, you first need to know the concepts of mutability and immutability in programming.
Caution: Somewhat esoteric developer-speak follows. If the contents make you dizzy, confused, or sleepy, discontinue reading and contact AndPlus at once to discuss how we can help you with your next JavaScript-based web application. We’ll take care of the immutability part.
In computer programming, all objects can be classified as mutable or immutable. An immutable object cannot have its value or state changed (or “mutated”) once it is created, whereas a mutable object can have its value, properties, or state changed as the program runs.
Many traditional programming languages have the notion of a constant, a named value that cannot be changed after it is first created. Immutability—not just for individual values, but for more complex data structures such as arrays and objects with multiple properties—is important for a few reasons:
JavaScript does not provide any way of enforcing immutability on objects in the document object model (DOM). There are certain techniques that developers can use to impose a sort of “immutability” on objects, but this approach has some limitations:
For these reasons, the Immutable.js framework was created. The Immutable.js framework provides a library that enables developers to encapsulate data objects in a way that guarantees their immutability. Essentially, Immutable.js uses the same techniques that a developer would use to impose immutability, but ensures it is done consistently for a given object.
The Immutable.js framework has the advantages you would expect, such as guaranteeing immutability and therefore enhancing the performance of your application. There are, however, some disadvantages that developers need to be aware of and address with careful coding:
These issues can be overcome, but developers need to be well-versed in Immutable.js and how to program around its limitations—without writing a lot of extra code.
Immutable.js can be a great way to enforce immutability on JavaScript objects and therefore optimize an application’s performance. It does require discipline and know-how to use properly. The JaveScript developers at AndPlus are intimately familiar with Immutable.js and how to apply it appropriately (and when not to apply it at all). If you made it this far through this article, contact AndPlus today to discuss how we can optimize your JavaScript web application.