ledge icon indicating copy to clipboard operation
ledge copied to clipboard

lazy import ledge render components

Open LiuuY opened this issue 4 years ago • 0 comments

现在 Ledge render 的 component 是写死在代码里面的,例如:

switch (codeBlock.lang) {
    case 'chart':
        const chartData = LedgeMarkdownConverter.toJson(codeBlock.text);
        this.markdownData.push({ type: 'chart', data: chartData.tables[0] });
        break;
    case ...

可能导致并没有使用的 component 包含进来。

可以改为 lazy import 的方式

switch (codeBlock.lang) {
    case 'chart':
        import('./chart/ledge-bar-chart/ledge-bar-chart.component').then(({ LedgeBarChartComponent }) => {
          const componentFactory = this.componentFactoryResolver.resolveComponentFactory(LedgeBarChartComponent);
          const { instance } = this.chartContainer.createComponent(componentFactory);

          instance.data = chartData.tables[0]
        });
    case ...

LiuuY avatar May 06 '20 05:05 LiuuY