State is not being updated when using Fluxor in Blazor Server
I'm trying to add Fluxor to my Blazor Server-side app. All the examples that I've seen are based on the Counter sample blazor app. I need to update a complex entity from within different components and each component need to have the updated entity.
So first I created a state class:
[FeatureState]
public class EntityState
{
public Entity Entity{ get; }
public EntityState()
{
//Empty constructor needed or else exception is thrown on startup
}
public EntityState(Entity entity)
{
this.Entity = entity;
}
}
And an empty action:
public class SetEntityAction
{ }
And finally the reducer:
public static class Reducers
{
[ReducerMethod]
public static EntityState OnSetEntity(EntityState state, SetEntityAction action) =>
new(entity: state.Entity);
}
I then inject all the required services into the page and its components. One component creates an entity in the OnInitialized
method or update the same entity in other methods, for example:
private void OnEntityPropertyValueChanged(SomeProperty property)
{
entity.Propert开发者_运维问答y = property;
dispatcher.Dispatch(new SetAboAction());
}
And in another component I do:
var entity = entityState.Value.Entity;
But I'm definitely missing a step because the entity value is always null. So how do I actually update the entity in the first component and get it in the second component?
精彩评论