Mastering Immutable.js

Book description

This book shows JavaScript developers how to build highly dependable JavaScript projects using the Immutable.js framework.

About This Book

  • Master the Immutable.js JavaScript framework
  • Build predictable and dependable applications using immutability
  • Control how data flows through your application
  • Control the effects of data flow in your user interface using Node.js

Who This Book Is For

This book is for JavaScript developers, from intermediate level and beyond, who need to create dependable JavaScript projects, using the Immutable.js JavaScript framework.

What You Will Learn

  • Learn how Immutable.js can improve the dependability of your JavaScript code
  • Discover how to create Immutable data, and work with persistent changes
  • See how to combine and filter collections, and find items
  • Learn how to work with sequences and side effects
  • Sort collections, maps, and sets
  • Get to know tricks to avoid processing chains
  • Compare and move between lists, sets, and maps
  • Work with Immutable patterns and Immutable architecture

In Detail

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.

Style and Approach

Adam Boduch covers all the key concepts and benefits of immutability, and then presents you with hands-on practical experience on implementing immutability in your JavaScript projects.

Publisher resources

Download Example Code

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Why Immutable.js?
    1. Mutations are destructive
      1. Deleting old data
      2. A scary class of bugs
      3. Persisting changes
    2. The Immutable.js approach
      1. A collections API
      2. Collection methods return new data
      3. Chaining method calls
    3. Unidirectional data flow
      1. What other direction is there?
      2. Subscriptions are out
      3. Data is only created
      4. Implicit side-effects are hard to do
    4. Other libraries similar to Immutable.js
      1. What are we comparing?
      2. Lodash is a good bet
    5. Summary
  3. Creating Immutable Data
    1. Immutable.js constructors
      1. The types of Immutable.js data
        1. Lists
        2. Maps
        3. Ordered maps
        4. Sets
        5. Ordered sets
        6. Sequences
        7. Stacks
        8. Records
      2. Passing JavaScript collections
      3. Passing Immutable.js collections
    2. Using the of() method
      1. Lists of values
      2. Maps of values
      3. Sets of values
      4. Sequences of values
    3. Parsing data using the fromJS() function
      1. Parsing JavaScript arrays
      2. Parsing JavaScript objects
      3. Parsing complex structures
    4. Summary
  4. Persistent Changes
    1. Adding values to collections
      1. Pushing values to lists
      2. Adding key-value pairs to maps
      3. Chaining value insertion methods
        1. Pushing multiple list values
        2. Adding multiple map key-value pairs
    2. Changing collection values
      1. Changing list values
        1. Setting list values
        2. Updating list values
      2. Changing map values
        1. Setting map values
        2. Updating map values
      3. Chaining collection mutation methods
    3. Removing values from collections
      1. Removing values from lists
      2. Removing values from maps
      3. Chaining collection removal methods
    4. Emptying collections
      1. Replacing collections with new instances
      2. Using the clear() method
    5. Keeping track of changes
    6. Summary
  5. Filtering Collections and Finding Items
    1. Filtering using simple comparisons
      1. Strict equality
      2. Greater than and less than
      3. Filtering by negation
    2. Filtering maps by keys
      1. Filtering string keys
      2. Filtering fancy keys
    3. Finding collection values
      1. Value existence checks
      2. Getting values using find()
    4. Filtering using deep equality
      1. Using the is() function and the equals() method
      2. Searching lists of maps
    5. Partial matches
      1. The shape of maps
      2. Subsets and supersets
    6. Changing the search direction
      1. Searching sorted collections
      2. Using findLast() and reduceRight()
    7. Summary
  6. Sequences and Side-Effects
    1. Why lazy evaluation?
      1. Large collections are expensive
      2. Avoiding unnecessary work
      3. Chained operations are easy to understand
    2. Sequence creation and iteration
      1. Basic sequence creation
      2. Collections to sequences
        1. Lists to sequences
        2. Maps to sequences
      3. Iterating with for...of loops
      4. Iterating with forEach()
    3. Lazy filtering
      1. Basic lazy filtering
      2. Multiple filter levels
    4. Limiting results and reducing work
      1. Using take() to limit results
      2. Using slice() to paginate
    5. Summary
  7. Sorting Collections
    1. Sorting and reversing
      1. The sort() method
      2. The reverse() method
    2. Sorting lists of maps
      1. The sortBy() method
      2. Sorting by multiple keys
    3. Ordered maps
      1. Order guarantees
      2. Insertion order is not sort order
      3. Setting the order with set()
    4. Sorting maps
      1. Creating ordered maps
      2. Sorting maps by key
    5. Maintaining sort order
      1. Finding the insertion index
      2. Is this really necessary?
    6. Summary
  8. Mapping and Reducing
    1. Mapping lists of maps
      1. Plucking values
      2. Computing new values
    2. Mapping to new lists of maps
      1. Creating new keys
      2. Filtering keys
    3. Reducing collections
      1. When filtering isn't enough
      2. Producing minimums and maximums
      3. Accumulating values
    4. Lazy mapping
      1. Multiple map() calls
      2. Filtering before mapping
      3. The ultimate lazy pattern
    5. Summary
  9. Zipping and Flattening
    1. Zipping collections
      1. Removing excess iterations
      2. Zipping lists of simple values
      3. Zipping lists of maps
      4. Lazy zipping
    2. Flattening collections
      1. Avoiding recursion
      2. Deep flattening nested lists
      3. Shallow flattening lists
      4. Flattening nested maps
    3. Summary
  10. Persistent Change Detection
    1. Collection equality
      1. Strict equality and mutative methods
        1. Detecting changes
        2. Detecting no changes
      2. Strict equality versus deep equality
    2. Transformations versus mutations
      1. Transformations always return new collections
      2. Detecting changes before transformations
    3. Caching side-effects
    4. Summary
  11. Working with Sets
    1. Sets are not lists
      1. Do not use the get() method
      2. No defined iteration order
      3. Maps with keys only
    2. Removing duplicates
      1. Converting to sets
      2. Converting to sets, then back to lists
      3. Lazy duplicate removal
    3. Ordered sets
      1. Sorting sets
      2. Iterating over sets
    4. Maintaining sets
      1. Adding unique values
      2. Adding duplicate values
    5. Summary
  12. Comparing Collections
    1. Set intersections
      1. Intersecting sets
      2. Ordered intersections
    2. List intersections
      1. Reducing list intersections
      2. Filtering list intersections
    3. Collection differences
      1. Set differences
      2. List differences
    4. Comparing maps
      1. Map intersections
      2. Map differences
    5. Subsets and supersets
      1. List subsets
      2. List supersets
    6. Summary
  13. Combining Collections
    1. Merging maps
      1. Merging maps by key
      2. Merging maps with complex keys
    2. Merging lists
      1. Merging simple values
      2. Merging lists of maps
      3. Merging lists of lists
    3. Concatenating lists and sequences
      1. Simple value concatenation
      2. Lazy sequence concatenation
    4. Interposing and interleaving
      1. Lazily interposing values
      2. Lazily interleaving values
    5. Summary
  14. Declarative Decision Making
    1. Mapping behavior
      1. Keys are logical paths, values are behavior
      2. Wrapping behavior maps in functions
    2. Parameters and defaults
      1. Providing default behavior
      2. Parameterizing mapped behavior
    3. Composing behavior
      1. A generic higher-order behavior function
      2. Logical and/or conditions
      3. Complex behavior compositions
    4. Summary
  15. Side-Effects in User Interfaces
    1. A simple application
      1. Application data
      2. Filter controls
      3. Episode results
    2. DOM side-effects
      1. HTML markup
        1. Filter fields
        2. Rating slider
        3. Episode template
      2. Filtering episodes
      3. Handling events
      4. Rendering elements
    3. React side-effects
      1. Application state
      2. Handling events and changing state
      3. Mapping episodes to elements
    4. Summary
  16. Side-Effects in Node.js
    1. Reading data into collections
      1. Reading and parsing CSV data
      2. Reading large amounts of data
        1. Using concat()
        2. Using push()
        3. Using push() and withMutations()
    2. Writing collection data
      1. Iterating over collections and writing lines
      2. Asynchronous data and sequences
      3. Chaining lazy sequences and streams
    3. Summary
  17. Immutable Architecture
    1. The reusable application state updater
      1. Initial state
      2. Side-effects
      3. Updating state and running side-effects
    2. Initial application state
      1. Result state
      2. Creating a new episode state
    3. Events and state updaters
      1. Updating the search query
      2. Updating the checkboxes and slider state
      3. Updating new episode data
      4. Creating new episodes
    4. Executing side-effects
      1. Rendering episode results
      2. Rendering the result count
      3. Resetting the new episode form
    5. Summary

Product information

  • Title: Mastering Immutable.js
  • Author(s): Adam Boduch
  • Release date: September 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788395113