Skip to content

Commit

Permalink
Merge pull request #14966 from apache/fix-component-missing-error
Browse files Browse the repository at this point in the history
fix(option): check the missing component before merge theme
  • Loading branch information
pissang authored May 17, 2021
2 parents a50c9fa + b6c5ce3 commit 35a15f8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
28 changes: 18 additions & 10 deletions src/model/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ const BUILTIN_CHARTS_MAP = {

const componetsMissingLogPrinted: Record<string, boolean> = {};

function checkMissingComponents(option: ECUnitOption) {
each(option, function (componentOption, mainType: ComponentMainType) {
if (!ComponentModel.hasClass(mainType)) {
const componentImportName = BUITIN_COMPONENTS_MAP[mainType as keyof typeof BUITIN_COMPONENTS_MAP];
if (componentImportName && !componetsMissingLogPrinted[componentImportName]) {
error(`Component ${mainType} is used but not imported.
import { ${componentImportName} } from 'echarts/components';
echarts.use([${componentImportName}]);`);
componetsMissingLogPrinted[componentImportName] = true;
}
}
});
}

class GlobalModel extends Model<ECUnitOption> {
// @readonly
option: ECUnitOption;
Expand Down Expand Up @@ -238,6 +252,9 @@ class GlobalModel extends Model<ECUnitOption> {

if (!type || type === 'recreate') {
const baseOption = optionManager.mountOption(type === 'recreate');
if (__DEV__) {
checkMissingComponents(baseOption);
}

if (!this.option || type === 'recreate') {
initBase(this, baseOption);
Expand Down Expand Up @@ -308,16 +325,6 @@ class GlobalModel extends Model<ECUnitOption> {
}

if (!ComponentModel.hasClass(mainType)) {
if (__DEV__) {
const componentImportName = BUITIN_COMPONENTS_MAP[mainType as keyof typeof BUITIN_COMPONENTS_MAP];
if (componentImportName && !componetsMissingLogPrinted[componentImportName]) {
error(`Component ${mainType} is used but not imported.
import { ${componentImportName} } from 'echarts/components';
echarts.use([${componentImportName}]);`);
componetsMissingLogPrinted[componentImportName] = true;
}
}

// globalSettingTask.dirty();
option[mainType] = option[mainType] == null
? clone(componentOption)
Expand Down Expand Up @@ -990,6 +997,7 @@ function mergeTheme(option: ECUnitOption, theme: ThemeOption): void {
if (name === 'colorLayer' && notMergeColorLayer) {
return;
}

// If it is component model mainType, the model handles that merge later.
// otherwise, merge them here.
if (!ComponentModel.hasClass(name)) {
Expand Down
28 changes: 21 additions & 7 deletions test/ut/spec/model/componentMissing.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35a15f8

Please sign in to comment.