Files
blockly3d/webclient/src/state/debugLabelsState.ts
T

40 lines
1002 B
TypeScript

import { makeAutoObservable } from "mobx";
class DebugLabelsState {
public labels = new Map<string, Record<string, string>>();
constructor() {
makeAutoObservable(this);
}
public getAll(objectId: string): Record<string, string> {
return this.labels.get(objectId) ?? {};
}
public getOne(objectId: string, key: string): string | undefined {
return this.getAll(objectId)[key];
}
public setOne(objectId: string, key: string, text: string) {
if (!this.labels.has(objectId))
this.labels.set(objectId, {});
this.labels.get(objectId)![key] = text;
}
public deleteAll(objectId: string) {
this.labels.delete(objectId);
}
public deleteOne(objectId: string, key: string) {
if (this.labels.has(objectId)) {
delete (this.labels.get(objectId)![key]);
}
}
public clear() {
this.labels.clear();
}
}
export const debugLabelsStore = new DebugLabelsState();