Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(option): check the missing component before merge theme #14966

Merged
merged 2 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
plainheart marked this conversation as resolved.
Show resolved Hide resolved
}

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.