-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMicroAppElement.ts
33 lines (28 loc) · 921 Bytes
/
MicroAppElement.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { initOption } from './helpers/init-option';
import { initApp } from './helpers/init-app';
import { defineProperties } from './helpers/utils';
export default class MicroAppElement extends HTMLElement {
_option: MicroAppOption;
#root: MicroAppRoot;
connectedCallback() {
const ctx = this;
const option = initOption(ctx);
ctx._option = option;
let shadowRoot: MicroAppRoot;
if (ctx.#root) {
shadowRoot = ctx.#root;
} else {
shadowRoot = <MicroAppRoot> ctx.attachShadow({ mode: option.shadowMode });
ctx.#root = shadowRoot;
}
initApp(option, shadowRoot);
}
disconnectedCallback() {
this.#root.innerHTML = '';
defineProperties(this.#root, {
documentElement: { value: null },
head: { value: null },
body: { value: null },
});
}
}