src/preferences/PreferencesBase.js
function PreferencesSystem(contextBuilder) {
        this.contextBuilder = contextBuilder;

        this._knownPrefs = {};
        this._scopes = {
            "default": new Scope(new MemoryStorage())
        };

        this._scopes["default"].load();

        this._defaults = {
            scopeOrder: ["default"],
            _shadowScopeOrder: [{
                id: "default",
                scope: this._scopes["default"],
                promise: (new $.Deferred()).resolve().promise()
            }]
        };

        this._pendingScopes = {};

        this._saveInProgress = false;
        this._nextSaveDeferred = null;

        // The objects that define the different kinds of path-based Scope handlers.
        // Examples could include the handler for .brackets.json files or an .editorconfig
        // handler.
        this._pathScopeDefinitions = {};

        // Names of the files that contain path scopes
        this._pathScopeFilenames = [];

        // Keeps track of cached path scope objects.
        this._pathScopes = {};

        // Keeps track of change events that need to be sent when change events are resumed
        this._changeEventQueue = null;

        var notifyPrefChange = function (id) {
            var pref = this._knownPrefs[id];
            if (pref) {
                pref.trigger(PREFERENCE_CHANGE);
            }
        }.bind(this);

        // When we signal a general change message on this manager, we also signal a change
        // on the individual preference object.
        this.on(PREFERENCE_CHANGE, function (e, data) {
            data.ids.forEach(notifyPrefChange);
        }.bind(this));
    }
function PreferencesSystem(contextBuilder) {
        this.contextBuilder = contextBuilder;

        this._knownPrefs = {};
        this._scopes = {
            "default": new Scope(new MemoryStorage())
        };

        this._scopes["default"].load();

        this._defaults = {
            scopeOrder: ["default"],
            _shadowScopeOrder: [{
                id: "default",
                scope: this._scopes["default"],
                promise: (new $.Deferred()).resolve().promise()
            }]
        };

        this._pendingScopes = {};

        this._saveInProgress = false;
        this._nextSaveDeferred = null;

        // The objects that define the different kinds of path-based Scope handlers.
        // Examples could include the handler for .brackets.json files or an .editorconfig
        // handler.
        this._pathScopeDefinitions = {};

        // Names of the files that contain path scopes
        this._pathScopeFilenames = [];

        // Keeps track of cached path scope objects.
        this._pathScopes = {};

        // Keeps track of change events that need to be sent when change events are resumed
        this._changeEventQueue = null;

        var notifyPrefChange = function (id) {
            var pref = this._knownPrefs[id];
            if (pref) {
                pref.trigger(PREFERENCE_CHANGE);
            }
        }.bind(this);

        // When we signal a general change message on this manager, we also signal a change
        // on the individual preference object.
        this.on(PREFERENCE_CHANGE, function (e, data) {
            data.ids.forEach(notifyPrefChange);
        }.bind(this));
    }
function PreferencesSystem ( contextBuilder ) { this . contextBuilder = contextBuilder ; this . _knownPrefs = { } ; this . _scopes = { "default" : new Scope ( new MemoryStorage ( ) ) } ; this . _scopes [ "default" ] . load ( ) ; this . _defaults = { scopeOrder : [ "default" ] , _shadowScopeOrder : [ { id : "default" , scope : this . _scopes [ "default" ] , promise : ( new $ . Deferred ( ) ) . resolve ( ) . promise ( ) } ] } ; this . _pendingScopes = { } ; this . _saveInProgress = false ; this . _nextSaveDeferred = null ; // The objects that define the different kinds of path-based Scope handlers. // Examples could include the handler for .brackets.json files or an .editorconfig // handler. this . _pathScopeDefinitions = { } ; // Names of the files that contain path scopes this . _pathScopeFilenames = [ ] ; // Keeps track of cached path scope objects. this . _pathScopes = { } ; // Keeps track of change events that need to be sent when change events are resumed this . _changeEventQueue = null ; var notifyPrefChange = function ( id ) { var pref = this . _knownPrefs [ id ] ; if ( pref ) { pref . trigger ( PREFERENCE_CHANGE ) ; } } . bind ( this ) ; // When we signal a general change message on this manager, we also signal a change // on the individual preference object. this . on ( PREFERENCE_CHANGE , function ( e , data ) { data . ids . forEach ( notifyPrefChange ) ; } . bind ( this ) ) ; }
PreferencesSystem ties everything together to provide a simple interface for
managing the whole prefs system.

It keeps track of multiple Scope levels and also manages path-based Scopes.

It also provides the ability to register preferences, which gives a fine-grained
means for listening for changes and will ultimately allow for automatic UI generation.

The contextBuilder is used to construct get/set contexts based on the needs of individual
context systems. It can be passed in at construction time or set later.

@constructor
@param {function=} contextNormalizer function that is passed the context used for get or set to adjust for specific PreferencesSystem behavior
PreferencesSystem ties everything together to provide a simple interface for managing the whole prefs system .