I am experiencing difficulties integrating Fluxor into my Blazor Auto application. While the initial setup appears correct, the state management does not work as expected, particularly with action dispatching and state updates.
Projects Structure
Nexus.Retail: Blazor Server app for the main retail interface.
Nexus.Retail.Client: Blazor WebAssembly app for the client interface.
Nexus.Retail.Components: Contains shared Razor components and classes specific to Nexus Retail.
Problem Details
State Not Updating:
The counter button does not increment the count when clicked. The action seems to be placed in the queued actions but is not dequeued correctly. I tried creating a blank Blazor WASM project and Fluxor was working just fine.
using Fluxor;
namespace Nexus.Retail.Components.State
{
[FeatureState]
public class CounterState
{
public int Count { get; }
public CounterState()
{
Count = 0; // Default value
}
public CounterState(int count)
{
Count = count;
}
}
}
IncrementCounterAction.cs
namespace Nexus.Retail.Components.State
{
public class IncrementCounterAction { }
}
CounterReducers.cs
using Fluxor;
namespace Nexus.Retail.Components.State
{
public static class CounterReducers
{
[ReducerMethod]
public static CounterState ReduceIncrementCounterAction(CounterState state, IncrementCounterAction action) =>
new CounterState(state.Count + 1);
}
}
Program.cs (Server-Side)
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Fluxor;
using Fluxor.Blazor.Web.ReduxDevTools;
using Nexus.Retail.Components;
using Nexus.Retail.Components.Services;
using Nexus.Retail.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents().AddInteractiveServerComponents().AddInteractiveWebAssemblyComponents();
builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddFluxor(o =>
{
o.ScanAssemblies(typeof(Nexus.Retail.Components.State.CounterState).Assembly);
o.UseReduxDevTools(rdt => rdt.Name = "My application");
});
builder.WebHost.UseStaticWebAssets();
var app = builder.Build();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode().AddInteractiveWebAssemblyRenderMode().AddAdditionalAssemblies(
typeof(Nexus.Retail.Components._Imports).Assembly,
typeof(Nexus.Retail.Client._Imports).Assembly
);
app.Run();
Program.cs (Client-Side)
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Nexus.Retail.Components.Services;
using Fluxor;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddFluxor(o => o.ScanAssemblies(typeof(Nexus.Retail.Components.State.CounterState).Assembly));
await builder.Build().RunAsync();
Description
I am experiencing difficulties integrating Fluxor into my Blazor Auto application. While the initial setup appears correct, the state management does not work as expected, particularly with action dispatching and state updates.
Projects Structure
Problem Details
State Not Updating: The counter button does not increment the count when clicked. The action seems to be placed in the queued actions but is not dequeued correctly. I tried creating a blank Blazor WASM project and Fluxor was working just fine.
Code Snippets
Counter.razor
CounterState.cs
IncrementCounterAction.cs
CounterReducers.cs
Program.cs (Server-Side)
Program.cs (Client-Side)
App.razor (Server-Side)
.csproj (Server-Side)
Additional Context
Request
Any guidance on resolving these issues would be greatly appreciated. Specifically, I'm looking for: