DEV Community

Discussion on: Advanced Blazor State Management Using Fluxor, part 6 - Persisting State

Collapse
 
thomeijer profile image
Thomas Meijer

Thanks for the great series, I really enjoyed all six posts.

I was wondering how you would go about 'cross user state'. For example, if there are two users active at the same time, and a weather forecast was added by user 1, how would you notify user 2 that a weather forecast was added.

Would it be possible to use a Singleton store where all users can dispatch actions to and subscribe to application wide actions?

Collapse
 
mr_eking profile image
Eric King • Edited

Thanks for the kind words.

In this scenario, the application state is all located in the client, as it's a Blazor WebAssembly application. There's no shared Fluxor state at all, as each client has its own store.

If I were to add cross-client communication so that each client's state could be updated based on another client's actions, I don't think I would do it via Fluxor on the server. I would do it via SignalR on the server, and my "singleton store" would be a database.

User1 submits some change to the server (which gets stored in the database), and that process notifies the server's SignalR hub of the change. The SignalR hub broadcasts the change to all of the listening clients, which would include User2. And User2's listener then Dispatches the appropriate Action to update their Store and whatever UI changes are needed.

Collapse
 
mr_eking profile image
Eric King

FYI I added a simple example using SignalR to the repo for this series. It doesn't persist anything to a database (I'm trying to keep the project as simple as possible) but it does demonstrate how two clients can communicate via Actions. I'll add another blog post about it soon.

github.com/eric-king/BlazorWithFluxor

Collapse
 
thomeijer profile image
Thomas Meijer

That looks exactly like something I was looking for, thanks a bunch!