Top Banner
Immutability and immutableJS Marcelo Cure
12

Immutability and immutable js

Feb 09, 2017

Download

Internet

Marcelo Cure
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Immutability and immutable js

Immutability and immutableJS

Marcelo Cure

Page 2: Immutability and immutable js

What is Immutability?

Page 3: Immutability and immutable js

Why is immutability good?

● no state changing● easier to test● avoid bugs● safe refactoring● leads to better design

Page 4: Immutability and immutable js

Great powers ...

allocates many objects in memory instead of changing existing ones

...comes with great responsibility

Page 5: Immutability and immutable js

Side effect

If a function mutates an object then it has side effects.

Mutation is side effect.

Page 6: Immutability and immutable js

Immutability and FP

● In FP you should only use immutable stuff● Many languages accept mutation● Hybrid languages accept mutation

Page 7: Immutability and immutable js

Apache Camel example

Exchange is a bitch in a route

Page 8: Immutability and immutable js

Weak vs Strong immutability

Page 9: Immutability and immutable js

Immutable JS

Library with immutable collections

Page 10: Immutability and immutable js

Immutable JS

Page 11: Immutability and immutable js

https://facebook.github.io/immutable-js/

Page 12: Immutability and immutable js