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:
parent
ee8a942e5c
commit
3cf45c56b5
@ -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);
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user