@itwin/core-react
Version:
A react component library of iTwin.js UI general purpose components
63 lines • 2.83 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module UiStateStorage
*/
import { UiStateStorageStatus } from "./UiStateStorage.js";
/* eslint-disable @typescript-eslint/no-deprecated */
/** A single UI State entry that is identified by namespace and setting name.
* @public
* @deprecated in 4.16.0. Use {@link UiStateStorage} APIs instead.
*/
export class UiStateEntry {
settingNamespace;
settingName;
getValue;
applyValue;
defaultValue;
/** Constructor
* @param settingNamespace Namespace for the setting, passed to UiStateStorage.
* @param settingName Name for the setting, passed to UiStateStorage.
* @param getValue Function for getting the value from the application.
* @param applyValue Function for applying the setting value to the application.
* @param defaultValue Optional default value if not already stored.
*/
constructor(settingNamespace, settingName, getValue, applyValue, defaultValue) {
this.settingNamespace = settingNamespace;
this.settingName = settingName;
this.getValue = getValue;
this.applyValue = applyValue;
this.defaultValue = defaultValue;
}
/** Gets the setting from [[UiStateStorage]] */
async getSetting(storage) {
return storage.getSetting(this.settingNamespace, this.settingName);
}
/** Saves the setting value from the `getValue` function to UiStateStorage */
async saveSetting(storage) {
return storage.saveSetting(this.settingNamespace, this.settingName, this.getValue());
}
/** Deletes the setting from UiStateStorage */
async deleteSetting(storage) {
return storage.deleteSetting(this.settingNamespace, this.settingName);
}
/** Gets the setting from UiStateStorage and applies the value using the `applyValue` function */
async getSettingAndApplyValue(storage) {
if (this.applyValue) {
const result = await this.getSetting(storage);
if (result.status === UiStateStorageStatus.Success) {
this.applyValue(result.setting);
}
else if (undefined !== this.defaultValue) {
this.applyValue(this.defaultValue);
result.setting = this.defaultValue;
result.status = UiStateStorageStatus.Success;
}
return result;
}
return { status: UiStateStorageStatus.Uninitialized };
}
}
//# sourceMappingURL=UiStateEntry.js.map