name:
src/main/js/models/nodes/ListNode.ts
-rw-r--r--
625
1import { Grid } from "../common/Grid";
2import { Node } from "./Node";
3import { NodeType } from "./NodeType";
4
5/**
6 * Node that is a literal list of nodes, possibly other list nodes.
7 */
8export class ListNode extends Object implements Node {
9 readonly type: NodeType = NodeType.List;
10 readonly grid: Grid<Node>;
11
12 constructor(grid?: Grid<Node>) {
13 super();
14 this.grid = grid ? grid : new Grid<Node>(0, 0);
15 }
16
17 isEmpty(): boolean {
18 return this.grid.isEmpty();
19 }
20
21 toString() {
22 return `{${this.grid
23 .raw()
24 .map((row) => row.map((node) => node.toString()).join(","))
25 .join(";")}}`;
26 }
27}