Angular State Management Options

John Peters - Nov 30 '19 - - Dev Community

I do not use libraries for state management. The reason is, when I studied Redux, I saw it as a great tool whose problem it solved as being a non-issue.

Within the opinionated React way of doing things, state management is a top priority. Redux could make sense there for sure. However; to me, after 25 years as a programmer state management was never a separate concern. Neither was immutability or drill down data design such as React embraces.

To me the most elegant way to accomplish state management is the ubiquitous EventEmitter. Events and Event Handlers have been around for 50 years. They are a type of Observer pattern, easy to set up and they never fail.

Inter-Component communication may easily rely on EventEmitters contained in an Angular service to both Emit and Subscribe to app wide events. This pattern is loosely coupled in that neither the Emitter or Subscriber are directly coupled to each other. Instead, Angular injects the servive which provides a common code point.

Each component then receives notifications at indeterminate times. This allows each component to change state as needed. Each component boots up and sets the initial state, each notification advances the state flow.

This is really no different than Redux or Angular's own Ngrx. Both register something to trigger an event which notifies a specific component of a new state.

We revealed the super easy Angular Event Service in a prior post in this seies. It showed how easy this pattern is to implement. Who needs ngRx?

JWP2019

Comments Welcome!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player