persist
persist
Table of contents
Classes
Decorators
Options
Decorators
persist
▸ persist<T
>(options?
): (target
: any
, prop
: any
) => void
Sync class property with persistent storage (LocalStorage by default)
Type parameters
Parameters
Returns
fn
Decorator function
▸ (target
, prop
): void
Parameters
Name |
Type |
target |
any |
prop |
any |
Returns
void
Example
class ThemeEngine {
@persist({default: 'os'}) current!: string;
}
const theme = new ThemeEngine();
console.log(theme.current) // Output: os
theme.current = 'light'; //Any changes will be automatically saved to localStorage
location.reload(); // Simulate refresh
console.log(theme.current) // Output: light
Defined in
persist.ts:135
Options
PersistOptions
Ƭ PersistOptions<T
>: Object
Configurations persistence behaviour
Type parameters
Type declaration
Name |
Type |
Description |
default? |
T |
Default/Initial value if undefined |
storage? |
Storage |
Storage implementation, defaults to LocalStorage |
type? |
any |
Force value to have prototype |
Defined in
persist.ts:6