import { HoistService, InitContext } from '@xh/hoist/core'; /** * Service to read and set user-specific preference values. * * Server-side preference support is provided by hoist-core. Preferences must be predefined on the * server (they can be managed via the Admin console) and are referenced by their string key. They * are assigned default values that apply to users who have yet to have a value set that is specific * to their account. Once set, however, the user will get their customized value instead of the * default going forwards. * * This could happen via an explicit option the user adjusts, or happen transparently based on a * natural user action or component integration (e.g. collapsing or resizing a `Resizable` that has * been configured with preference support). * * Preferences are persisted automatically back to the server by default so as to follow their user * across workstations. */ export declare class PrefService extends HoistService { telemetryPrefix: string; static instance: PrefService; private _data; private _updates; initAsync(ctx: InitContext): Promise; /** * Check to see if a given preference has been *defined*. */ hasKey(key: string): boolean; /** * Check whether the current user has an explicit value on file for the given preference, vs. * receiving the preference's server-side default value. * * @param key - unique key used to identify the pref. */ isSet(key: string): boolean; /** * Get the value for a given key, either the user-specific value (if set) or the default. * Typically accessed via the convenience alias {@link XH.getPref}. * * @param key - unique key used to identify the pref. * @param defaultValue - value to return if the preference key is not found - i.e. * the config has not been created on the server - instead of throwing. Use sparingly! * In general, it's better to not provide defaults here, but instead keep entries updated * via the Admin client and have it be obvious when one is missing. */ get(key: string, defaultValue?: any): any; /** * Set a preference value for the current user. * Typically accessed via the convenience alias {@link XH.setPref}. * * Values are validated client-side to ensure they (probably) are of the correct data type. * * Values are saved to the server in an asynchronous and debounced manner. * See pushAsync() and pushPendingAsync() */ set(key: string, value: any): void; /** * Restore a preference to its default value, clearing the user's explicit value on the server. * * Unlike `set()`, this clears the user's explicit value rather than persisting the default as * one - so {@link isSet} will report `false` afterwards. Saved asynchronously (see `set()`). */ unset(key: string): void; /** * Set a preference value for the current user, and immediately trigger a sync to the server. * * Useful when important to verify that the preference has been fully round-tripped - e.g. * before making another call that relies on its updated value being read on the server. */ pushAsync(key: string, value: any): Promise; /** * Push any pending buffered updates to persist newly set values to the server. * * Not typically called by applications. Called automatically by the framework after changes * and when page is hidden/terminated. */ pushPendingAsync(): Promise; private pushPendingBuffered; private loadPrefsAsync; private ensureKeyExists; private validateBeforeSet; private valueIsOfType; }