mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-03-29 13:51:37 +00:00
Made event registration resilient against double registrations
This commit is contained in:
parent
e416552467
commit
1436ffd7e0
@ -100,7 +100,7 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
|
||||
Event.PLUGINS_RELOADED,
|
||||
};
|
||||
|
||||
this.MessageBus.ApplyFilters(this, filterComponents, eventsList.ToArray());
|
||||
this.MessageBus.ApplyFilters(this, filterComponents, eventsList.ToHashSet());
|
||||
}
|
||||
|
||||
protected virtual void DisposeResources()
|
||||
|
||||
@ -33,10 +33,10 @@ public sealed class MessageBus
|
||||
/// <param name="receiver">That's you, the receiver.</param>
|
||||
/// <param name="filterComponents">A list of components for which you want to receive messages. Use an empty list to receive messages from all components.</param>
|
||||
/// <param name="events">A list of events for which you want to receive messages.</param>
|
||||
public void ApplyFilters(IMessageBusReceiver receiver, ComponentBase[] filterComponents, Event[] events)
|
||||
public void ApplyFilters(IMessageBusReceiver receiver, ComponentBase[] filterComponents, HashSet<Event> events)
|
||||
{
|
||||
this.componentFilters[receiver] = filterComponents;
|
||||
this.componentEvents[receiver] = events;
|
||||
this.componentEvents[receiver] = events.ToArray();
|
||||
}
|
||||
|
||||
public void RegisterComponent(IMessageBusReceiver receiver)
|
||||
|
||||
@ -11,6 +11,6 @@ public static class MessageBusExtensions
|
||||
|
||||
public static void ApplyFilters(this IMessageBusReceiver component, ComponentBase[] components, Event[] events)
|
||||
{
|
||||
MessageBus.INSTANCE.ApplyFilters(component, components, events);
|
||||
MessageBus.INSTANCE.ApplyFilters(component, components, events.ToHashSet());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user