mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
EventBus: Fix error in ScopedEventBus (#75349)
This commit is contained in:
parent
f4de29dd87
commit
5a91d00f52
@ -47,7 +47,7 @@ describe('EventBus', () => {
|
||||
expect(events.length).toBe(1);
|
||||
});
|
||||
|
||||
describe('EventBusWithSource', () => {
|
||||
describe('ScopedEventBus', () => {
|
||||
it('can add sources to the source path', () => {
|
||||
const bus = new EventBusSrv();
|
||||
const busWithSource = bus.newScopedBus('foo');
|
||||
@ -56,15 +56,34 @@ describe('EventBus', () => {
|
||||
|
||||
it('adds the source to the event payload', () => {
|
||||
const bus = new EventBusSrv();
|
||||
let events: BusEvent[] = [];
|
||||
const events: BusEvent[] = [];
|
||||
|
||||
bus.subscribe(DataHoverEvent, (event) => events.push(event));
|
||||
|
||||
const busWithSource = bus.newScopedBus('foo');
|
||||
busWithSource.publish({ type: DataHoverEvent.type });
|
||||
const scopedBus = bus.newScopedBus('foo');
|
||||
scopedBus.publish({ type: DataHoverEvent.type });
|
||||
|
||||
expect(events.length).toEqual(1);
|
||||
expect(events[0].origin).toEqual(busWithSource);
|
||||
expect(events[0].origin).toEqual(scopedBus);
|
||||
});
|
||||
|
||||
it('Can subscribe to only local events', () => {
|
||||
const bus = new EventBusSrv();
|
||||
const allEvents: BusEvent[] = [];
|
||||
const scopedEvents: BusEvent[] = [];
|
||||
|
||||
bus.subscribe(DataHoverEvent, (event) => allEvents.push(event));
|
||||
|
||||
const scopedBus1 = bus.newScopedBus('foo', { onlyLocal: true });
|
||||
const scopedBus2 = bus.newScopedBus('foo', { onlyLocal: true });
|
||||
|
||||
scopedBus1.subscribe(DataHoverEvent, (event) => scopedEvents.push(event));
|
||||
|
||||
scopedBus1.publish({ type: DataHoverEvent.type });
|
||||
scopedBus2.publish({ type: DataHoverEvent.type });
|
||||
|
||||
expect(allEvents.length).toEqual(2);
|
||||
expect(scopedEvents.length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -136,7 +136,7 @@ class ScopedEventBus implements EventBus {
|
||||
}
|
||||
|
||||
getStream<T extends BusEvent>(eventType: BusEventType<T>): Observable<T> {
|
||||
return this.eventBus.getStream(eventType).pipe(filter(this.filter));
|
||||
return this.eventBus.getStream(eventType).pipe(filter(this.filter.bind(this)));
|
||||
}
|
||||
|
||||
// syntax sugar
|
||||
|
Loading…
Reference in New Issue
Block a user