mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-15 00:45:04 +01:00
avoid wasm symbol conflicts
This commit is contained in:
parent
6bdbf14ecb
commit
e951cd5ee1
8 changed files with 188 additions and 99 deletions
23
src/utils.ts
23
src/utils.ts
|
|
@ -16,3 +16,26 @@ export function unwrap<T>(value: T | undefined): T {
|
|||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* A `Map` that can have arbitrarily complex keys.
|
||||
* It uses JSON+string equality instead of refernece equality.
|
||||
*/
|
||||
export class ComplexMap<K, V> {
|
||||
inner: Map<string | number, V> = new Map();
|
||||
|
||||
public get(key: K): V | undefined {
|
||||
return this.inner.get(this.mangleKey(key));
|
||||
}
|
||||
|
||||
public set(key: K, value: V) {
|
||||
this.inner.set(this.mangleKey(key), value);
|
||||
}
|
||||
|
||||
private mangleKey(key: K): string | number {
|
||||
if (typeof key === "string" || typeof key === "number") {
|
||||
return key;
|
||||
}
|
||||
return JSON.stringify(key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue