PREF
Persistent user preferences.
On this page
API
method
PREF.get(key)
Reads a preference.
PREF.get(key)| Parameter | Type | Description |
|---|---|---|
key |
String |
The name of the preference. |
Returns Object The value.
ON('ready', function() {
PREF.set('theme', 'dark');
console.log(PREF.get('theme')); // dark
});
method
PREF.set(key, value)
Writes a preference and saves all preferences for one year.
PREF.set(key, value)| Parameter | Type | Description |
|---|---|---|
key |
String |
The name of the preference. |
value |
Object |
The value. |
Returns Object The written value.
Write preferences from the ready event onward, when the stored values are loaded. The key set is reserved and is ignored. Do not use the key get either: it replaces the method PREF.get().
ON('ready', function() {
console.log(PREF.set('language', 'en')); // en
console.log(PREF.language); // en
});
property
PREF.{key}
Each stored preference is also a property of the object.
PREF.{key}Returns Object The value of the preference.
Stored values are restored when the library starts. Reading a property is equal to calling PREF.get(). To save a change, use PREF.set().
DEF.onstorageread = function(callback) {
var stored = {};
stored['ui' + HASH('PREF').toString(36)] = { value: { theme: 'dark' }, expire: new Date(Date.now() + 60000) };
callback(stored);
};
ON('ready', function() {
console.log(PREF.theme); // dark
});