Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async overload of SubscribeToAction #533

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Source/Lib/Fluxor.Blazor.Web/Components/FluxorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ public void SubscribeToAction<TAction>(Action<TAction> callback)
});
}

/// <summary>
/// Subscribes to be notified whenever a specific action is dispatched
/// </summary>
/// <typeparam name="TAction">The type of action (and its descendants) to be notified of</typeparam>
/// <param name="subscriber">The instance that is subscribing to notifications</param>
/// <param name="callback">The asynchronous action to execute whenever a qualifying action is dispatched</param>
public void SubscribeToActionAsync<TAction>(Func<TAction, Task> callback)
{
ActionSubscriber.SubscribeToAction<TAction>(this, action =>
{
InvokeAsync(async () =>
{
if (!Disposed)
await callback(action);
StateHasChanged();
});
});
}

/// <summary>
/// Disposes of the component and unsubscribes from any state
/// </summary>
Expand Down