Skip to content

v.2.3.0

Choose a tag to compare

@fedeAlterio fedeAlterio released this 23 Jun 19:00
· 16 commits to main since this release
d9841e4
  • Added a single notification computed via TrackedScope (performance optimization) using (Signal.TrackedScope(out var subscription, OnSignalChanged))
  • Introduced a new package, SignalsDotnet.Blazor, which enables the use of TrackedScope directly in Razor templates. This was inspired by this Steven Giesel blogpost
@page "/counter"

@using SignalsDotnet
@using R3
@using SignalsDotnet.Blazor

<TrackedScope>
    <div>
        <h1>Counter</h1>
        <p>
            Count: @_count.Value <br />
        </p>
        
        <TrackedScope>
            <p>Now: @_now.Value</p>
        </TrackedScope>

        <button class="btn btn-primary"
                @onclick="() => _count.Value++">
            Click me
        </button>
    </div>
</TrackedScope>

@code {
    readonly CancellationDisposable _cd = new();
    readonly Signal<int> _count = new(0);
    IReadOnlySignal<DateTime> _now = null!;

    protected override void OnInitialized()
    {
        _now = Observable
            .Interval(TimeSpan.FromSeconds(1))
            .Select(_ => DateTime.Now)
            .TakeUntil(_cd.Token)
            .ToSignal();
    }
}