Saturday, August 14, 2021 / Blazor
To best understand Blazor-State, you should be familiar with Blazor, MediatR, the Command Pattern, and the Chain of Responsibility Pattern.
Blazor is a framework that allows programmers to write client-side code in C#. Blazor provides near-native performance and requires no plugins, because it runs on top of WebAssembly. You can learn more about Blazor here.
MediatR is an implementation of the Mediator Pattern. The Mediator Pattern decouples objects by providing a layer through which they can communicate. A widely-used analogy to the Mediator Pattern is an air traffic controller. Instead of every plane (think object) having to talk to every other plane (object) to ensure they don't crash into one another, the planes (objects) talk to the air traffic controller (the mediator), who can then give relevant information ("Don't move onto the runway yet, Plane A! Plane B is landing right now!") to the other planes (objects). For a more in-depth explanation of the Mediator Pattern, see this article.
In the Command Pattern, clients are decoupled from commands by representing actions as objects which implement a
Command interface. This interface requires an
execute() method. This pattern is beneficial because it allows an application to make queueable requests. You can learn more about the Command Pattern here.
In the Chain of Responsibility Pattern, the sender of a message sends its message to the first link in a chain of handlers. That first link can choose to either handle the message or pass it along to the second link in the chain. That second link can make the same decision, and so on down the line, until the message is either handled or the end of the chain is reached. You can learn more about the Chain of Responsibility Pattern here.
Blazor-State is an approach to managing state in Blazor.
Blazor-State implements a
Store which has a collection of
State. Behaviors can be registered via the MediatR pipeline and the extension method
AddBlazorState provided by Blazor-State.
When an Action is triggered in the view, it is sent to the Mediator, which sends the Action down the Chain of Responsibility. A Handler in the Chain of Responsibility handles the Action and updates the State. Then the View updates with the updated State. This is known as unidirectional data flow.
Blazor-State can be used in Blazor WebAssembly Apps in need of state management, particularly for the purposes of updating Views based on State.
To learn the basics of Blazor-State, follow this tutorial, or follow along with the video below.
As you go through the Getting Started video, you'll want to have the following links handy:
Blazor-State uses three terms which can sometimes cause confusion due to similar concepts used in other contexts. For clarity, here are the definitions of those terms as used by Blazor-State:
To learn more, explore the following resources:
Also published at ilyana.dev.