Fix: cacheFirstCall -> memoize

This commit is contained in:
eight 2018-09-02 14:36:18 +08:00
parent 8531d20c55
commit b27b6676fa
5 changed files with 9 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/* global cacheFirstCall editorWorker stylelint csslint showCodeMirrorPopup loadScript messageBox */ /* global memoize editorWorker stylelint csslint showCodeMirrorPopup loadScript messageBox */
'use strict'; 'use strict';
(() => { (() => {
@ -26,7 +26,7 @@
return; return;
} }
const storageName = linter === 'styleint' ? 'editorStylelintConfig' : 'editorCSSLintConfig'; const storageName = linter === 'styleint' ? 'editorStylelintConfig' : 'editorCSSLintConfig';
const getRules = cacheFirstCall(linter === 'stylelint' ? const getRules = memoize(linter === 'stylelint' ?
editorWorker.getStylelintRules : editorWorker.getCsslintRules); editorWorker.getStylelintRules : editorWorker.getCsslintRules);
const linterTitle = linter === 'stylelint' ? 'Stylelint' : 'CSSLint'; const linterTitle = linter === 'stylelint' ? 'Stylelint' : 'CSSLint';
const defaultConfig = stringifyConfig( const defaultConfig = stringifyConfig(

View File

@ -1,4 +1,4 @@
/* global linter editorWorker cacheFirstCall */ /* global linter editorWorker memoize */
'use strict'; 'use strict';
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
@ -49,7 +49,7 @@ var csslint = (() => {
}; };
let config; let config;
const prepareConfig = cacheFirstCall(() => { const prepareConfig = memoize(() => {
chrome.storage.onChanged.addListener((changes, area) => { chrome.storage.onChanged.addListener((changes, area) => {
if (area !== 'sync' || !changes.hasOwnProperty('editorCSSLintConfig')) { if (area !== 'sync' || !changes.hasOwnProperty('editorCSSLintConfig')) {
return; return;

View File

@ -1,9 +1,9 @@
/* global showHelp editorWorker cacheFirstCall */ /* global showHelp editorWorker memoize */
'use strict'; 'use strict';
function createLinterHelpDialog(getIssues) { function createLinterHelpDialog(getIssues) {
let csslintRules; let csslintRules;
const prepareCsslintRules = cacheFirstCall(() => const prepareCsslintRules = memoize(() =>
editorWorker.getCsslintRules() editorWorker.getCsslintRules()
.then(rules => { .then(rules => {
csslintRules = rules; csslintRules = rules;

View File

@ -1,4 +1,4 @@
/* global linter editorWorker cacheFirstCall */ /* global linter editorWorker memoize */
'use strict'; 'use strict';
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
@ -174,7 +174,7 @@ var stylelint = (() => {
}; };
let config; let config;
const prepareConfig = cacheFirstCall(() => { const prepareConfig = memoize(() => {
chrome.storage.onChanged.addListener((changes, area) => { chrome.storage.onChanged.addListener((changes, area) => {
if (area !== 'sync' || !changes.hasOwnProperty('editorStylelintConfig')) { if (area !== 'sync' || !changes.hasOwnProperty('editorStylelintConfig')) {
return; return;

View File

@ -123,7 +123,7 @@ function clipString(str, limit = 100) {
} }
// this is a decorator. Cache the first call // this is a decorator. Cache the first call
function cacheFirstCall(fn) { function memoize(fn) {
let cached = false; let cached = false;
let result; let result;
return (...args) => { return (...args) => {