diff --git a/main/contracts/contracts.ts b/main/contracts/contracts.ts index 3f8ff75..485a580 100644 --- a/main/contracts/contracts.ts +++ b/main/contracts/contracts.ts @@ -68,7 +68,7 @@ export interface IMessageBroker { /** * A list of all child scopes that have been created on this instance of the broker. */ - readonly scopes: IMessageBroker[]; + readonly children: IMessageBroker[]; /** * Creates a new channel with the provided channelName. An optional config object can be passed that specifies how many messages to cache. diff --git a/main/core/messagebroker.ts b/main/core/messagebroker.ts index 37034a1..3550c1f 100644 --- a/main/core/messagebroker.ts +++ b/main/core/messagebroker.ts @@ -36,7 +36,7 @@ export function messagebroker(): IMessageBroker { export class MessageBroker implements IMessageBroker { private channelLookup: ChannelModelLookup = {}; private messagePublisher = new Subject>(); - private _scopes: { + private _children: { name: string; instance: IMessageBroker; }[] = []; @@ -96,7 +96,7 @@ export class MessageBroker implements IMessageBroker { * @param channelName Name of the messagebroker channel */ public dispose(channelName: K): void { - this._scopes.forEach((scope) => scope.instance.dispose(channelName)); + this._children.forEach((scope) => scope.instance.dispose(channelName)); const channel = this.channelLookup[channelName]; if (this.isChannelConfiguredWithCaching(channel)) { channel.subscription.unsubscribe(); @@ -111,13 +111,13 @@ export class MessageBroker implements IMessageBroker { * @returns An instance of the messagebroker that matches the scopeName provided */ public createScope(scopeName: string): IMessageBroker { - const existingScope = this._scopes.find((scope) => scope.name === scopeName); + const existingScope = this._children.find((scope) => scope.name === scopeName); if (existingScope) { return existingScope.instance; } const instance = new MessageBroker(this.rsvpMediator, this); - this._scopes.push({ + this._children.push({ name: scopeName, instance, }); @@ -168,7 +168,7 @@ export class MessageBroker implements IMessageBroker { } const publishFunction = (data?: T[K], type?: string): void => { - this._scopes.forEach((scope) => scope.instance.create(channelName).publish(data), type); + this._children.forEach((scope) => scope.instance.create(channelName).publish(data), type); this.messagePublisher.next(this.createMessage(channelName, data, type)); }; @@ -211,7 +211,7 @@ export class MessageBroker implements IMessageBroker { return this._parent; } - public get scopes(): IMessageBroker[] { - return this._scopes.map((scope) => scope.instance); + public get children(): IMessageBroker[] { + return this._children.map((scope) => scope.instance); } } diff --git a/spec/core/messagebroker.spec.ts b/spec/core/messagebroker.spec.ts index 27005fb..ab4c13e 100644 --- a/spec/core/messagebroker.spec.ts +++ b/spec/core/messagebroker.spec.ts @@ -409,7 +409,7 @@ describe('MessageBroker', () => { const scope2 = instance.createScope('scope2'); const scope3 = instance.createScope('scope3'); - expect(instance.scopes).toEqual([scope1, scope2, scope3]); + expect(instance.children).toEqual([scope1, scope2, scope3]); }); it('should publish messages from parent to children', () => {