Add: use cacheFn
This commit is contained in:
parent
2e66ecca18
commit
eb76861fad
|
@ -1,4 +1,4 @@
|
||||||
/* global linter editorWorker */
|
/* global linter editorWorker cacheFn */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var csslint = (() => { // eslint-disable-line
|
var csslint = (() => { // eslint-disable-line
|
||||||
|
@ -47,7 +47,23 @@ var csslint = (() => { // eslint-disable-line
|
||||||
'zero-units': 0
|
'zero-units': 0
|
||||||
};
|
};
|
||||||
let config;
|
let config;
|
||||||
let preparing;
|
|
||||||
|
const prepareConfig = cacheFn(() => {
|
||||||
|
chrome.storage.onChanged.addListener((changes, area) => {
|
||||||
|
if (area !== 'sync' || !changes.hasOwnProperty('editorCSSLintConfig')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getNewValue().then(linter.refresh);
|
||||||
|
});
|
||||||
|
return getNewValue();
|
||||||
|
|
||||||
|
function getNewValue() {
|
||||||
|
return chromeSync.getLZValue('editorCSSLintConfig')
|
||||||
|
.then(newConfig => {
|
||||||
|
config = Object.assign({}, DEFAULT, newConfig);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
linter.register((text, options, cm) => {
|
linter.register((text, options, cm) => {
|
||||||
if (prefs.get('editor.linter') !== 'csslint' || cm.getOption('mode') !== 'css') {
|
if (prefs.get('editor.linter') !== 'csslint' || cm.getOption('mode') !== 'css') {
|
||||||
|
@ -69,27 +85,4 @@ var csslint = (() => { // eslint-disable-line
|
||||||
});
|
});
|
||||||
|
|
||||||
return {DEFAULT};
|
return {DEFAULT};
|
||||||
|
|
||||||
function prepareConfig() {
|
|
||||||
if (config) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
if (!preparing) {
|
|
||||||
chrome.storage.onChanged.addListener((changes, area) => {
|
|
||||||
if (area !== 'sync' || !changes.editorCSSLintConfig) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getNewValue().then(newConfig => {
|
|
||||||
config = newConfig;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
preparing = getNewValue();
|
|
||||||
}
|
|
||||||
return preparing;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNewValue() {
|
|
||||||
return chromeSync.getLZValue('editorCSSLintConfig')
|
|
||||||
.then(newConfig => Object.assign({}, DEFAULT, newConfig));
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* global linter editorWorker */
|
/* global linter editorWorker cacheFn */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var stylelint = (() => { // eslint-disable-line no-var
|
var stylelint = (() => { // eslint-disable-line no-var
|
||||||
|
@ -6,7 +6,7 @@ var stylelint = (() => { // eslint-disable-line no-var
|
||||||
const DEFAULT = {
|
const DEFAULT = {
|
||||||
// 'sugarss' is a indent-based syntax like Sass or Stylus
|
// 'sugarss' is a indent-based syntax like Sass or Stylus
|
||||||
// ref: https://github.com/postcss/postcss#syntaxes
|
// ref: https://github.com/postcss/postcss#syntaxes
|
||||||
syntax: 'sugarss',
|
// syntax: 'sugarss',
|
||||||
// ** recommended rules **
|
// ** recommended rules **
|
||||||
// ref: https://github.com/stylelint/stylelint-config-recommended/blob/master/index.js
|
// ref: https://github.com/stylelint/stylelint-config-recommended/blob/master/index.js
|
||||||
rules: {
|
rules: {
|
||||||
|
@ -172,7 +172,26 @@ var stylelint = (() => { // eslint-disable-line no-var
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let config;
|
let config;
|
||||||
let preparing;
|
|
||||||
|
const prepareConfig = cacheFn(() => {
|
||||||
|
chrome.storage.onChanged.addListener((changes, area) => {
|
||||||
|
if (area !== 'sync' || !changes.hasOwnProperty('editorStylelintConfig')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getNewValue().then(linter.refresh);
|
||||||
|
});
|
||||||
|
return getNewValue();
|
||||||
|
|
||||||
|
function getNewValue() {
|
||||||
|
return chromeSync.getLZValue('editorStylelintConfig')
|
||||||
|
.then(newConfig => {
|
||||||
|
const output = {};
|
||||||
|
output.rules = Object.assign({}, DEFAULT.rules, newConfig && newConfig.rules);
|
||||||
|
output.syntax = 'sugarss';
|
||||||
|
config = output;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
linter.register((text, options, cm) => {
|
linter.register((text, options, cm) => {
|
||||||
if (
|
if (
|
||||||
|
@ -207,32 +226,4 @@ var stylelint = (() => { // eslint-disable-line no-var
|
||||||
});
|
});
|
||||||
|
|
||||||
return {DEFAULT};
|
return {DEFAULT};
|
||||||
|
|
||||||
function prepareConfig() {
|
|
||||||
if (config) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
if (!preparing) {
|
|
||||||
chrome.storage.onChanged.addListener((changes, area) => {
|
|
||||||
if (area !== 'sync' || !changes.editorStylelintConfig) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getNewValue().then(newConfig => {
|
|
||||||
config = newConfig;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
preparing = getNewValue();
|
|
||||||
}
|
|
||||||
return preparing;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNewValue() {
|
|
||||||
return chromeSync.getLZValue('editorStylelintConfig')
|
|
||||||
.then(newConfig => {
|
|
||||||
const output = {};
|
|
||||||
output.rules = Object.assign({}, DEFAULT.rules, newConfig && newConfig.rules);
|
|
||||||
output.syntax = 'sugarss';
|
|
||||||
config = output;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user