Skip to content

Commit aafd7c4

Browse files
authored
Merge pull request #1087 from IgnaceMaes/lazy-load-highcharts
feat: lazy load Highcharts
2 parents 2619f7e + 07f24b0 commit aafd7c4

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

app/modifiers/draw-chart.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { registerDestructor } from '@ember/destroyable';
22
import merge from 'deepmerge';
33
import Modifier from 'ember-modifier';
4-
import Highcharts from 'highcharts';
5-
import highchartsAccessibilty from 'highcharts/modules/accessibility';
64

75
const optionsForAllCharts = {
86
credits: {
@@ -21,26 +19,33 @@ const optionsForAllCharts = {
2119
};
2220

2321
export default class DrawChartModifier extends Modifier {
24-
constructor(owner, args) {
25-
super(owner, args);
22+
highcharts;
2623

27-
this.initializeHighcharts();
28-
}
29-
30-
modify(element, [chart]) {
24+
async modify(element, [chart]) {
3125
if (!chart) {
3226
return;
3327
}
3428

29+
await this.initializeHighcharts();
30+
3531
this.drawChart({ chart, element });
3632

3733
registerDestructor(this, this.destroyChart.bind(this));
3834
}
3935

40-
initializeHighcharts() {
41-
highchartsAccessibilty(Highcharts);
36+
async initializeHighcharts() {
37+
if (this.highcharts) {
38+
return;
39+
}
40+
41+
const { default: highcharts } = await import('highcharts');
42+
const { default: highchartsAccessibilty } = await import(
43+
'highcharts/modules/accessibility'
44+
);
45+
46+
highchartsAccessibilty(highcharts);
4247

43-
this.highcharts = Highcharts;
48+
this.highcharts = highcharts;
4449
this.highcharts.setOptions(optionsForAllCharts);
4550
}
4651

0 commit comments

Comments
 (0)