1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Removing circular dependency from extensions #753

This commit is contained in:
Patrik J. Braun 2023-11-17 22:22:13 +01:00
parent ee8a942e5c
commit 3cf45c56b5
2 changed files with 13 additions and 3 deletions

View File

@ -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,
@ -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);

View File

@ -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]';
@ -57,6 +58,7 @@ export class ExtensionManager implements IObjectManager {
}
}
};
ExtensionDecoratorObject.init(this.events);
}
public loadExtensionsList() {