forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adder_v0.ts
63 lines (55 loc) · 1.43 KB
/
adder_v0.ts
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import nodes from '$lib/node_register';
import categories from '$lib/node_categories';
import type { BaseData, DGNodeInterface } from '$lib/node_data_types';
export default class AdderNode {
id: string;
data: AdderData;
position: { x: number; y: number };
type: string;
constructor(node_data: AdderNodeInterface) {
const { id, data, position, type } = node_data;
this.id = id;
this.data = data;
this.position = position;
this.type = type;
}
async compute(
inputData: object,
context: string,
info: (arg: string) => void,
error: (arg: string) => void,
success: (arg: string) => void,
slug: string,
Cookies: any
) {
const a = inputData['a'] || inputData[this.data.input_ids.a];
const b = inputData['b'] || inputData[this.data.input_ids.b];
return a + b;
}
}
interface AdderData extends BaseData {
output: Record<string, any>;
value: number;
}
type AdderNodeInterface = DGNodeInterface & {
data: AdderData;
};
export const adder_node_data: AdderNodeInterface = {
id: 'adder_v0',
data: {
label: 'adder_v0',
compute_type: 'adder_v0',
input_ids: { a: '', b: '' },
category: categories.wip.id,
icon: 'adder_v0',
show_in_ui: true,
message: '',
output: {},
dirty: false,
value: 0
},
position: { x: 0, y: 0 },
type: 'default_v0'
};
export const adder_node = new AdderNode(adder_node_data);
nodes.register(AdderNode, adder_node_data);