UserOptions
UserOptions — a class for managing personal options of the current user. Singleton instance is available after Frame initialization.
User options do not override application-wide option values.
ts
import { UserOptions } from '@aspro-cloud/miniapp-jssdk'Methods
getInstance
Returns the current singleton instance of UserOptions. Call only after Frame initialization
ts
static getInstance(): UserOptionsdestroy
Removes subscriptions and releases resources
ts
destroy(): voidget
Returns all options (OptionsValues) or a single option value (OptionValue) by identifier
ts
async get(): Promise<OptionsValues>ts
async get(optionId: string): Promise<OptionValue>| Parameter | Type | Description |
|---|---|---|
optionId | string | Option identifier |
set
Saves multiple options at once or a single option value by identifier
ts
async set(values: OptionsValues): Promise<OptionsValues>| Parameter | Type | Description |
|---|---|---|
values | OptionsValues | Object with options to save multiple values |
ts
async set(optionId: string, value: OptionValue): Promise<OptionValue>| Parameter | Type | Description |
|---|---|---|
optionId | string | Option identifier |
value | OptionValue | Option value |
Example
ts
import { App, UserOptions } from '@aspro-cloud/miniapp-jssdk'
await App.initializeFrame()
const userOptions = UserOptions.getInstance()
// get user option value
const theme = await userOptions.get('theme')
// save an option value
await userOptions.set('theme', 'dark')
// save multiple option values
await userOptions.set({
theme: 'dark',
compact: true
})js
const App = window.ACloudMiniApp
const frame = await App.initializeFrame()
// get user option value
const theme = await frame.userOptions.get('theme');
// save an option value
await frame.userOptions.set('theme', 'dark');
// save multiple option values
await frame.userOptions.set({
theme: 'dark',
compact: true
});