1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-23 01:27:14 +02: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 {IExtensionEvent, IExtensionEvents} from './IExtension';
import {ObjectManagers} from '../ObjectManagers';
import {ExtensionEvent} from './ExtensionEvent'; 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>) => { export const ExtensionDecorator = <I extends [], O>(fn: (ee: IExtensionEvents) => IExtensionEvent<I, O>) => {
return ( return (
target: unknown, target: unknown,
@ -11,11 +19,11 @@ export const ExtensionDecorator = <I extends [], O>(fn: (ee: IExtensionEvents) =
const targetMethod = descriptor.value; const targetMethod = descriptor.value;
descriptor.value = async function(...args: I) { descriptor.value = async function(...args: I) {
if (!ObjectManagers.isReady()) { if (!ExtensionDecoratorObject.events) {
return await targetMethod.apply(this, args); 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 eventObj = {stopPropagation: false};
const input = await event.triggerBefore({inputs: args}, eventObj); const input = await event.triggerBefore({inputs: args}, eventObj);

View File

@ -10,6 +10,7 @@ import {ExtensionEvent} from './ExtensionEvent';
import * as express from 'express'; import * as express from 'express';
import {SQLConnection} from '../database/SQLConnection'; import {SQLConnection} from '../database/SQLConnection';
import {ExtensionObject} from './ExtensionObject'; import {ExtensionObject} from './ExtensionObject';
import {ExtensionDecoratorObject} from './ExtensionDecorator';
const LOG_TAG = '[ExtensionManager]'; const LOG_TAG = '[ExtensionManager]';
@ -57,6 +58,7 @@ export class ExtensionManager implements IObjectManager {
} }
} }
}; };
ExtensionDecoratorObject.init(this.events);
} }
public loadExtensionsList() { public loadExtensionsList() {