Files
openmaic/OpenMAIC/lib/edit/scene-editor-registry.ts
2026-08-16 14:58:47 +08:00

26 lines
1.1 KiB
TypeScript

import type { SceneType } from '@/lib/types/stage';
import type { SceneEditorRegistry, SceneEditorSurface } from './scene-editor-surface';
const surfaces = new Map<SceneType, SceneEditorSurface>();
export const sceneEditorRegistry: SceneEditorRegistry = {
register: (surface) => {
// Re-registering the same instance is benign (HMR re-executes module init
// and the second pass passes the identical surface object). Only warn when
// a different surface tries to take the slot, since that silently masks
// bugs like accidental double-imports from divergent paths.
const existing = surfaces.get(surface.sceneType);
if (existing && existing !== surface && process.env.NODE_ENV !== 'production') {
console.warn(
`[sceneEditorRegistry] overwriting existing surface for "${surface.sceneType}". ` +
`If this is HMR, call unregister first.`,
);
}
surfaces.set(surface.sceneType, surface as SceneEditorSurface);
},
unregister: (sceneType) => {
surfaces.delete(sceneType);
},
resolve: (sceneType) => surfaces.get(sceneType),
};