Skip to content

Commit

Permalink
renamed scopes to children
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanm3341 committed Nov 13, 2024
1 parent 75fe872 commit 0389a8b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion main/contracts/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface IMessageBroker<T> {
/**
* A list of all child scopes that have been created on this instance of the broker.
*/
readonly scopes: IMessageBroker<T>[];
readonly children: IMessageBroker<T>[];

/**
* Creates a new channel with the provided channelName. An optional config object can be passed that specifies how many messages to cache.
Expand Down
14 changes: 7 additions & 7 deletions main/core/messagebroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function messagebroker<T = any>(): IMessageBroker<T> {
export class MessageBroker<T = any> implements IMessageBroker<T> {
private channelLookup: ChannelModelLookup<T> = {};
private messagePublisher = new Subject<IMessage<any>>();
private _scopes: {
private _children: {
name: string;
instance: IMessageBroker<T>;
}[] = [];
Expand Down Expand Up @@ -96,7 +96,7 @@ export class MessageBroker<T = any> implements IMessageBroker<T> {
* @param channelName Name of the messagebroker channel
*/
public dispose<K extends keyof T>(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();
Expand All @@ -111,13 +111,13 @@ export class MessageBroker<T = any> implements IMessageBroker<T> {
* @returns An instance of the messagebroker that matches the scopeName provided
*/
public createScope(scopeName: string): IMessageBroker<T> {
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<T>(this.rsvpMediator, this);
this._scopes.push({
this._children.push({
name: scopeName,
instance,
});
Expand Down Expand Up @@ -168,7 +168,7 @@ export class MessageBroker<T = any> implements IMessageBroker<T> {
}

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));
};

Expand Down Expand Up @@ -211,7 +211,7 @@ export class MessageBroker<T = any> implements IMessageBroker<T> {
return this._parent;
}

public get scopes(): IMessageBroker<T>[] {
return this._scopes.map((scope) => scope.instance);
public get children(): IMessageBroker<T>[] {
return this._children.map((scope) => scope.instance);
}
}
2 changes: 1 addition & 1 deletion spec/core/messagebroker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 0389a8b

Please sign in to comment.