diff --git a/Source/Lib/Fluxor.Blazor.Web/Components/FluxorComponent.cs b/Source/Lib/Fluxor.Blazor.Web/Components/FluxorComponent.cs index d8c89d1f..0bdfa366 100644 --- a/Source/Lib/Fluxor.Blazor.Web/Components/FluxorComponent.cs +++ b/Source/Lib/Fluxor.Blazor.Web/Components/FluxorComponent.cs @@ -52,6 +52,25 @@ public void SubscribeToAction(Action callback) }); } + /// + /// Subscribes to be notified whenever a specific action is dispatched + /// + /// The type of action (and its descendants) to be notified of + /// The instance that is subscribing to notifications + /// The asynchronous action to execute whenever a qualifying action is dispatched + public void SubscribeToActionAsync(Func callback) + { + ActionSubscriber.SubscribeToAction(this, action => + { + InvokeAsync(async () => + { + if (!Disposed) + await callback(action); + StateHasChanged(); + }); + }); + } + /// /// Disposes of the component and unsubscribes from any state ///