mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.23k stars 139 forks source link

Feature: provide a way to supply IStateChangedNotifier to FluxorComponent #340

Closed johnbaro closed 1 year ago

johnbaro commented 1 year ago

I want to encapsulate all state into a Facade, including IState.

This is not possible with FluxorComponent as relies on an IStateChangedNotifier member to be present.

Would it be accepted if I opened a PR to support the following which would be integrated into the collection of states

protected IEnumerable<IStateChangedNotifier> States { get; }
mrpmorris commented 1 year ago

Components should only subscribe to parts of state they are interested in, not everything.

johnbaro commented 1 year ago

I misspoke sorry, I meant that I want to encapsulate all relevant state for a single entity (Todo) into a facade. So the interface might look like:

public interface ITodoFacade
{
    void Load();    
    Todo Get(string id);
    IState<TodoState> State { get; }
    // etc..
}
mrpmorris commented 1 year ago

Can't you also implement IStateChangedNotifier on that and FluxorComponent will pick it up?

johnbaro commented 1 year ago

Yes, for some reason when I looked at the code it looked like a more complex interface. Closing this I guess. Thanks.

mrpmorris commented 1 year ago

Just to be clear.

I think if you descend your interface from IStateChangedNotifier, then FluxorComponent/FluxorLayout will detect it when it scans for injected properties and will automatically re-render when it triggers its event.

johnbaro commented 1 year ago

Yes, that worked perfectly thanks, 5 lines and done. Thanks again.

On Tue, 16 Aug 2022, 21:11 Peter Morris, @.***> wrote:

Just to be clear.

I think if you descend your interface from IStateChangedNotifier, then FluxorComponent/FluxorLayout will detect it when it scans for injected properties and will automatically re-render when it triggers its event.

— Reply to this email directly, view it on GitHub https://github.com/mrpmorris/Fluxor/issues/340#issuecomment-1216491016, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARZ4JES3NE7ZH6HVYADX3CLVZNZN3ANCNFSM56GWVW4A . You are receiving this because you modified the open/close state.Message ID: @.***>