debounce and subscribe updateLinter

This commit is contained in:
tophf 2017-08-29 17:59:45 +03:00
parent b91324992d
commit 3d5383ceaf
2 changed files with 11 additions and 7 deletions

View File

@ -371,9 +371,6 @@ function acmeEventListener(event) {
} }
option = 'highlightSelectionMatches'; option = 'highlightSelectionMatches';
break; break;
case 'linter':
debounce(updateLinter);
break;
} }
CodeMirror.setOption(option, value); CodeMirror.setOption(option, value);
} }

View File

@ -93,7 +93,7 @@ var linterConfig = {
if (area === 'sync') { if (area === 'sync') {
for (const name of ['editorCSSLintConfig', 'editorStylelintConfig']) { for (const name of ['editorCSSLintConfig', 'editorStylelintConfig']) {
if (name in changes && changes[name].newValue !== changes[name].oldValue) { if (name in changes && changes[name].newValue !== changes[name].oldValue) {
this.loadAll().then(() => debounce(updateLinter)); this.loadAll().then(updateLinter);
break; break;
} }
} }
@ -132,9 +132,16 @@ function initLint() {
linterConfig.loadAll(); linterConfig.loadAll();
linterConfig.watchStorage(); linterConfig.watchStorage();
prefs.subscribe(updateLinter, ['editor.linter']);
updateLinter();
} }
function updateLinter(linter = prefs.get('editor.linter')) { function updateLinter({immediately} = {}) {
if (!immediately) {
debounce(updateLinter, 0, {immediately: true});
return;
}
const linter = prefs.get('editor.linter');
const GUTTERS_CLASS = 'CodeMirror-lint-markers'; const GUTTERS_CLASS = 'CodeMirror-lint-markers';
function updateEditors() { function updateEditors() {
@ -147,7 +154,7 @@ function updateLinter(linter = prefs.get('editor.linter')) {
updateGutters(cm, guttersOption); updateGutters(cm, guttersOption);
} }
cm.refresh(); cm.refresh();
updateLintReport(cm, 200); updateLintReport(cm);
}); });
} }
@ -408,7 +415,7 @@ function setupLinterSettingsEvents(popup) {
} }
linterConfig.save(json); linterConfig.save(json);
linterConfig.showSavedMessage(); linterConfig.showSavedMessage();
debounce(updateLinter); updateLinter();
} else { } else {
showLinterErrorMessage(linter, t('linterJSONError')); showLinterErrorMessage(linter, t('linterJSONError'));
} }