-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmemento.ts
43 lines (38 loc) · 931 Bytes
/
memento.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
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Stores an array of objects that can be serialized and passed
* between a web worker and the main thread.
*/
export class Memento {
/**
* The objects stored in the memento.
*/
public readonly objects: any[] = [];
/**
* The index of the next object to return.
*/
private getIndex: number = 0;
/**
* Creates a new instance of the Memento class.
* @param objects The objects to store in the memento.
*/
public constructor(objects?: any[]) {
if (objects) {
this.objects = objects;
}
}
/**
* Adds an object to the memento.
* @param object The object to add.
*/
public add(object: any): void {
this.objects.push(object);
}
/**
* Returns the next object from the memento.
* @returns The next object from the memento.
*/
public get(): any {
return this.objects[this.getIndex++];
}
}