summaryrefslogtreecommitdiff
path: root/apps/web/src/services/renderer/nodes/base-node.ts
blob: 1d6fc0e496e9cf8354aa64d69e3553a73dc3bd44 (plain) (blame)
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
export type BaseNodeParams = object | undefined;
export type AnyBaseNode = BaseNode<BaseNodeParams, unknown>;

export class BaseNode<
	Params extends BaseNodeParams = BaseNodeParams,
	Resolved = unknown,
> {
	params: Params;
	resolved: Resolved | null = null;

	constructor(params?: Params) {
		this.params = params ?? ({} as Params);
	}

	children: AnyBaseNode[] = [];

	add(child: AnyBaseNode) {
		this.children.push(child);
		return this;
	}

	remove(child: AnyBaseNode) {
		this.children = this.children.filter((c) => c !== child);
		return this;
	}
}