Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3587)

Unified Diff: chrome/browser/resources/settings/prefs/prefs.js

Issue 1147933002: Switch prefs.js to Object.observe now that observe-js is no longer a dep. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: michaels comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/prefs/prefs.js
diff --git a/chrome/browser/resources/settings/prefs/prefs.js b/chrome/browser/resources/settings/prefs/prefs.js
index febc22d41b1e70e46394148759d257e9ffb05762..4ac5a35cf59706025f4f2c4746c7e226ced00879 100644
--- a/chrome/browser/resources/settings/prefs/prefs.js
+++ b/chrome/browser/resources/settings/prefs/prefs.js
@@ -68,8 +68,8 @@
/**
* Updates the settings model with the given prefs.
* @param {!Array<!chrome.settingsPrivate.PrefObject>} prefs
- * @param {boolean} shouldObserve Whether to add an ObjectObserver for each
- * of the prefs.
+ * @param {boolean} shouldObserve Whether each of the prefs should be
+ * observed.
* @private
*/
updatePrefs_: function(prefs, shouldObserve) {
@@ -90,47 +90,39 @@
}
// NOTE: Do this copy rather than just a re-assignment, so that the
- // ObjectObserver fires.
+ // observer fires.
for (let objKey in prefObj) {
let path = 'prefStore.' + prefObj.key + '.' + objKey;
this.setPathValue(path, prefObj[objKey]);
}
if (shouldObserve) {
- let keyObserver = new ObjectObserver(root);
- keyObserver.open(
- this.propertyChangeCallback_.bind(this, prefObj.key));
+ Object.observe(root, this.propertyChangeCallback_, ['update']);
}
}, this);
},
/**
* Called when a property of a pref changes.
- * @param {string} propertyPath The path before the property names.
- * @param {!Array<string>} added An array of keys which were added.
- * @param {!Array<string>} removed An array of keys which were removed.
- * @param {!Array<string>} changed An array of keys of properties whose
- * values changed.
- * @param {function(string) : *} getOldValueFn A function which takes a
- * property name and returns the old value for that property.
+ * @param {!Array<!Object>} changes An array of objects describing changes.
+ * @see http://www.html5rocks.com/en/tutorials/es7/observe/
* @private
*/
- propertyChangeCallback_: function(
- propertyPath, added, removed, changed, getOldValueFn) {
- for (let property in changed) {
+ propertyChangeCallback_: function(changes) {
+ changes.forEach(function(change) {
// UI should only be able to change the value of a setting for now, not
// disabled, etc.
- assert(property == 'value');
+ assert(change.name == 'value');
- let newValue = changed[property];
+ let newValue = change.object[change.name];
assert(newValue !== undefined);
chrome.settingsPrivate.setPref(
- propertyPath,
+ change.object['key'],
newValue,
/* pageId */ '',
/* callback */ function() {});
- }
+ });
},
});
})();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698