Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Immutable State in Redux

Immutable State in Redux

I did a talk with a co-worker about Immutable.JS in Redux. These are the slides.

Ryan Boone

March 13, 2018
Tweet

More Decks by Ryan Boone

Other Decks in Programming

Transcript

  1. immutable [ih-myoo-tuh-buh l] adjective 1. not mutable; unchangeable; 
 changeless.

    "immutable". Dictionary.com Unabridged. Random House, Inc. 12 Mar. 2018. <Dictionary.com http://www.dictionary.com/browse/immutable>. What is immutability? Immutable State in React #ContainerStoreTech
  2. •Improved performance •Predictable, consistent
 structure of application data •Rich, well

    documented API
 (Immutable.JS) Why immutability? Immutable State in React #ContainerStoreTech
  3. •Built by Facebook •No dependencies •JS-like API •Performant with complex

    
 objects #ContainerStoreTech Immutable State in React Immutable.js
  4. •List •Map and Ordered Map •Set and Ordered Set •Stack

    #ContainerStoreTech Data Structures Immutable State in React
  5. •List (think JS array) •Map (think JS object) •Default data

    structures 
 when converting with 
 fromJS() #ContainerStoreTech Data Structures Immutable State in React
  6. •Shallow (get, set, delete) •Deep (getIn, setIn, deleteIn) •Callback Methods

    (update) #ContainerStoreTech Getters and Setters Immutable State in React
  7. •List Methods (push, pop, 
 map, reduce, find, etc) •Map

    Methods (merge, 
 mergeIn, mergeDeep) #ContainerStoreTech Getters and Setters Immutable State in React
  8. •List Methods (push, pop, 
 map, reduce, find, etc) •Map

    Methods (merge, 
 mergeIn) •Chainable #ContainerStoreTech Getters and Setters Immutable State in React
  9. •Never mix plain JS objects 
 with Immutable.JS •Make entire

    Redux state 
 an Immutable.JS object #ContainerStoreTech Immutable.js with Redux Best Practices Immutable State in React
  10. •Never mix plain JS objects 
 with Immutable.JS •Make entire

    Redux state 
 an Immutable.JS object •Use Immutable.JS everywhere 
 except dumb components #ContainerStoreTech Immutable.js with Redux Best Practices Immutable State in React
  11. •Limit your use of toJS() •Never use toJS() in 


    mapStateToProps() #ContainerStoreTech Immutable.js with Redux Best Practices Immutable State in React
  12. •Limit your use of toJS() •Never use toJS() in
 mapStateToProps()

    •Try to limit Immutable.js
 methods to reducers, use
 abstract methods elsewhere #ContainerStoreTech Immutable.js with Redux Best Practices Immutable State in React
  13. •Can be more difficult 
 to debug •No destructuring or

    spread
 operators #ContainerStoreTech Gotchas Immutable State in React
  14. •Can be more difficult 
 to debug •No destructuring or

    spread
 operators •Not suitable for small values
 that change often #ContainerStoreTech Gotchas Immutable State in React