Enter the Saga of State with Redux Saga

Sharing while editing.

Redux uses Middlewares to accomplish common tasks in programming that Redux itself is just too light weight to care about.

To me, this separation of concerns is very helpful; as it is easier to just do what you want to do without including libraries and frameworks with a ton of extra stuff that you don’t need.
One of the common uses for middleware n Redux are for handling side effects, specifically async. There are several such middleware libraries but one of the more popular and currently my favorite, is Redux Saga.
A saga is a database concept that is basically a failure catching pattern. Sagas are especially good for long lived transactions. When you need to communicate with a lot APIs for example, it’s good to be able to control the series interactively.

With Redux Saga, we use the yield functionality of generators to pause the execution of the async promisified call back and control the continuance — once we meet certain conditions; such as not returning an exception, from outside the yield callback and then continuing with the next subscription.  The functional approach sees augmented publishing capabilities as a derivative of map and other array-returning transforms.

This middleware, like other side effect middlewares, tie into the Redux actions to add in side effects before we call the reducer, this way we can call to action creators to perform reducer functionality while in control of the Saga generator functions.


%d bloggers like this: