src/preferences/PreferencesBase.js
function (id, value, options, doNotSave) {
            options = options || {};
            var context = this._getContext(options.context),

                // The case where the "default" scope was chosen specifically is special.
                // Usually "default" would come up only when a preference did not have any
                // user-set value, in which case we'd want to set the value in a different scope.
                forceDefault = options.location && options.location.scope === "default" ? true : false,
                location = options.location || this.getPreferenceLocation(id, context);

            if (!location || (location.scope === "default" && !forceDefault)) {
                var scopeOrder = this._getScopeOrder(context);

                // The default scope for setting a preference is the lowest priority
                // scope after "default".
                if (scopeOrder.length > 1) {
                    location = {
                        scope: scopeOrder[scopeOrder.length - 2]
                    };
                } else {
                    return { valid: true, stored: false };
                }
            }

            var scope = this._scopes[location.scope];
            if (!scope) {
                return { valid: true, stored: false };
            }

            var pref      = this.getPreference(id),
                validator = pref && pref.validator;
            if (validator && !validator(value)) {
                return { valid: false, stored: false };
            }

            var wasSet = scope.set(id, value, context, location);
            if (wasSet) {
                if (!doNotSave) {
                    this.save();
                }
                this._triggerChange({
                    ids: [id]
                });
            }
            return { valid: true, stored: wasSet };
        }
function (id, value, options, doNotSave) {
            options = options || {};
            var context = this._getContext(options.context),

                // The case where the "default" scope was chosen specifically is special.
                // Usually "default" would come up only when a preference did not have any
                // user-set value, in which case we'd want to set the value in a different scope.
                forceDefault = options.location && options.location.scope === "default" ? true : false,
                location = options.location || this.getPreferenceLocation(id, context);

            if (!location || (location.scope === "default" && !forceDefault)) {
                var scopeOrder = this._getScopeOrder(context);

                // The default scope for setting a preference is the lowest priority
                // scope after "default".
                if (scopeOrder.length > 1) {
                    location = {
                        scope: scopeOrder[scopeOrder.length - 2]
                    };
                } else {
                    return { valid: true, stored: false };
                }
            }

            var scope = this._scopes[location.scope];
            if (!scope) {
                return { valid: true, stored: false };
            }

            var pref      = this.getPreference(id),
                validator = pref && pref.validator;
            if (validator && !validator(value)) {
                return { valid: false, stored: false };
            }

            var wasSet = scope.set(id, value, context, location);
            if (wasSet) {
                if (!doNotSave) {
                    this.save();
                }
                this._triggerChange({
                    ids: [id]
                });
            }
            return { valid: true, stored: wasSet };
        }
function ( id , value , options , doNotSave ) { options = options || { } ; var context = this . _getContext ( options . context ) , // The case where the "default" scope was chosen specifically is special. // Usually "default" would come up only when a preference did not have any // user-set value, in which case we'd want to set the value in a different scope. forceDefault = options . location && options . location . scope === "default" ? true : false , location = options . location || this . getPreferenceLocation ( id , context ) ; if ( ! location || ( location . scope === "default" && ! forceDefault ) ) { var scopeOrder = this . _getScopeOrder ( context ) ; // The default scope for setting a preference is the lowest priority // scope after "default". if ( scopeOrder . length > 1 ) { location = { scope : scopeOrder [ scopeOrder . length - 2 ] } ; } else { return { valid : true , stored : false } ; } } var scope = this . _scopes [ location . scope ] ; if ( ! scope ) { return { valid : true , stored : false } ; } var pref = this . getPreference ( id ) , validator = pref && pref . validator ; if ( validator && ! validator ( value ) ) { return { valid : false , stored : false } ; } var wasSet = scope . set ( id , value , context , location ) ; if ( wasSet ) { if ( ! doNotSave ) { this . save ( ) ; } this . _triggerChange ( { ids : [ id ] } ) ; } return { valid : true , stored : wasSet } ; }
Sets a preference and notifies listeners that there may
have been a change. By default, the preference is set in the same location in which
it was defined except for the "default" scope. If the current value of the preference
comes from the "default" scope, the new value will be set at the level just above
default.

@param {string} id Identifier of the preference to set
@param {Object} value New value for the preference
@param {{location: ?Object, context: ?Object}=} options Specific location in which to set the value or the context to use when setting the value
@param {boolean=} doNotSave True if the preference change should not be saved automatically.
@return {valid:  {boolean}, true if no validator specified or if value is valid
stored: {boolean}} true if a value was stored
Sets a preference and notifies listeners that there may have been a change . By default the preference is set in the same location in which it was defined except for the default scope . If the current value of the preference comes from the default scope the new value will be set at the level just above default .