mrpmorris / Fluxor

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

Add event for specific action on Dispatcher #338

Closed BISmb closed 1 year ago

BISmb commented 1 year ago

Hello,

Sometimes I would like to be notified of a specific action only (within my Blazor component). I was wondering if something like the below could be added to the Dispatcher?

Dispatcher.On<MyAction>(_ => DoSomeLogic());

Currently, I use an extension method on the Dispatcher class to get this functionality.

public static void OnActionDispatched<TAction>(this IDispatcher dispatcher, Action actionToRun)
{
    dispatcher.ActionDispatched += (sender, args) =>
    {
        if (args.Action.GetType() == typeof(TAction))
            actionToRun();
    };
}

Does this type of addition make sense with the architecture or Fluxor? I can work on an example PR if need be.

mrpmorris commented 1 year ago

This already exists... https://github.com/mrpmorris/Fluxor/blob/master/Source/Tutorials/01-BasicConcepts/01E-ActionSubscriber/README.md

BISmb commented 1 year ago

Ah sorry, I forgot about the ActionSubscriber.