Skip to content

Commit

Permalink
Removing circular dependency from extensions #753
Browse files Browse the repository at this point in the history
  • Loading branch information
bpatrik committed Nov 17, 2023
1 parent ee8a942 commit 3cf45c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/backend/model/extension/ExtensionDecorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import {IExtensionEvent, IExtensionEvents} from './IExtension';
import {ObjectManagers} from '../ObjectManagers';
import {ExtensionEvent} from './ExtensionEvent';

export class ExtensionDecoratorObject {
public static events: IExtensionEvents;

static init(events: IExtensionEvents) {
this.events = events;
}

}

export const ExtensionDecorator = <I extends [], O>(fn: (ee: IExtensionEvents) => IExtensionEvent<I, O>) => {
return (
target: unknown,
Expand All @@ -11,11 +19,11 @@ export const ExtensionDecorator = <I extends [], O>(fn: (ee: IExtensionEvents) =

const targetMethod = descriptor.value;
descriptor.value = async function(...args: I) {
if (!ObjectManagers.isReady()) {
if (!ExtensionDecoratorObject.events) {
return await targetMethod.apply(this, args);
}

const event = fn(ObjectManagers.getInstance().ExtensionManager.events) as ExtensionEvent<I, O>;
const event = fn(ExtensionDecoratorObject.events) as ExtensionEvent<I, O>;
const eventObj = {stopPropagation: false};
const input = await event.triggerBefore({inputs: args}, eventObj);

Expand Down
2 changes: 2 additions & 0 deletions src/backend/model/extension/ExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {ExtensionEvent} from './ExtensionEvent';
import * as express from 'express';
import {SQLConnection} from '../database/SQLConnection';
import {ExtensionObject} from './ExtensionObject';
import {ExtensionDecoratorObject} from './ExtensionDecorator';

const LOG_TAG = '[ExtensionManager]';

Expand Down Expand Up @@ -57,6 +58,7 @@ export class ExtensionManager implements IObjectManager {
}
}
};
ExtensionDecoratorObject.init(this.events);
}

public loadExtensionsList() {
Expand Down

0 comments on commit 3cf45c5

Please sign in to comment.