Skip to content

Commit

Permalink
chore: renamed the blackList ignoredEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienGranger committed Jul 22, 2022
1 parent 3f3843b commit 2b86a22
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export function omitEvents<
export function createEventBus<C extends EventDeclaration>(args: {
events: C
channels?: Channel[]
blackList?: Array<keyof C>
ignoredEvents?: Array<keyof C>
}): 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<C> = {}
Expand Down
2 changes: 1 addition & 1 deletion src/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type TransportUnregistrationMessage = {

export type TransportEventListMessage = {
type: 'event_list',
blackList: string[]
ignoredEvents: string[]
}

export type TransportMessage =
Expand Down
41 changes: 20 additions & 21 deletions src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {}

/**
Expand All @@ -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':
Expand All @@ -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)
}
Expand All @@ -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
})
}
})
Expand All @@ -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]()
}
}
)
Expand Down Expand Up @@ -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
}
}
Expand Down
16 changes: 8 additions & 8 deletions test/Slot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -452,7 +452,7 @@ describe('connectSlot', () => {

channelA.fakeReceive({
type: 'event_list',
blackList: [],
ignoredEvents: [],
})

broadcastBool(true)
Expand Down

0 comments on commit 2b86a22

Please sign in to comment.