forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaopHelper.ts
More file actions
27 lines (24 loc) · 718 Bytes
/
aopHelper.ts
File metadata and controls
27 lines (24 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { BaseGenerator, IScope } from '../types/core';
export function executeFunctionStack<I, T, C>(
input: I,
scope: IScope,
funcs: BaseGenerator<I, T, C> | Array<BaseGenerator<I, T, C>>,
baseFunc: BaseGenerator<I, T, C>,
config?: C,
): T {
const funcList: Array<BaseGenerator<I, T, C>> = [];
if (Array.isArray(funcs)) {
funcList.push(...funcs);
} else {
funcList.push(funcs);
}
let next: BaseGenerator<I, T, C> = baseFunc;
while (funcList.length > 0) {
const func = funcList.pop();
if (func) {
const warppedFunc = ((nextFunc) => (i: I, s: IScope, cfg?: C) => func(i, s, cfg, nextFunc))(next);
next = warppedFunc;
}
}
return next(input, scope, config);
}