Commit 1c2d4fcd authored by jlklein's avatar jlklein Committed by Commit bot

Switch prefs.js to Object.observe now that observe-js is no longer a dep.

BUG=

Review URL: https://codereview.chromium.org/1147933002

Cr-Commit-Position: refs/heads/master@{#330797}
parent 00c47bbf
......@@ -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() {});
}
});
},
});
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment