formaui-net.Framework.Events
1.0.0-preview.27
Prefix Reserved
dotnet add package formaui-net.Framework.Events --version 1.0.0-preview.27
NuGet\Install-Package formaui-net.Framework.Events -Version 1.0.0-preview.27
<PackageReference Include="formaui-net.Framework.Events" Version="1.0.0-preview.27" />
<PackageVersion Include="formaui-net.Framework.Events" Version="1.0.0-preview.27" />
<PackageReference Include="formaui-net.Framework.Events" />
paket add formaui-net.Framework.Events --version 1.0.0-preview.27
#r "nuget: formaui-net.Framework.Events, 1.0.0-preview.27"
#:package formaui-net.Framework.Events@1.0.0-preview.27
#addin nuget:?package=formaui-net.Framework.Events&version=1.0.0-preview.27&prerelease
#tool nuget:?package=formaui-net.Framework.Events&version=1.0.0-preview.27&prerelease
Forma.Framework.Events
Change notification and debouncing. INotifyStateChanged lets a component subscribe an
asynchronous callback to a service, and StateNotifier is the list of callbacks a service keeps
and invokes after each change. IDebounceable runs work for input that arrives in bursts, such as
a search box, a resize or a scroll, once the input has been quiet for a delay, a later request
canceling the one before it; Debouncer measures the delay on a TimeProvider, so a test
advances a fake clock to trigger it.
Install and register
dotnet add package formaui-net.Framework.Events --prerelease
using Forma.Framework.Events;
builder.Services.AddFormaEventServices();
AddFormaEventServices registers IDebounceable as a transient Debouncer, so each consumer
holds its own pending request, and TimeProvider.System as the singleton TimeProvider each
debouncer measures on. It registers with TryAdd, so a service the host registered first is kept,
a TimeProvider included. INotifyStateChanged and StateNotifier are used directly and need no
registration.
| Member | What it does |
|---|---|
INotifyStateChanged.Subscribe(callback) |
Registers a Func<Task> invoked on each change. |
INotifyStateChanged.Unsubscribe(callback) |
Removes a registered callback. |
StateNotifier.NotifyAsync(cancellationToken) |
Invokes every subscribed callback, awaiting each in the order it subscribed. |
IDebounceable.DebounceAsync(action, delay, cancellationToken) |
Runs the action once the delay passes with no further request. |
IDebounceable.Cancel() |
Abandons the request still waiting or running. |
Debouncer.Clock |
The TimeProvider the delay is measured on, given to the constructor. |
Announcing changes
A service's contract extends INotifyStateChanged, and the service keeps a StateNotifier,
forwards subscriptions to it and calls NotifyAsync once its state has changed:
using Forma.Framework.Events;
public interface ICartService : INotifyStateChanged
{
IReadOnlyList<CartLine> Lines { get; }
Task AddAsync(CartLine line, CancellationToken cancellationToken = default);
}
public sealed class CartService : ICartService
{
private readonly StateNotifier _notifier = new();
private readonly List<CartLine> _lines = [];
public IReadOnlyList<CartLine> Lines => _lines;
public async Task AddAsync(CartLine line, CancellationToken cancellationToken = default)
{
_lines.Add(line);
await _notifier.NotifyAsync(cancellationToken);
}
public void Subscribe(Func<Task> callback) => _notifier.Subscribe(callback);
public void Unsubscribe(Func<Task> callback) => _notifier.Unsubscribe(callback);
}
Listening in a component
A component subscribes when it initializes, re-renders on the renderer's thread through
InvokeAsync, and unsubscribes the same method when it is disposed:
@implements IDisposable
@inject ICartService Cart
<span>@Cart.Lines.Count items</span>
@code {
protected override void OnInitialized()
=> Cart.Subscribe(HandleCartChangedAsync);
private Task HandleCartChangedAsync()
=> InvokeAsync(StateHasChanged);
public void Dispose()
=> Cart.Unsubscribe(HandleCartChangedAsync);
}
Unsubscribe removes the callback equal to the one it is given, so a method group, or a delegate
kept in a field, removes what it subscribed.
Debouncing a search
The token handed to the action is canceled by a later DebounceAsync, by Cancel or by the
caller's token, including while the action runs. A superseded or canceled request completes
without throwing, and a zero delay runs the action at once.
The action runs on the thread the delay elapsed on, so a component dispatches its work back to
the renderer with InvokeAsync:
using Forma.Framework.Events;
public sealed partial class ProductSearch : ComponentBase, IDisposable
{
private static readonly TimeSpan SearchDelay = TimeSpan.FromMilliseconds(300);
[Inject] private IDebounceable SearchDebouncer { get; set; } = default!;
private Task HandleQueryChangedAsync(string query)
=> SearchDebouncer.DebounceAsync(token => InvokeAsync(() => SearchAsync(query, token)), SearchDelay).AsTask();
public void Dispose()
=> SearchDebouncer.Cancel();
}
Testing a debounce
A test gives the debouncer a FakeTimeProvider from Microsoft.Extensions.TimeProvider.Testing
and advances it:
var clock = new FakeTimeProvider();
var debouncer = new Debouncer(clock);
var request = debouncer.DebounceAsync(_ => RunAsync(), TimeSpan.FromMilliseconds(300));
clock.Advance(TimeSpan.FromMilliseconds(300));
await request;
License
Apache License 2.0, under the repository's LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- No dependencies.
NuGet packages (9)
Showing the top 5 NuGet packages that depend on formaui-net.Framework.Events:
| Package | Downloads |
|---|---|
|
formaui-net.Framework.Culture
The culture state each user scope holds: the culture that formats dates, numbers and collation, and the UI culture that chooses strings and direction, kept apart so an application can show English text with German formats. |
|
|
formaui-net.Framework.Culture.Browser.Interop
The page's culture coordinator: one per document, it orders every culture switch on the page, gives each the next number in the document's sequence, and delivers the accepted pair to the culture state of every runtime registered with it, each Interactive Server circuit and WebAssembly runtime on the page, so they converge on one pair. |
|
|
formaui-net.Framework.Share
The share contracts: the item a share menu acts on, the targets an item can be shared to, and the sources a host answers a user's credentials through. |
|
|
formaui-net.Blazor
A Blazor component library for .NET 11: form inputs and pickers, dialogs, popovers and toasts, toolbars and menus, tabs and layout, file pickers, uploaders and viewers, icons, emoji and windows. |
|
|
formaui-net.Framework.Feedback
The services behind Forma's feedback surfaces: a toast service any code raises a notice through, a confirm dialog service any code awaits a yes or no from, and a catalog of the statuses an application's badges are named after. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.27 | 111 | 12/3/2026 |
| 1.0.0-preview.26 | 118 | 12/3/2026 |
| 1.0.0-preview.25 | 124 | 12/2/2026 |
| 1.0.0-preview.24 | 183 | 12/1/2026 |
| 1.0.0-preview.23 | 270 | 11/30/2026 |
| 1.0.0-preview.22 | 263 | 11/30/2026 |
| 1.0.0-preview.21 | 273 | 11/29/2026 |
| 1.0.0-preview.20 | 225 | 11/26/2026 |
| 1.0.0-preview.19 | 227 | 11/26/2026 |
| 1.0.0-preview.18 | 203 | 11/26/2026 |
| 1.0.0-preview.17 | 200 | 11/26/2026 |
| 1.0.0-preview.16 | 194 | 11/24/2026 |
| 1.0.0-preview.15 | 193 | 11/23/2026 |
| 1.0.0-preview.14 | 186 | 11/23/2026 |
| 1.0.0-preview.13 | 183 | 11/21/2026 |
| 1.0.0-preview.12 | 186 | 11/20/2026 |
| 1.0.0-preview.11 | 183 | 11/18/2026 |
| 1.0.0-preview.10 | 186 | 11/17/2026 |
| 1.0.0-preview.9 | 261 | 11/17/2026 |
| 1.0.0-preview.8 | 204 | 11/17/2026 |
What this release changed is in Forma's changelog: https://github.com/FormaUI/Forma/blob/v1.0.0-preview.27/CHANGELOG.md