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

RFC: Add ability for consumers to be notified of dispatched actions #66

Closed
mrpmorris opened this issue Aug 7, 2020 · 0 comments
Closed

Comments

@mrpmorris
Copy link
Owner

mrpmorris commented Aug 7, 2020

Some actions contain information that isn't destined for the store's state. For example, an effect that calls an API to return an editable object (e.g. Customer).

As the object is mutable it should not go into state where it can be modified. Instead, allow consumers to subscribe to the dispatching of actions so they can obtain a reference to the editable object for editing without it having to be reduced into state.

An example for observing dispatched actions in a component would look something like this

public class MyComponent : ComponentBase, IDisposable
{
	[Inject]
	protected IDispatcherObserver DispatcherObserver { get; set; }

	private IDisposable Subscription;

	protected override void OnInitialized()
	{
		base.OnInitialized();
		Subscription = DispatcherObserver.Observe<GetForUpdateResultAction>(SetModel);
		var getSupplierAction = new GetForUpdateAction(id: SupplierId);
		Dispatcher.Dispatch(getSupplierAction);
	}

	void IDisposable .Dispose()
	{
		Subscription?.Invoke();
	}
}

Or have a base Fluxor(some name)Component

protected override void OnInitialized()
{
    base.OnInitialized();
    Observe<GetForUpdateResultAction>(SetModel);
    var getSupplierAction = new GetForUpdateAction(id: SupplierId);
    Dispatcher.Dispatch(getSupplierAction);
}

private void SetModel(GetForUpdateResultAction action)
{
    Model = action.Supplier;
    StateHasChanged();
}
@mrpmorris mrpmorris changed the title Add ability for consumers to be notified of dispatched actions RFC: Add ability for consumers to be notified of dispatched actions Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant