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';
(() => {
@ -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(

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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) => {