SettingsManager
SettingsManager is a UI-agnostic helper for tracking settings snapshots,
emitting structured change descriptors, and persisting descriptor-backed values
to local storage.
Import
import {
getChangedSetting,
getSettingDefinitions,
SettingsManager,
settingsManager,
type SettingsChangeDescriptor,
type SettingsManagerOnChange
} from '@deck.gl-community/panels';
Usage
const manager = new SettingsManager();
manager.setSettingDefinitions(getSettingDefinitions(schema));
manager.setCurrentSettings(settings);
manager.setOnSettingsChange((nextSettings, changedSettings) => {
const opacityChange = getChangedSetting(changedSettings, 'render.opacity');
console.log(nextSettings, opacityChange?.nextValue);
});
manager.setSettingValue('render.opacity', 0.5);
Persistence
manager.setLocalStoragePersistence({
storageKey: 'my-settings'
});
Settings persist to local storage by default. Set persist: 'url' or
persist: 'none' on a setting descriptor when a value should not be written by
the local-storage persistence path.
Remarks
setSettingValueresolves values through the registered descriptor before emitting changes.getSettingDefinitionsindexes schema descriptors forsetSettingDefinitions.getChangedSettingreturns the change descriptor for one setting name from an emitted change list.setSettingsaccepts a full settings snapshot and emits one descriptor per known value that changed.getSettingsWithLocalStorageoverlays stored values onto a caller-provided settings snapshot.