A word on state management

Some components must have state. When there is a need for another component to know about that very same state, the first component needs to find a way to communicate that to the other component. There are many ways to achieve this. One way is to ensure that all state that should be shared lives in a centralized store. Think of this store as a single source of truth, from which all components can read. Every state does not necessarily need to end up in the centralized store, as the state may only concern a specific component. Before NgRx and Redux, one way of solving this was to put everything in a globally accessible object or service. The store, as we mentioned, is just that. It is globally accessible in the sense that it can be injected into any component that might need it. A word of caution; even though it is tempting to put all of our state in our store, we really shouldn't. State that we notice needs to be shared between components is worth putting there. 

Another benefit we get from having a centralized store is that it is very easy to save down the application's state for later recovery. If state only lives in one place, a user, or the system, can easily persist that state to a backend so that next time, if they want to continue from where they left off, they can easily do so by querying the backend for that state. So, there does exist another reason for wanting a centralized store other than wanting to share the data between many components.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.126.248