RForge.Blazor.Events lets components talk to each other from anywhere in the tree, without a shared parent,
without parameters passed down through every layer, and without a hand written service full of C# events.
Derive from RfEventComponent and it takes care of subscribing, re-rendering on the right thread,
error handling and disposal for you.
It has two parts. Events (IEvent) are fire and forget messages that any component or
service can publish and any component can handle. State (IState<T>) is a
store-like value with a current value and change notification. Writing an equal value is a no-op, so record
equality keeps components from re-rendering needlessly.
When to Use
When two components that are far apart in the tree need to share a value or react to the same thing: a cart badge that updates when a product card adds an item, a theme picker that restyles unrelated components, a toast host that any component can ask for a message.
Features
- Selectors: re-render only when the part of the state you use changes.
- Scopes:
EventScopeandStateScopeisolate events and give subtrees their own state. Routes includeBubble(the default),Local,Broadcast,Root,GlobalandNamed. - Source generator:
[Subscribe]and[UseState]need no reflection, so they are trim and AOT safe. Analyzers (RFEVT001toRFEVT014) catch mistakes at build time. - Every render mode: static SSR, Interactive Server, WebAssembly and Auto, with or without prerendering, and opt-in state persistence from prerender to interactive.
- Plain components too: opt-in cascading values let third party components read state through
[CascadingParameter].