Replies: 2 comments
-
I don't think this is a simple task. Second SignalR channel just for cross client communication is normal. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Create a singleton and dispatch the change events. It's a hacky way, but that's the only way till something elegant emerges. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Blazor server-side and have been looking into the various third-party options for state management. The general idea goes that when something needs data from the backend, an action requests it and stores it in state somewhere that components can subscribe to. As the state changes, they receive the updates and all is good with the world.
If this spans a list of objects and I just need the data for one, I can read it out of the list given its identifier - no issues. And if I create, update or delete any of these objects, I can insert, update and remove the respective objects from the list in the state, so I can keep the "pull all" requests to a minimum.
That's all well and good, but as I understand it, Blazor runs entirely in the context of a single connected user. If UserA and UserB each connect to the site and pull a list of objects, then UserA creates a new object and deletes another existing one, UserA will have an up-to-date copy of the state, but UserB will have the original state when the connection was originally established.
Given I know when all the users update anything in my separate data store (via a service call), it seems disingenuous that after creating a list of objects in state, I'd then occasionally poll to refresh this cache in case any updates have been made by another user on the site.
I've considered setting up a separate SignalR hub that each client could subscribe to upon launch that would notify subscribers whenever a change has been made on the server state in order to prompt clients to request updated copies of that object and any referenced objects (instead of refreshing the full lists), since it has the ability to Send to all connected clients... but again, if Blazor is running in a single-user context, seems like the only connected client it'd see is going to be the one connected user already using SignalR for UI updates.
I could set up a second hub that everyone could connect to and host it from somewhere else, like Azure SignalR, but that seems increasingly complex for what seems like a simple ask.
TLDR: How can the server of a Blazor server-side hosted app notify all connected clients that a change has been made to data and that they all need to refresh their state to remain in sync?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions