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 the specified preference changed. |
kzar
2016/03/18 15:49:59
Nit: Should be "a specified"
Sebastian Noack
2016/03/18 18:15:49
Done.
|
* |
- * @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); |
} |
} |
}); |