Sync variable's value with persistent storage (LocalStorage by default)
const theme = new Persist('theme.current', {default: 'os'});console.log(theme.value); // Output: ostheme.value = 'light'; // Any changes to `.value` will automatically sync with localStoragelocation.reload(); // Simulate refreshconsole.log(theme.value); // Output: light Copy
const theme = new Persist('theme.current', {default: 'os'});console.log(theme.value); // Output: ostheme.value = 'light'; // Any changes to `.value` will automatically sync with localStoragelocation.reload(); // Simulate refreshconsole.log(theme.value); // Output: light
Primary key value will be stored under
Optional
Configure using PersistOptions
Readonly
Current value or default if undefined
Set value with proxy object wrapper to sync future changes
Delete value from storage
Load value from storage
Save current value to storage
Return value as JSON string
Stringified object as JSON
Return current value
Current value
Callback function which is run when there are changes
Callback will run on each change; it's passed the next value & it's return is ignored
Function which will unsubscribe the watch/callback when called
Sync variable's value with persistent storage (LocalStorage by default)
Example