Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/prefs.js

Issue 29338534: Issue 3826 - Filter preference change events (Closed)
Patch Set: Rebased and fixed a typo Created March 19, 2016, 7:48 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/messaging.js ('k') | lib/stats.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
}
});
« no previous file with comments | « lib/messaging.js ('k') | lib/stats.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld