forked from lowcoder-org/lowcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionNode.tsx
More file actions
46 lines (38 loc) · 1.37 KB
/
Copy pathfunctionNode.tsx
File metadata and controls
46 lines (38 loc) · 1.37 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { memoized } from "../util/memoize";
import { AbstractNode, FetchInfoOptions, Node } from "./node";
import { EvalMethods } from "./types/evalTypes";
import { evalPerfUtil } from "./utils/perfUtils";
/**
* return a new node, evaluating to a function result with the input node value as the function's input
*/
export class FunctionNode<T, OutputType> extends AbstractNode<OutputType> {
readonly type = "function";
constructor(readonly child: Node<T>, readonly func: (params: T) => OutputType) {
super();
}
@memoized()
override filterNodes(exposingNodes: Record<string, Node<unknown>>) {
return evalPerfUtil.perf(this, "filterNodes", () => {
return this.child.filterNodes(exposingNodes);
});
}
override justEval(
exposingNodes: Record<string, Node<unknown>>,
methods?: EvalMethods
): OutputType {
return this.func(this.child.evaluate(exposingNodes, methods));
}
override getChildren(): Node<unknown>[] {
return [this.child];
}
override dependValues(): Record<string, unknown> {
return this.child.dependValues();
}
@memoized()
override fetchInfo(exposingNodes: Record<string, Node<unknown>>, options?: FetchInfoOptions) {
return this.child.fetchInfo(exposingNodes, options);
}
}
export function withFunction<T, OutputType>(child: Node<T>, func: (params: T) => OutputType) {
return new FunctionNode(child, func);
}