Skip to content

Commit

Permalink
Update extension types #743
Browse files Browse the repository at this point in the history
  • Loading branch information
bpatrik committed Nov 26, 2023
1 parent a0d4d7f commit 4be86d6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/backend/model/extension/ExtensionDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
6 changes: 3 additions & 3 deletions src/backend/model/extension/ExtensionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/backend/model/extension/IExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;


Expand Down

0 comments on commit 4be86d6

Please sign in to comment.