Core Feature

Event System

Decouple your UI components. Controllers trigger events, handlers update the UI.

The Problem

Controllers become "God Objects" that know too much about the UIโ€”every action explicitly updates every affected component.

The Solution

Invert the dependency. Controllers trigger events. Independent handlers update the UI.

1. Define Events

public record TaskCompletedEvent(int TaskId);

2. Create Handlers

[SwapHandler]
public class TaskListHandler : ISwapEventHandler<TaskCompletedEvent>
{
    public Task HandleAsync(TaskCompletedEvent evt, SwapResponseBuilder builder, ...)
    {
        builder.AlsoUpdate(...);
        return Task.CompletedTask;
    }
}

3. Clean Controllers

return SwapEvent(new TaskCompletedEvent(id)).Build();

Benefits

Without EventsWith Events
Controllers coupled to UIControllers know business events only
Adding widget = editing controllerAdding widget = new handler
Hard to testUnit test handlers independently

Key Components

  • [SwapHandler] attribute
  • ISwapEventHandler<T>
  • SwapEvent() method

Best For

  • โœ“ Complex dashboards
  • โœ“ Multi-widget pages
  • โœ“ Large teams

See Events in Action

Watch handlers coordinate updates automatically.

Open Demo Lab