Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux is a predictable state container

Tags:

redux

The description of Redux project is:

Redux is a predictable state container

Can explain to me what "predictable" word meaning in this context?

like image 913
Matanya Cohen Avatar asked Feb 23 '19 21:02

Matanya Cohen


2 Answers

You first have to understand how Redux works. There are few key principles:

  1. State is a immutable object
  2. You never mutate application state, you always return a new, modified one
  3. All state changes are initiated through actions (they contain desired changes details)
  4. Reducers take current state, action and produce a new state ((state, action) => state)

So you can see that this is all unidirectional (changes flow one way only):

state -> action -> reducer -> state -> action -> reducer -> state ...

Redux is heavily inspired by Elm architecture and encourages functional programming principles, one of them being pure functions (they produce no side effects (like http calls, disk reads) and their output is always the same for the same input).

Every single state change in reducers has to be taken care by developers explicitly. Also all reducers are supposed to be pure. That's where the predictability comes from.

So to summarize, predictable in this context means, that using Redux you'll know what every single action in application will do and how state will change.

like image 186
Evaldas Buinauskas Avatar answered Sep 24 '22 14:09

Evaldas Buinauskas


Redux is a "state container" because it holds all the state of your application. It doesn't let you change that state directly, but instead forces you to describe changes as plain objects called "actions". Actions can be recorded and replayed later, so this makes state management predictable. With the same actions in the same order, you're going to end up in the same state.

By Dan Abramov

like image 35
Nitin Pawar Avatar answered Sep 25 '22 14:09

Nitin Pawar