Book Image

Mastering Immutable.js

By : Adam Boduch
Book Image

Mastering Immutable.js

By: Adam Boduch

Overview of this book

Immutable.js is a JavaScript library that will improve the robustness and dependability of your larger JavaScript projects. All aspects of the Immutable.js framework are covered in this book, and common JavaScript situations are examined in a hands-on way so that you gain practical experience using Immutable.js that you can apply across your own JavaScript projects. The key to building robust JavaScript applications using immutability is to control how data flows through your application, and how the side-effects of these flows are managed. Many problems that are difficult to pinpoint in large codebases stem from data that’s been mutated where it shouldn’t have been. With immutable data, you rule out an entire class of bugs. Mastering Immutable.js takes a practical, hands-on approach throughout, and shows you the ins and outs of the Immutable.js framework so that you can confidently build successful and dependable JavaScript projects.
Table of Contents (23 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Summary


In this chapter, you learned about the basics of sorting collections in Immutable.js. The basic sort() and reverse() methods sort values using a default comparator function. You can supply your own comparator functions for more complex scenarios. There's also the sortBy() method that accepts an iteratee function, which is used to return values that are passed to the comparator.

We then addressed the issue of sorting maps. Because they're a keyed collection, they have no inherent mechanism to keep track of the order of values. Lists, on the other hand, have this value built into them. Ordered maps are used to preserve the ordering of maps. You can also sort maps by keys if you use sortBy() to return the key.

We looked at the problem of maintaining the sort order of collections. Having to sort collections every time they change can be inefficient. To address this, you can leverage the sort index approach. On the other hand, this can be difficult to maintain and sort() is good enough...