Changing the interface INonGenericStateObserver to be able to manage the state of different StateObserver<T> objects#4
Conversation
…e some states with various generic types
|
now i have to do this ugly thing: ... |
|
Will reply soon, thanks for your PR! |
|
@megafetis could you elaborate on why this is needed? How does the component look like that uses |
my case: public abstract class AbstractComponent : ComponentBase, IDisposable
{
private CancellationTokenSource? _disposeCancellationSource;
protected CancellationToken DisposeToken => (_disposeCancellationSource??=new()).Token;
private ConcurrentBag<INonGenericStateObserver> _states = new();
protected void RegisterState<TState>(IStateObserver<TState> state,Action? callback = null)
{
state.Register(this, callback ?? StateHasChanged);
_states.Add(state);
}
protected void RegisterState<TState>(IStateObserver<TState> state, Func<Task> callback)
{
state.Register(this, callback);
_states.Add(state);
}
public virtual void Dispose()
{
_disposeCancellationSource?.Cancel();
foreach (var item in _states)
{
item.GetType().GetMethod("Unregister")!.Invoke(item, [this]);
}
}
}derived: @page "/me"
@inherits AbstractComponent
<PageTitle>My page</PageTitle>
<SomeCode/>
@code {
[CascadingParameter]
private CabinetStore Store { get; set; } = null!;
protected override void OnInitialized()
{
this.RegisterState(Store.Notifications);
}
}in addition, there is actually a convenient opportunity to make sense of the common interface |
|
Thanks for clarifying. I think the Your PR makes sense anyway, we can move those methods to the non generic interface though |
Thanks, I hope the changes will be published. I dont not, but |
|
Hello. When do you plan to post updates? |
Example: creating base blazor component with register state function, and unregister when
Dispose