UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

36 lines (35 loc) 1.19 kB
export const PreferenceGroups = ['system', 'map', 'visual']; /** Contains info/config about preference items the user can change in the UserPreferenceComponent. */ export class UserPreference { currentValue = undefined; visible = true; configPath; statePath; group; uiElement; // The setting value in the config can have a different type as in the state, e.g. string vs object. In these cases, // a mapping function is needed to get from the config value to the value in the state. _configToStateMapper; _options = []; constructor(configPath, statePath, group, uiElement, configToStateMapper) { this.configPath = configPath; this.statePath = statePath; this.group = group; this.uiElement = uiElement; this._configToStateMapper = configToStateMapper || ((valueInConfig) => valueInConfig); } get options() { return this._options; } set options(options) { this._options = options; if (this._options.length === 0) { this.visible = false; } } getCurrentValueForState() { return this._configToStateMapper(this.currentValue); } }