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

Unified Diff: lib/prefs.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Define and destructure backgroundPage more consistently, fix minor whitespace errors Created Jan. 18, 2017, 7:34 a.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
Index: lib/prefs.js
diff --git a/lib/prefs.js b/lib/prefs.js
index e1aa3f751c5feb430e5dfb83ada7917bd777bd9f..632e3aa03936d8d10a02cfbc8ecd92b58f9721af 100644
--- a/lib/prefs.js
+++ b/lib/prefs.js
@@ -17,7 +17,9 @@
/** @module prefs */
-let {EventEmitter} = require("events");
+"use strict";
+
+const {EventEmitter} = require("events");
const keyPrefix = "pref:";
@@ -188,7 +190,7 @@ let Prefs = exports.Prefs = {
* @param {string} preference
* @param {function} callback
*/
- on: function(preference, callback)
+ on(preference, callback)
{
eventEmitter.on(preference, callback);
},
@@ -199,7 +201,7 @@ let Prefs = exports.Prefs = {
* @param {string} preference
* @param {function} callback
*/
- off: function(preference, callback)
+ off(preference, callback)
{
eventEmitter.off(preference, callback);
},
@@ -230,11 +232,8 @@ function prefToKey(pref)
function addPreference(pref)
{
Object.defineProperty(Prefs, pref, {
- get: function()
- {
- return (pref in overrides ? overrides : defaults)[pref];
- },
- set: function(value)
+ get() { return (pref in overrides ? overrides : defaults)[pref]; },
+ set(value)
{
let defaultValue = defaults[pref];
@@ -262,7 +261,7 @@ function init()
prefs.forEach(addPreference);
let localLoaded = new Promise(resolve => {
- ext.storage.get(prefs.map(prefToKey), function(items)
+ ext.storage.get(prefs.map(prefToKey), items =>
{
for (let key in items)
overrides[keyToPref(key)] = items[key];
@@ -274,7 +273,7 @@ function init()
let managedLoaded = new Promise(resolve => {
if (require("info").platform == "chromium" && "managed" in chrome.storage)
{
- chrome.storage.managed.get(null, function(items)
+ chrome.storage.managed.get(null, items =>
{
// Opera doesn't support chrome.storage.managed, but instead simply
// removing the API, Opera sets chrome.runtime.lastError when using it.
@@ -296,7 +295,7 @@ function init()
function onLoaded()
{
- ext.storage.onChanged.addListener(function(changes)
+ ext.storage.onChanged.addListener(changes =>
{
for (let key in changes)
{

Powered by Google App Engine
This is Rietveld