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",
|
"name": "pigallery2-extension-kit",
|
||||||
"version": "2.0.3-edge",
|
"version": "2.0.3-edge3",
|
||||||
"description": "Interfaces for developing extensions for pigallery2",
|
"description": "Interfaces for developing extensions for pigallery2",
|
||||||
"author": "Patrik J. Braun",
|
"author": "Patrik J. Braun",
|
||||||
"homepage": "https://github.com/bpatrik/pigallery2",
|
"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 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(args, eventObj);
|
||||||
|
|
||||||
// skip the rest of the execution if the before handler asked for stop propagation
|
// skip the rest of the execution if the before handler asked for stop propagation
|
||||||
if (eventObj.stopPropagation) {
|
if (eventObj.stopPropagation) {
|
||||||
return input as O;
|
return input as O;
|
||||||
}
|
}
|
||||||
const out = await targetMethod.apply(this, args);
|
const out = await targetMethod.apply(this, input);
|
||||||
return await event.triggerAfter(out);
|
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> {
|
public async triggerBefore(input: I, event: { stopPropagation: boolean }): Promise<I | O> {
|
||||||
let pipe: { inputs: I} | O = input;
|
let pipe: I | O = input;
|
||||||
if (this.beforeHandlers && this.beforeHandlers.length > 0) {
|
if (this.beforeHandlers && this.beforeHandlers.length > 0) {
|
||||||
const s = this.beforeHandlers.slice(0);
|
const s = this.beforeHandlers.slice(0);
|
||||||
for (let i = 0; i < s.length; ++i) {
|
for (let i = 0; i < s.length; ++i) {
|
||||||
if (event.stopPropagation) {
|
if (event.stopPropagation) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pipe = await s[i](pipe as { inputs: I }, event);
|
pipe = await s[i](pipe as I, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pipe;
|
return pipe;
|
||||||
|
@ -18,9 +18,7 @@ import {ParentDirectoryDTO} from '../../../common/entities/DirectoryDTO';
|
|||||||
import {DirectoryScanSettings} from '../fileaccess/DiskManager';
|
import {DirectoryScanSettings} from '../fileaccess/DiskManager';
|
||||||
|
|
||||||
|
|
||||||
export type IExtensionBeforeEventHandler<I extends unknown[], O> = (input: { inputs: I }, event: { stopPropagation: boolean }) => Promise<{
|
export type IExtensionBeforeEventHandler<I extends unknown[], O> = (input: I, event: { stopPropagation: boolean }) => Promise<I | O>;
|
||||||
inputs: I
|
|
||||||
} | O>;
|
|
||||||
export type IExtensionAfterEventHandler<O> = (output: O) => Promise<O>;
|
export type IExtensionAfterEventHandler<O> = (output: O) => Promise<O>;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user