Skip to content

Lorefist5/FluentSignals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FluentSignals

A reactive state management library for .NET with first-class Blazor support. FluentSignals provides a simple, type-safe way to manage application state with automatic UI updates.

Features

  • Reactive State Management: Signals automatically notify subscribers when values change
  • Type-Safe: Full generic support with compile-time type checking
  • Async Support: Built-in support for asynchronous operations with loading and error states
  • Composite Signals: Automatically manage subscriptions to signals containing internal signals
  • HTTP Resource Management: Specialized signals for HTTP operations with retry logic
  • Blazor Integration: SignalComponentBase for automatic subscription management and UI updates

Installation

dotnet add package FluentSignals
dotnet add package FluentSignals.Blazor # For Blazor projects

Quick Start

Basic Signal Usage

// Create a signal
var counter = new TypedSignal<int>(0);

// Subscribe to changes
counter.Subscribe(value => Console.WriteLine($"Counter: {value}"));

// Update the value
counter.Value = 5; // Outputs: Counter: 5

Blazor Component Usage

@inherits SignalComponentBase

<div>
    <p>Count: @counter.Value</p>
    <button @onclick="Increment">Increment</button>
</div>

@code {
    private readonly TypedSignal<int> counter = new(0);

    protected override void OnInitialized()
    {
        base.OnInitialized();
        // Automatically triggers StateHasChanged when signal changes
        SubscribeForUpdate(counter);
    }

    private void Increment() => counter.Value++;
}

Async Operations

var asyncSignal = new AsyncTypedSignal<string>();

// Subscribe to all state changes
asyncSignal.IsLoading.Subscribe(loading => Console.WriteLine($"Loading: {loading}"));
asyncSignal.Error.Subscribe(error => Console.WriteLine($"Error: {error?.Message}"));
asyncSignal.Subscribe(value => Console.WriteLine($"Value: {value}"));

// Execute async operation
await asyncSignal.ExecuteAsync(async () => {
    await Task.Delay(1000);
    return "Data loaded!";
});

HTTP Resources

// Create HTTP resource
var httpResource = new HttpResource(httpClient);

// Make requests with automatic state management
await httpResource.GetAsync<User[]>("/api/users");

// Access state
if (httpResource.IsLoading.Value)
    // Show loading indicator
else if (httpResource.Error.Value != null)
    // Handle error
else
    // Use httpResource.Value

Documentation

For more examples and detailed documentation, see the demo application in the FluentSignals.ServerTest project.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published