michael@0: /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const {Cc, Ci, Cu, Cr} = require("chrome"); michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/devtools/event-emitter.js"); michael@0: michael@0: exports.PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled"; michael@0: michael@0: /** michael@0: * A PreferenceObserver observes a pref branch for pref changes. michael@0: * It emits an event for each preference change. michael@0: */ michael@0: function PrefObserver(branchName) { michael@0: this.branchName = branchName; michael@0: this.branch = Services.prefs.getBranch(branchName); michael@0: this.branch.addObserver("", this, false); michael@0: michael@0: EventEmitter.decorate(this); michael@0: } michael@0: michael@0: exports.PrefObserver = PrefObserver; michael@0: michael@0: PrefObserver.prototype = { michael@0: observe: function(subject, topic, data) { michael@0: if (topic == "nsPref:changed") { michael@0: this.emit(this.branchName + data); michael@0: } michael@0: }, michael@0: michael@0: destroy: function() { michael@0: if (this.branch) { michael@0: this.branch.removeObserver('', this); michael@0: } michael@0: } michael@0: };