Skip to main content

Interface: SettingsExtension<T>

Defined in: src/lib/classes/SettingsExtensions/index.ts:29

Settings a wrapper app adds to PaintCanvas's app settings, under a key of its own (e.g. livecanvas). They're kept, exported and imported with the app settings, wherever those are kept.

Example​

const extension: SettingsExtension<{ sound: boolean }> = {
key: "livecanvas",
validate: (value): value is { sound: boolean } => typeof (value as { sound?: unknown })?.sound === "boolean",
collect: () => ({ sound: mySettings.sound }),
apply: (value) => mySettings.update(value),
target: mySettings, // dispatches `change`
};

Type Parameters​

T​

T = unknown

Properties​

key​

key: string

Defined in: src/lib/classes/SettingsExtensions/index.ts:31

Key of its settings in the app settings (not one of RESERVED_SETTINGS_KEYS)


target?​

optional target?: EventTarget

Defined in: src/lib/classes/SettingsExtensions/index.ts:39

Dispatches change when its settings change, so they're saved

Methods​

apply()​

apply(value): void

Defined in: src/lib/classes/SettingsExtensions/index.ts:37

Use settings read from a store or a file

Parameters​

value​

T

Returns​

void


collect()​

collect(): T

Defined in: src/lib/classes/SettingsExtensions/index.ts:35

Its current settings (JSON-friendly)

Returns​

T


validate()​

validate(value): value is T

Defined in: src/lib/classes/SettingsExtensions/index.ts:33

Whether a value (read from a store or a file, so untrusted) is valid settings for it

Parameters​

value​

unknown

Returns​

value is T