$30 off During Our Annual Pro Sale. View Details »

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.

Vitor Alencar

February 08, 2020
Tweet

More Decks by Vitor Alencar

Other Decks in Programming

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.

    View Slide

  2. HELLO
    Vitor Alencar
    @vitormalencar

    View Slide

  3. Immutable
    State
    Structural
    sharing
    Currying
    Detect and distribute
    changes in data
    Today we’re looking at
    updates and new features
    regarding...

    View Slide

  4. Functional
    Programming

    View Slide

  5. Why Immutability
    is so important ?

    View Slide

  6. Is deletable ?

    View Slide

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

    View Slide

  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

    View Slide

  9. Aug 4, 2014

    View Slide

  10. View Slide

  11. nice but….

    View Slide

  12. Immer

    View Slide

  13. Keeps previous state, produces new next state

    View Slide

  14. View Slide

  15. View Slide

  16. How does Immer
    work?

    View Slide

  17. View Slide

  18. ● Proxy root
    ● Lazily create proxy when a field is
    dereferenced
    ● Upon write, create shallow clone
    ● Upon finish, combine clones, freeze the
    modified objects

    View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. View Slide

  23. View Slide

  24. Immutable
    State

    View Slide

  25. Currying

    View Slide

  26. Even Better

    View Slide

  27. Hooks

    View Slide

  28. Hooks

    View Slide

  29. Performance

    View Slide

  30. View Slide

  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

    View Slide

  32. Obrigado!

    View Slide