Skip to content

Commit 4dcc0a1

Browse files
committed
build: restored old code
1 parent 9c2d6e3 commit 4dcc0a1

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LitElement, html } from "lit";
1+
import { LitElement, html, PropertyValues } from "lit";
22
import { property, customElement } from "lit/decorators.js";
33
import { Container, Engine, tsParticles } from "tsparticles-engine";
44

@@ -23,37 +23,41 @@ export class LitParticles extends LitElement {
2323

2424
container?: Container;
2525

26+
initialized = false;
27+
2628
@property({ type: Function })
2729
particlesInit?: (engine: Engine) => Promise<void>;
2830

2931
@property({ type: Function })
3032
particlesLoaded?: (container?: Container) => Promise<void>;
3133

32-
constructor() {
33-
super();
34-
35-
this.particlesInit?.(tsParticles);
36-
}
37-
3834
connectedCallback() {
3935
super.connectedCallback();
4036

41-
tsParticles.load(this.id, this.options).then(async (container) => {
42-
this.container = container;
43-
44-
await this.particlesLoaded?.(container);
37+
this.particlesInit?.(tsParticles).then(() => {
38+
this.initialized = true;
4539
});
4640
}
4741

48-
disconnectedCallback(): void {
49-
if (this.container) {
50-
this.container.destroy();
51-
}
42+
update(changedProperties: PropertyValues) {
43+
super.update(changedProperties);
44+
45+
if (this.initialized) {
46+
tsParticles.load(this.id, this.options).then((container) => {
47+
this.container = container;
5248

53-
super.disconnectedCallback();
49+
this.particlesLoaded?.(container);
50+
});
51+
}
5452
}
5553

5654
render() {
57-
return html`<div id=${this.id}></div>`;
55+
if (!this.initialized) {
56+
return html``;
57+
}
58+
59+
return html`<div id=${this.id}>
60+
<canvas></canvas>
61+
</div>`;
5862
}
5963
}

0 commit comments

Comments
 (0)