Skip to content

Commit cb8d980

Browse files
committed
fix: optimize resource loading
1 parent 5b9fe41 commit cb8d980

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/main/default/lwc/eventTimeline/eventTimeline.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,23 @@ export default class EventTimeline extends LightningElement {
3838
xAxis;
3939
yAxis;
4040

41-
async renderedCallback() {
42-
if (this.isD3Initialized) {
43-
this.drawTimeline();
44-
return;
45-
}
41+
async connectedCallback() {
4642
await loadScript(this, D3);
4743
this.isD3Initialized = true;
4844
this.initializeTimeline();
49-
this.drawTimeline();
45+
}
46+
47+
async renderedCallback() {
48+
this.initializeTimeline();
5049
}
5150

5251
initializeTimeline() {
52+
if (!this.isD3Initialized) {
53+
return;
54+
}
55+
5356
const rootElement = this.template.querySelector('.timeline');
57+
rootElement.childNodes.forEach((childNode) => childNode.remove());
5458

5559
// Add SVG element
5660
const svgElement = d3

src/main/default/lwc/orgLimits/orgLimits.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export default class OrgLimits extends LightningElement {
1717

1818
async connectedCallback() {
1919
try {
20-
const limits = await getOrgLimits();
20+
const [limits] = await Promise.all([
21+
getOrgLimits(),
22+
loadScript(this, D3)
23+
]);
24+
this.isD3Initialized = true;
2125
this.limits = limits
2226
.map((limit) => {
2327
const l = { ...limit };
@@ -33,23 +37,16 @@ export default class OrgLimits extends LightningElement {
3337
}
3438

3539
async renderedCallback() {
36-
try {
37-
if (!this.isD3Initialized) {
38-
await loadScript(this, D3);
39-
this.isD3Initialized = true;
40-
}
41-
this.drawChart();
42-
} catch (error) {
43-
this.error = JSON.stringify(error);
44-
}
40+
this.drawChart();
4541
}
4642

4743
drawChart() {
48-
if (!this.isD3Initialized || !this.limits) {
44+
if (!this.isD3Initialized) {
4945
return;
5046
}
5147

5248
const rootElement = this.template.querySelector('.chart');
49+
rootElement.childNodes.forEach((childNode) => childNode.remove());
5350

5451
// Add SVG element
5552
const svg = d3

0 commit comments

Comments
 (0)