From b27b6676facc892f5ad3cd89c9293a5d33a0a9a1 Mon Sep 17 00:00:00 2001 From: eight Date: Sun, 2 Sep 2018 14:36:18 +0800 Subject: [PATCH] Fix: cacheFirstCall -> memoize --- edit/linter-config-dialog.js | 4 ++-- edit/linter-csslint.js | 4 ++-- edit/linter-help-dialog.js | 4 ++-- edit/linter-stylelint.js | 4 ++-- edit/util.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/edit/linter-config-dialog.js b/edit/linter-config-dialog.js index e36cba91..752e5c7f 100644 --- a/edit/linter-config-dialog.js +++ b/edit/linter-config-dialog.js @@ -1,4 +1,4 @@ -/* global cacheFirstCall editorWorker stylelint csslint showCodeMirrorPopup loadScript messageBox */ +/* global memoize editorWorker stylelint csslint showCodeMirrorPopup loadScript messageBox */ 'use strict'; (() => { @@ -26,7 +26,7 @@ return; } const storageName = linter === 'styleint' ? 'editorStylelintConfig' : 'editorCSSLintConfig'; - const getRules = cacheFirstCall(linter === 'stylelint' ? + const getRules = memoize(linter === 'stylelint' ? editorWorker.getStylelintRules : editorWorker.getCsslintRules); const linterTitle = linter === 'stylelint' ? 'Stylelint' : 'CSSLint'; const defaultConfig = stringifyConfig( diff --git a/edit/linter-csslint.js b/edit/linter-csslint.js index e8572cbf..bd606344 100644 --- a/edit/linter-csslint.js +++ b/edit/linter-csslint.js @@ -1,4 +1,4 @@ -/* global linter editorWorker cacheFirstCall */ +/* global linter editorWorker memoize */ 'use strict'; // eslint-disable-next-line no-var @@ -49,7 +49,7 @@ var csslint = (() => { }; let config; - const prepareConfig = cacheFirstCall(() => { + const prepareConfig = memoize(() => { chrome.storage.onChanged.addListener((changes, area) => { if (area !== 'sync' || !changes.hasOwnProperty('editorCSSLintConfig')) { return; diff --git a/edit/linter-help-dialog.js b/edit/linter-help-dialog.js index ea9d99f9..7946a6e5 100644 --- a/edit/linter-help-dialog.js +++ b/edit/linter-help-dialog.js @@ -1,9 +1,9 @@ -/* global showHelp editorWorker cacheFirstCall */ +/* global showHelp editorWorker memoize */ 'use strict'; function createLinterHelpDialog(getIssues) { let csslintRules; - const prepareCsslintRules = cacheFirstCall(() => + const prepareCsslintRules = memoize(() => editorWorker.getCsslintRules() .then(rules => { csslintRules = rules; diff --git a/edit/linter-stylelint.js b/edit/linter-stylelint.js index 87ce2d03..0692b35e 100644 --- a/edit/linter-stylelint.js +++ b/edit/linter-stylelint.js @@ -1,4 +1,4 @@ -/* global linter editorWorker cacheFirstCall */ +/* global linter editorWorker memoize */ 'use strict'; // eslint-disable-next-line no-var @@ -174,7 +174,7 @@ var stylelint = (() => { }; let config; - const prepareConfig = cacheFirstCall(() => { + const prepareConfig = memoize(() => { chrome.storage.onChanged.addListener((changes, area) => { if (area !== 'sync' || !changes.hasOwnProperty('editorStylelintConfig')) { return; diff --git a/edit/util.js b/edit/util.js index c6260c41..a16c742f 100644 --- a/edit/util.js +++ b/edit/util.js @@ -123,7 +123,7 @@ function clipString(str, limit = 100) { } // this is a decorator. Cache the first call -function cacheFirstCall(fn) { +function memoize(fn) { let cached = false; let result; return (...args) => {