/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict";
/** * Finds the accessor for the provided pref, based on the blueprint object * used in the constructor. * * @param PrefsHelper self * @param object prefsBlueprint * @return string
*/ function accessorNameForPref(somePrefName, prefsBlueprint) { for (const accessorName in prefsBlueprint) { const [, prefName] = prefsBlueprint[accessorName]; if (somePrefName == prefName) { return accessorName;
}
} return"";
}
/** * Creates a pref observer for `self`. * * @param PrefsHelper self * @param Map cache * @param string prefsRoot * @param object prefsBlueprint * @return object
*/ function makeObserver(self, cache, prefsRoot, prefsBlueprint) { return {
register() { this._branch = Services.prefs.getBranch(prefsRoot + "."); this._branch.addObserver("", this);
},
unregister() { this._branch.removeObserver("", this);
},
observe(subject, topic, prefName) { // If this particular pref isn't handled by the blueprint object, // even though it's in the specified branch, ignore it. const accessorName = accessorNameForPref(prefName, prefsBlueprint); if (!(accessorName in self)) { return;
}
cache.delete(prefName);
self.emit("pref-changed", accessorName, self[accessorName]);
},
};
}
exports.PrefsHelper = PrefsHelper;
/** * A PreferenceObserver observes a pref branch for pref changes. * It emits an event for each preference change.
*/ class PrefObserver extends EventEmitter {
constructor(branchName) { super();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.