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

Immutable Data With Immer

Immutable Data With Immer

Using immutable data structures provides many benefits, including making your code easier to reason about and less prone to bugs.

072193805185e22e0f42720b3a048149?s=128

Vitor Alencar

February 08, 2020
Tweet

Transcript

  1. Immutable Data With Immer Using immutable data structures provides many

    benefits, including making your code easier to reason about and less prone to bugs.
  2. HELLO Vitor Alencar @vitormalencar

  3. Immutable State Structural sharing Currying Detect and distribute changes in

    data Today we’re looking at updates and new features regarding...
  4. Functional Programming

  5. Why Immutability is so important ?

  6. Is deletable ?

  7. Using immutable data structures provides many benefits, including making your

    code easier to reason about and less prone to bugs.
  8. WHY • Immutable objects are simpler to construct, test, and

    use • Truly immutable objects are always thread-safe • They help to avoid temporal coupling • Their usage is side-effect free
  9. Aug 4, 2014

  10. None
  11. nice but….

  12. Immer

  13. Keeps previous state, produces new next state

  14. None
  15. None
  16. How does Immer work?

  17. None
  18. • Proxy root • Lazily create proxy when a field

    is dereferenced • Upon write, create shallow clone • Upon finish, combine clones, freeze the modified objects
  19. None
  20. None
  21. None
  22. None
  23. None
  24. Immutable State

  25. Currying

  26. Even Better

  27. Hooks

  28. Hooks

  29. Performance

  30. None
  31. • Immutability with normal JavaScript objects, arrays, Sets and Maps.

    No new APIs to learn! • Strongly typed, no string based paths selectors etc. • Structural sharing out of the box • Object freezing out of the box • Deep updates are a breeze • Boilerplate reduction. Less noise, more concise code. • First class support for patches • Small size 6kb Benefits
  32. Obrigado!