Index: lib/prefs.js |
=================================================================== |
--- a/lib/prefs.js |
+++ b/lib/prefs.js |
@@ -17,11 +17,15 @@ |
/** @module prefs */ |
+let {EventEmitter} = require("events"); |
+ |
const keyPrefix = "pref:"; |
+let eventEmitter = new EventEmitter(); |
+let overrides = Object.create(null); |
+ |
/** @lends module:prefs.Prefs */ |
let defaults = Object.create(null); |
-let overrides = Object.create(null); |
/** |
* Only for compatibility with core code. Please do not change! |
@@ -178,12 +182,27 @@ |
*/ |
let Prefs = exports.Prefs = { |
/** |
- * Fired when the value of a preference changes. |
+ * Adds a callback that is called when the |
+ * value of a specified preference changed. |
* |
- * @event |
- * @property {string} pref The name of the preference that changed. |
+ * @param {string} preference |
+ * @param {function} callback |
*/ |
- onChanged: new ext._EventTarget(), |
+ on: function(preference, callback) |
+ { |
+ eventEmitter.on(preference, callback); |
+ }, |
+ |
+ /** |
+ * Removes a callback for the specified preference. |
+ * |
+ * @param {string} preference |
+ * @param {function} callback |
+ */ |
+ off: function(preference, callback) |
+ { |
+ eventEmitter.off(preference, callback); |
+ }, |
/** |
* A promise that is fullfilled when all preferences have been loaded. |
@@ -290,7 +309,7 @@ |
else |
delete overrides[pref]; |
- Prefs.onChanged._dispatch(pref); |
+ eventEmitter.emit(pref); |
} |
} |
}); |