forked from stenciljs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisconnected-callback.ts
More file actions
48 lines (41 loc) · 1.46 KB
/
Copy pathdisconnected-callback.ts
File metadata and controls
48 lines (41 loc) · 1.46 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { BUILD } from '@app-data';
import { getHostRef, plt } from '@platform';
import type * as d from '../declarations';
import { PLATFORM_FLAGS } from './runtime-constants';
import { rootAppliedStyles } from './styles';
import { safeCall } from './update-component';
const disconnectInstance = (instance: any, elm?: d.HostElement) => {
if (BUILD.lazyLoad) {
safeCall(instance, 'disconnectedCallback', undefined, elm || instance);
}
};
export const disconnectedCallback = async (elm: d.HostElement) => {
if ((plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) {
const hostRef = getHostRef(elm);
if (BUILD.hostListener) {
if (hostRef?.$rmListeners$) {
hostRef.$rmListeners$.map((rmListener) => rmListener());
hostRef.$rmListeners$ = undefined;
}
}
if (!BUILD.lazyLoad) {
disconnectInstance(elm);
} else if (hostRef?.$lazyInstance$) {
disconnectInstance(hostRef.$lazyInstance$, elm);
} else if (hostRef?.$onReadyPromise$) {
hostRef.$onReadyPromise$.then(() => disconnectInstance(hostRef.$lazyInstance$, elm));
}
}
/**
* Remove the element from the `rootAppliedStyles` WeakMap
*/
if (rootAppliedStyles.has(elm)) {
rootAppliedStyles.delete(elm);
}
/**
* Remove the shadow root from the `rootAppliedStyles` WeakMap
*/
if (elm.shadowRoot && rootAppliedStyles.has(elm.shadowRoot as unknown as Element)) {
rootAppliedStyles.delete(elm.shadowRoot as unknown as Element);
}
};