utils.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. const Services = require("Services");
  7. const EventEmitter = require("devtools/shared/event-emitter");
  8. exports.PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled";
  9. /**
  10. * A PreferenceObserver observes a pref branch for pref changes.
  11. * It emits an event for each preference change.
  12. */
  13. function PrefObserver(branchName) {
  14. this.branchName = branchName;
  15. this.branch = Services.prefs.getBranch(branchName);
  16. this.branch.addObserver("", this, false);
  17. EventEmitter.decorate(this);
  18. }
  19. exports.PrefObserver = PrefObserver;
  20. PrefObserver.prototype = {
  21. observe: function (subject, topic, data) {
  22. if (topic == "nsPref:changed") {
  23. this.emit(this.branchName + data);
  24. }
  25. },
  26. destroy: function () {
  27. if (this.branch) {
  28. this.branch.removeObserver("", this);
  29. }
  30. }
  31. };