mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
Update extension types #743
This commit is contained in:
parent
a0d4d7f246
commit
4be86d6ebc
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pigallery2-extension-kit",
|
||||
"version": "2.0.3-edge",
|
||||
"version": "2.0.3-edge3",
|
||||
"description": "Interfaces for developing extensions for pigallery2",
|
||||
"author": "Patrik J. Braun",
|
||||
"homepage": "https://github.com/bpatrik/pigallery2",
|
||||
|
@ -25,13 +25,13 @@ export const ExtensionDecorator = <I extends unknown[], O>(fn: (ee: IExtensionEv
|
||||
|
||||
const event = fn(ExtensionDecoratorObject.events) as ExtensionEvent<I, O>;
|
||||
const eventObj = {stopPropagation: false};
|
||||
const input = await event.triggerBefore({inputs: args}, eventObj);
|
||||
const input = await event.triggerBefore(args, eventObj);
|
||||
|
||||
// skip the rest of the execution if the before handler asked for stop propagation
|
||||
if (eventObj.stopPropagation) {
|
||||
return input as O;
|
||||
}
|
||||
const out = await targetMethod.apply(this, args);
|
||||
const out = await targetMethod.apply(this, input);
|
||||
return await event.triggerAfter(out);
|
||||
};
|
||||
|
||||
|
@ -27,15 +27,15 @@ export class ExtensionEvent<I extends unknown[], O> implements IExtensionEvent<I
|
||||
}
|
||||
|
||||
|
||||
public async triggerBefore(input: { inputs: I }, event: { stopPropagation: boolean }): Promise<{ inputs: I } | O> {
|
||||
let pipe: { inputs: I} | O = input;
|
||||
public async triggerBefore(input: I, event: { stopPropagation: boolean }): Promise<I | O> {
|
||||
let pipe: I | O = input;
|
||||
if (this.beforeHandlers && this.beforeHandlers.length > 0) {
|
||||
const s = this.beforeHandlers.slice(0);
|
||||
for (let i = 0; i < s.length; ++i) {
|
||||
if (event.stopPropagation) {
|
||||
break;
|
||||
}
|
||||
pipe = await s[i](pipe as { inputs: I }, event);
|
||||
pipe = await s[i](pipe as I, event);
|
||||
}
|
||||
}
|
||||
return pipe;
|
||||
|
@ -18,9 +18,7 @@ import {ParentDirectoryDTO} from '../../../common/entities/DirectoryDTO';
|
||||
import {DirectoryScanSettings} from '../fileaccess/DiskManager';
|
||||
|
||||
|
||||
export type IExtensionBeforeEventHandler<I extends unknown[], O> = (input: { inputs: I }, event: { stopPropagation: boolean }) => Promise<{
|
||||
inputs: I
|
||||
} | O>;
|
||||
export type IExtensionBeforeEventHandler<I extends unknown[], O> = (input: I, event: { stopPropagation: boolean }) => Promise<I | O>;
|
||||
export type IExtensionAfterEventHandler<O> = (output: O) => Promise<O>;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user