From ea8eaf3146a632c4875fa98dabc74a64817f3bd3 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 3 Sep 2017 20:06:20 +0300 Subject: [PATCH] swap parameters in prefs.subscribe --- background/background.js | 8 +++++--- background/update.js | 2 +- edit/edit.js | 4 +++- edit/lint.js | 2 +- js/prefs.js | 7 +++++-- options/options.js | 4 ++-- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/background/background.js b/background/background.js index 87ad49eb..51fbe3d8 100644 --- a/background/background.js +++ b/background/background.js @@ -42,7 +42,7 @@ if ('commands' in chrome) { // ************************************************************************* // set the default icon displayed after a tab is created until webNavigation kicks in -prefs.subscribe(() => updateIcon({id: undefined}, {}), ['iconset']); +prefs.subscribe(['iconset'], () => updateIcon({id: undefined}, {})); updateIcon({id: undefined}, {}); // ************************************************************************* @@ -143,7 +143,9 @@ contextMenus = Object.assign({ } }; createContextMenus(); - prefs.subscribe((id, checked) => { + const toggleableIds = Object.keys(contextMenus).filter(key => + typeof prefs.readOnlyValues[key] === 'boolean'); + prefs.subscribe(toggleableIds, (id, checked) => { if (id === 'editor.contextDelete') { if (checked) { createContextMenus([id]); @@ -153,7 +155,7 @@ contextMenus = Object.assign({ } else { chrome.contextMenus.update(id, {checked}, ignoreChromeError); } - }, Object.keys(contextMenus).filter(key => typeof prefs.readOnlyValues[key] === 'boolean')); + }); } // ************************************************************************* diff --git a/background/update.js b/background/update.js index 04f368f5..c400a29b 100644 --- a/background/update.js +++ b/background/update.js @@ -157,4 +157,4 @@ var updater = { }; updater.schedule(); -prefs.subscribe(updater.schedule, ['updateInterval']); +prefs.subscribe(['updateInterval'], updater.schedule); diff --git a/edit/edit.js b/edit/edit.js index 46118226..224d6a70 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -1400,7 +1400,9 @@ function initHooks() { $('#options h2').addEventListener('click', () => { setTimeout(() => prefs.set('editor.options.expanded', $('#options').open)); }); - prefs.subscribe((key, value) => ($('#options').open = value), ['editor.options.expanded']); + prefs.subscribe(['editor.options.expanded'], (key, value) => { + $('#options').open = value; + }); initLint(); diff --git a/edit/lint.js b/edit/lint.js index 44b3899b..09dd6bc4 100644 --- a/edit/lint.js +++ b/edit/lint.js @@ -132,7 +132,7 @@ function initLint() { linterConfig.loadAll(); linterConfig.watchStorage(); - prefs.subscribe(updateLinter, ['editor.linter']); + prefs.subscribe(['editor.linter'], updateLinter); updateLinter(); } diff --git a/js/prefs.js b/js/prefs.js index 7f54c556..7b021556 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -153,7 +153,10 @@ var prefs = new function Prefs() { } }, - subscribe(listener, keys) { + subscribe(keys, listener) { + // keys: string[] ids + // or a falsy value to subscribe to everything + // listener: function (key, value) if (keys) { for (const key of keys) { onChange.specific.set(key, listener); @@ -332,7 +335,7 @@ function setupLivePrefs( updateElement({id, element, force: true}); element.addEventListener('change', onChange); } - prefs.subscribe((id, value) => updateElement({id, value}), IDs); + prefs.subscribe(IDs, (id, value) => updateElement({id, value})); function onChange() { const value = this[checkedProps[this.id]]; diff --git a/options/options.js b/options/options.js index 10404e5b..cc84e7fc 100644 --- a/options/options.js +++ b/options/options.js @@ -81,7 +81,7 @@ function setupRadioButtons() { sets[name][prefs.get(name)].checked = true; } // listen to pref changes and update the values - prefs.subscribe((key, value) => { + prefs.subscribe(Object.keys(sets), (key, value) => { sets[key][value].checked = true; - }, Object.keys(sets)); + }); }