Skip to content

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

MethodReturnsDescription
get<T>(key: string, defaultValue?: T)TRead a value. Returns defaultValue if the path is missing.
set<T>(key: string, value: T)voidWrite a value. Triggers any matching watchers.
merge(config: Partial<any>)voidDeep merge a partial config object.
validate(config: unknown)ValidationResultValidate a candidate config.
getAll()anyThe full current config.
reset()voidClear all config back to an empty object. Notifies watchers of removed values.
watch<T>(key, callback)stringSubscribe to changes at key. Returns a watcher id.
unwatch(watcherId: string)voidRemove 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 unwatch from destroy paths in plugins and services to avoid leaks.
  • merge performs a deep merge. Use set for surgical updates that must trigger a single watcher.

XViewr SDK and xConvert CLI documentation.