CODEBASE: Add Jsonable Map and Set types, move player.sourceFiles to a map (#473)

This commit is contained in:
Snarling
2023-04-18 03:19:45 -04:00
committed by GitHub
parent c44bdc1018
commit 0df984eea0
55 changed files with 439 additions and 532 deletions
+20
View File
@@ -0,0 +1,20 @@
import type { IReviverValue } from "../utils/JSONReviver";
// Jsonable versions of builtin JS class objects
export class JSONSet<T> extends Set<T> {
toJSON(): IReviverValue {
return { ctor: "JSONSet", data: Array.from(this) };
}
static fromJSON(value: IReviverValue): JSONSet<any> {
return new JSONSet(value.data);
}
}
export class JSONMap<K, V> extends Map<K, V> {
toJSON(): IReviverValue {
return { ctor: "JSONMap", data: Array.from(this) };
}
static fromJSON(value: IReviverValue): JSONMap<any, any> {
return new JSONMap(value.data);
}
}