Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mastering Immutable.js
Mastering Immutable.js

Mastering Immutable.js: Better JavaScript development using immutable data

Arrow left icon
Profile Icon Adam Boduch
Arrow right icon
AU$33.99 AU$48.99
eBook Sep 2017 216 pages 1st Edition
eBook
AU$33.99 AU$48.99
Paperback
AU$60.99
Subscription
Free Trial
Renews at AU$24.99p/m
Arrow left icon
Profile Icon Adam Boduch
Arrow right icon
AU$33.99 AU$48.99
eBook Sep 2017 216 pages 1st Edition
eBook
AU$33.99 AU$48.99
Paperback
AU$60.99
Subscription
Free Trial
Renews at AU$24.99p/m
eBook
AU$33.99 AU$48.99
Paperback
AU$60.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Immutable.js

Creating Immutable Data

The starting point of writing any Immutable.js code is to create an immutable collection. In this chapter, that's just what we'll do. There are a number of ways to create immutable collections, and you'll learn what they are and when they are appropriate to use. Specifically, we'll look at the following:

  • Using Immutable.js constructors
  • Using utility functions to create collections
  • Parsing JavaScript types into Immutable.js collections

Immutable.js constructors

The Immutable.js API exposes immutable collections as classes. You then use these classes to create new collection instances. This is just like any other object-oriented JavaScript API that exposes classes. There is one important difference, though—these aren't real classes.

There are a number of internal implementation reasons for why Immutable.js doesn't expose actual classes as its API. One reason is that in some cases, collection instances can be reused, such as when creating empty collections. The only thing to keep in mind is that you never need to use the new keyword when creating Immutable.js data.

The types of Immutable.js data

The entirety of the Immutable.js API is represented...

Using the of() method

Collection types in Immutable.js have a static of() method. This method is an alternative to using the collection constructor. The one downside to using the constructor approach is that you have to pass in a JavaScript literal. You have to build and allocate memory for a structure that you're not actually using.

The of() method uses the arguments that are passed to it as the collection items.

Lists of values

You can use the of() method to create lists of values as follows:

const myList = List.of(1, 2, 3);
console.log('myList', myList.toJS());
// -> myList [ 1, 2, 3 ]

Maps of values

...

Parsing data using the fromJS() function

Immutable.js has one more tool for creating immutable data in addition to everything we've looked at so far in this chapter. The fromJS() function is similar to a JSON parser, because it parses the same types of JavaScript objects that you'll see when you parse JSON strings: objects and arrays.

Parsing JavaScript arrays

You can parse a regular JavaScript array, resulting in a list, as shown here:

import { fromJS } from 'immutable';
const myList = fromJS([1, 2, 3]);
console.log('myList', myList.get(0));
// -> myList 1

This is just like passing the array to the List constructor.

...

Summary

In this chapter, you were introduced to the various types of collections found in Immutable.js. We then looked at some code that creates new instances of these collections. Most of the time, you'll want to pass some initial data to a collection when it's created. There are a number of ways to create collections with initial data, including passing native JavaScript types to the constructors and using the of() static method. We then looked at the fromJS() function for when you need to parse complex JavaScript structures into their Immutable.js counterparts.

In the next chapter, you'll learn how to mutate your collections using persistent change methods.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • 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

Description

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.

Who is this book 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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 28, 2017
Length: 216 pages
Edition : 1st
Language : English
ISBN-13 : 9781788397247
Vendor :
Facebook
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 28, 2017
Length: 216 pages
Edition : 1st
Language : English
ISBN-13 : 9781788397247
Vendor :
Facebook
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
AU$249.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts
AU$349.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 204.97
Mastering Blockchain
AU$75.99
Mastering JavaScript Functional Programming
AU$67.99
Mastering Immutable.js
AU$60.99
Total AU$ 204.97 Stars icon
Banner background image

Table of Contents

16 Chapters
Why Immutable.js? Chevron down icon Chevron up icon
Creating Immutable Data Chevron down icon Chevron up icon
Persistent Changes Chevron down icon Chevron up icon
Filtering Collections and Finding Items Chevron down icon Chevron up icon
Sequences and Side-Effects Chevron down icon Chevron up icon
Sorting Collections Chevron down icon Chevron up icon
Mapping and Reducing Chevron down icon Chevron up icon
Zipping and Flattening Chevron down icon Chevron up icon
Persistent Change Detection Chevron down icon Chevron up icon
Working with Sets Chevron down icon Chevron up icon
Comparing Collections Chevron down icon Chevron up icon
Combining Collections Chevron down icon Chevron up icon
Declarative Decision Making Chevron down icon Chevron up icon
Side-Effects in User Interfaces Chevron down icon Chevron up icon
Side-Effects in Node.js Chevron down icon Chevron up icon
Immutable Architecture Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.