Time travel is probably one of the most intriguing and fascinating thoughts out there. Einstein’s theories say, it might actually be possible to travel time. Though, as of now it does not seem like happening anytime soon.
Anyway, in the world of programming, a given application is a universe – U, that holds states and these states change over time. This application universe U necessarily is ordered, and nonchaotic. These states or at least those that are relevant, may be captured and replayed or recreated, by traveling back and forth in time. This time travel is made possible and coherent for our application universe U, by using tools like Redux!
Redux makes this possible by following 3 principles:
- Single source of truth – the state of your whole application is stored in an object tree within a single store
- State is read-only – the only way to change the state is to emit an action, an object describing what happened
- Changes are made with pure functions – to specify how the state tree is transformed by actions, you write pure reducers.
If you are into frontend technologies and find time travel interesting, redux might draw your attention, might even capture your imagination. Redux directly attacks one of the extremely subtle to fix programming bugs caused by – side effects! This in itself is huge. State changes occur only via reducer actions that execute pure functions. Hence whoever has subscribed to the action, is notified, once a state has changed. Changed state, is a new object, though old state held by not yet updated subscribers, still hold valid value or old object, till updated. This ensures coherence, even while change is being propagated through your app. Function purity guarantees predictability, ensuring time travel yielding the same state of the Universe at any particular point in time, though traveled again and again.
Finally, as all states of your application are available at any instant of time, it is a great boon for debugging and testing the application. Redux seems to be a great tool that can be used not just for the front-end development but can also be equally useful and usable for the back-end as well.