Appearance
ConfigManager
Hierarchical configuration store for the viewer. Accessible as viewer.configManager. Backed by the XViewerConfig passed to the constructor.
Usage
ts
const fov = viewer.configManager.get<number>("viewer.camera.fov", 75);
viewer.configManager.set("rendering.toneMappingExposure", 1.2);
viewer.configManager.merge({ rendering: { antialias: false } });
const watcherId = viewer.configManager.watch<number>(
"rendering.toneMappingExposure",
(newValue, oldValue, key) => {
console.log(key, oldValue, "->", newValue);
}
);
viewer.configManager.unwatch(watcherId);Keys are dot-separated paths. viewer.updateConfig(partial) is a shortcut for merge.
IConfigManager
| Method | Returns | Description |
|---|---|---|
get<T>(key: string, defaultValue?: T) | T | Read a value. Returns defaultValue if the path is missing. |
set<T>(key: string, value: T) | void | Write a value. Triggers any matching watchers. |
merge(config: Partial<any>) | void | Deep merge a partial config object. |
validate(config: unknown) | ValidationResult | Validate a candidate config. |
getAll() | any | The full current config. |
reset() | void | Clear all config back to an empty object. Notifies watchers of removed values. |
watch<T>(key, callback) | string | Subscribe to changes at key. Returns a watcher id. |
unwatch(watcherId: string) | void | Remove a watcher. |
ValidationResult
ts
interface ValidationResult {
isValid: boolean;
errors: ValidationError[];
}
interface ValidationError {
path: string;
message: string;
value: any;
}ConfigWatcher
ts
type ConfigWatcher<T = any> = (newValue: T, oldValue: T, key: string) => void;Watchers fire when the value at the watched key changes. key is the watched path.
Notes
- Always
unwatchfromdestroypaths in plugins and services to avoid leaks. mergeperforms a deep merge. Usesetfor surgical updates that must trigger a single watcher.