Menu Close

Redux Essentials

Redux and Redux-Saga Flow Chart

Redux is a Library to centrally manage the state of your application. Due to its unidirectional data flow, predictable, reproducible and thus testable applications are possible.

You can think of it as a global, generic container that contains a state and a bunch of specific, self-defined functions. Only these functions are allowed to change that state, thus there will never be more than one value for a specific use case. Immutability is the important key concept there.

Immutability

In short, Immutability means that an object cannot be changed once it is created (“burned into memory”). The opposite of that is mutabilty, which means that you actually can change the object (mutate it).

One benefit of Immutability is predictability, meaning that you can predictably say how an object changed over the past. 

Another benefit (there derivate more, like memoization) is concurrency, meaning that you can share an object safely between two different entities (processes, threads, users,…). This prevents changing an object while someone else is using it, which relates to predictability.

Redux uses Immutability for changing the state based on actions. This brings benefits like the already explained predictability, as well as extendabilty by addons or storing your application state for a better developer experience. For example, you could save a lot of time in your development process by simply persisting your state and rehydrating them when rebuilding. One example for such a Redux addon is Redux saga, which enables app side effects such as requests or other long running, asynchronous operations. 

The basic class Store dispatches actions to manipulate its internal state. To get notified when the state changed (which can only happen after an action was dispatched), you may subscribe to the store. This helped me to understand the concept behind Redux.

Leave a Reply

Your email address will not be published. Required fields are marked *

10 + 11 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.