Fluxor.Blazor.Persistence 1.2.3

dotnet add package Fluxor.Blazor.Persistence --version 1.2.3                
NuGet\Install-Package Fluxor.Blazor.Persistence -Version 1.2.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fluxor.Blazor.Persistence" Version="1.2.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fluxor.Blazor.Persistence --version 1.2.3                
#r "nuget: Fluxor.Blazor.Persistence, 1.2.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Fluxor.Blazor.Persistence as a Cake Addin
#addin nuget:?package=Fluxor.Blazor.Persistence&version=1.2.3

// Install Fluxor.Blazor.Persistence as a Cake Tool
#tool nuget:?package=Fluxor.Blazor.Persistence&version=1.2.3                

blazor-fluxor-persistence

Fluxor state persistence for web blazor application using LocalStorage. Currently supports LocalStorage only. Supports LocalStorage persistence only which is default, if set to other options - state will not persist.

Usage

In Program.cs file Add UsePersistence to FluxorOptions

Install Fluxor.Blazor.Persistence

Add below code to the program.cs file

builder.Services
  .AddFluxor(o =>
  {
    o.ScanAssemblies(typeof(Program).Assembly)
    .UseRouting()
    .UsePersistence();
  });

Using routing middleware but do not want to persist routes (default value for PersistOptions.PersistRoutes is true)

builder.Services
  .AddFluxor(o =>
  {
    o.ScanAssemblies(typeof(Program).Assembly)
    .UseRouting()
    .UsePersistence(x => x.PersistRoutes = false);
  });

Exceptions

Any exception thrown when loading/saving the persist state are added to `StatePersistenceFailureState' This errors can be retrieved from state

This exceptions are cleared on browser refresh or close. The exceptions can also be cleared by dispatching action

e.g. Razor component 'StateErrors.razor'

@page "/persist-state-errors"
@inherits FluxorComponent
@using Fluxor.Blazor.Persistence.Store
@inject IState<StatePersistenceFailureState> State
@inject IDispatcher Dispatcher;

<h3>Errors</h3>

@if (State.Value.Errors.Count == 0)
{
  <div>No Errors</div>
}
else 
{
  @foreach(var e in State.Value.Errors)
  {
    <div class="row">
      <span class="col1">@e.ActionType</span>
      <span class="col2">@e.FeatureName</span>
      <span class="col3">@e.Exception?.Message</span>
    </div>
  }

  <button class="btn btn-outline" @onclick="ClearErrors">Clear Errors</button>
}

@code {
  protected override void OnInitialized()
  {
    base.OnInitialized();
  }

  public void ClearErrors() 
  {
    Dispatcher.Dispatch(new ClearStatePersistenceFailureStateAction());
  }
}

Release 1.2.0 change log

public class PersistOtions
{
  public PersistenceType PersistenceType { get; set; } = PersistenceType.LocalStorage;
  public string PersistenceKey { get; set; } = "Fluxor.Blazor.Persistence";
  public bool PersistRoutes { get; set; } = true;
}

Added new PersistRoutes flag - default true.

Release 1.2.1 change log

Issue: Persisted state for the feature is null, causes initial state to be null.
Fix: do not restore feature state if persisted loaded state is null.

Release 1.2.2 change log

Added .net7.0 as target framework

Release 1.2.3 change log

Added .net5.0 as target framework Added support for session storage as persistenceType Removed nuget package Blazored.LocalStorage

builder.Services
  .AddFluxor(o =>
  {
    o.ScanAssemblies(typeof(Program).Assembly)
    .UseRouting()
    .UsePersistence(x => x.PersistenceType = PersistenceType.SessionStorage);
  });
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.3 1,034 10/10/2023
1.2.2 144 10/4/2023
1.2.1 149 10/3/2023
1.2.0 125 9/28/2023
1.1.0 131 9/27/2023