diff --git a/src/Events.ts b/src/Events.ts index 231d099..dd1eded 100644 --- a/src/Events.ts +++ b/src/Events.ts @@ -49,11 +49,11 @@ export function omitEvents< export function createEventBus(args: { events: C channels?: Channel[] - blackList?: Array + ignoredEvents?: Array }): C { const transports = (args.channels || []).map( - (c) => new Transport(c, (args.blackList as string[])) + (c) => new Transport(c, (args.ignoredEvents as string[])) ) const eventBus: Partial = {} diff --git a/src/Message.ts b/src/Message.ts index ffb086e..a3a512d 100644 --- a/src/Message.ts +++ b/src/Message.ts @@ -37,7 +37,7 @@ export type TransportUnregistrationMessage = { export type TransportEventListMessage = { type: 'event_list', - blackList: string[] + ignoredEvents: string[] } export type TransportMessage = diff --git a/src/Transport.ts b/src/Transport.ts index f75d24b..4702f80 100644 --- a/src/Transport.ts +++ b/src/Transport.ts @@ -79,7 +79,7 @@ export class Transport { * Callbacks provided by each slot allowing to remove blacklisted events * declaration from the remote handlers. */ - private _remoteEventListChangedCallbacks: + private _remoteIgnoredEventsCallbacks: { [slotName: string]: () => void } = {} /** @@ -89,7 +89,7 @@ export class Transport { private _channelReady = false - constructor(private _channel: Channel, blackList?: string[]) { + constructor(private _channel: Channel, ignoredEvents?: string[]) { this._channel.onData((message: TransportMessage) => { switch (message.type) { case 'request': @@ -103,7 +103,7 @@ export class Transport { case 'error': return this._errorReceived(message) case 'event_list': - return this._remoteEventListReceived(message) + return this._remoteIgnoredEventsReceived(message) default: assertNever(message) } @@ -118,15 +118,14 @@ export class Transport { }) }) - // Also send the list of events this end is interested in so the far - // end can know when to wait for this end to be ready when triggering - // a specific slot, and when NOT to wait. - // This is necessary only when some events have been blacklisted - // when calling createEventBus - if (blackList) { + // Also send the list of events this end is not interested in so the + // far end can know when to wait or not for this end to be ready + // when triggering a specific slot. This is necessary only when some + // events have been listed as ignored when calling createEventBus + if (ignoredEvents) { this._channel.send({ type: "event_list", - blackList + ignoredEvents }) } }) @@ -145,18 +144,18 @@ export class Transport { } /** - * This event is triggered when events have been blacklisted from the far - * end. It will call onRegister on blacklisted handlers to fake their - * registration so this end doesn't wait on the far end have registered them - * to be able to trigger them. + * This event is triggered when events have been listed as ignored by the far + * end. It will call onRegister on ignored events' handlers to fake their + * registration so this end doesn't wait on the far end to have registered + * them to be able to trigger them. */ - private _remoteEventListReceived({ - blackList + private _remoteIgnoredEventsReceived({ + ignoredEvents }: TransportEventListMessage): void { - Object.keys(this._remoteEventListChangedCallbacks).forEach( + Object.keys(this._remoteIgnoredEventsCallbacks).forEach( (slotName) => { - if (blackList.includes(slotName)) { - this._remoteEventListChangedCallbacks[slotName]() + if (ignoredEvents.includes(slotName)) { + this._remoteIgnoredEventsCallbacks[slotName]() } } ) @@ -342,8 +341,8 @@ export class Transport { slotName: string, eventListChangedListener: () => void ): void { - if (!this._remoteEventListChangedCallbacks[slotName]) { - this._remoteEventListChangedCallbacks[slotName] = + if (!this._remoteIgnoredEventsCallbacks[slotName]) { + this._remoteIgnoredEventsCallbacks[slotName] = eventListChangedListener } } diff --git a/test/Slot.spec.ts b/test/Slot.spec.ts index 583fbcb..85c8fed 100644 --- a/test/Slot.spec.ts +++ b/test/Slot.spec.ts @@ -320,7 +320,7 @@ describe('connectSlot', () => { }) describe('with two remote endpoints: A and B', () => { - describe('no event list sent by any endpoints', () => { + describe('no ignoredEvents list sent by any endpoints', () => { it('should wait for all remote endpoints to have signaled registration before sending the event', async () => { const { channel: channelA, transport: transportA } = makeTestTransport() @@ -385,7 +385,7 @@ describe('connectSlot', () => { }) }) - describe('a blacklist is sent to one endpoint (A)', () => { + describe('an ignoredEvents list is sent to one endpoint (A)', () => { it('should NOT wait for remote endpoint A but SHOULD wait on remote endpoint B to have signaled registration before sending the event', async () => { const { channel: channelA, transport: transportA } = makeTestTransport() @@ -397,10 +397,10 @@ describe('connectSlot', () => { transportB, ]) - // Receiving a black list of events + // Receiving a list of events to ignore channelA.fakeReceive({ type: 'event_list', - blackList: ['broadcastBool'], + ignoredEvents: ['broadcastBool'], }) // This will be called only when B is ready we don't care about @@ -429,10 +429,10 @@ describe('connectSlot', () => { }) }) - describe('an empty blacklist is sent to one endpoint (A)', () => { + describe('an empty ignoredEvents list is sent to one endpoint (A)', () => { // This is the same test as before. But this time the because the - // blackList is empty, we need to wait for A AND B to be registered - // to trigger the event + // ignoredEvents list is empty, we need to wait for A AND B to been + // registered to trigger the event. it('should wait for remote endpoint A and remote endpoint B to have signaled registration before sending the event', async () => { const { channel: channelA, transport: transportA } = makeTestTransport() @@ -452,7 +452,7 @@ describe('connectSlot', () => { channelA.fakeReceive({ type: 'event_list', - blackList: [], + ignoredEvents: [], }) broadcastBool(true)