Modules (180)

PreferenceStorage

deprecated
Use PreferencesManager APIs instead.

Description

PreferenceStorage defines an interface for persisting preference data as name/value pairs for a module or plugin.

Dependencies

Functions

Public API

PreferenceStorage

Creates a new PreferenceStorage object.

clientID non-nullable string
Unique identifier for PreferencesManager to associate this PreferenceStorage data with.
json non-nullable object
JSON object to persist preference data.
    function PreferenceStorage(clientID, json) {
        this._clientID = clientID;
        this._json = json;
    }
Private

_commit

    function _commit() {
        PreferencesManager.savePreferences();
    }
Private

_validateJSONPair

    function _validateJSONPair(key, value) {
        if (typeof key === "string") {
            // validate temporary JSON
            var temp = {},
                error = null;
            temp[key] = value;

            try {
                temp = JSON.parse(JSON.stringify(temp));
            } catch (err) {
                error = err;
            }

            // set value to JSON storage if no errors occurred
            if (!error && (temp[key] !== undefined)) {
                return true;
            } else {
                console.error("Value '" + value + "' for key '" + key + "' must be a valid JSON value");
                return false;
            }
        } else {
            console.error("Preference key '" + key + "' must be a string");
            return false;
        }
    }