aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/ChangeList.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/utils/ChangeList.ts b/src/utils/ChangeList.ts
new file mode 100644
index 0000000..d8f7449
--- /dev/null
+++ b/src/utils/ChangeList.ts
@@ -0,0 +1,24 @@
+export class ChangeList<T>{
+ private set = new Set<T>;
+
+ public get changeCount() {
+ return this.set.size;
+ }
+
+ public get hasChanges() {
+ return this.changeCount > 0;
+ }
+
+ public handleChange(item: T) {
+ if (!this.set.delete(item))
+ this.set.add(item);
+ }
+
+ public getChanges() {
+ return this.set.values();
+ }
+
+ public map<R>(mapper: (v: T, idx: number, arr: T[]) => R): R[] {
+ return [...this.getChanges()].map(mapper);
+ }
+}