Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Dec 31, 2024
1 parent bc58ceb commit fb8335e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
17 changes: 6 additions & 11 deletions src/client/client-host-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const registerInstance = (lazyInstance: any, hostRef: d.HostRef) => {
hostRef.$lazyInstance$ = lazyInstance;
hostRefKeys.push(lazyInstance);
return hostRefs.set(lazyInstance, hostRef);
}
};

/**
* Register a host element for a Stencil component, setting up various metadata
Expand Down Expand Up @@ -91,11 +91,7 @@ export const isMemberInElement = (elm: any, memberName: string) => memberName in
* @returns true if the node is attached to the DOM
*/
function isNodeAttached(node: Node) {
return (
node === document ||
node === document.documentElement ||
document.contains(node)
);
return node === document || node === document.documentElement || document.contains(node);
}

export const hostRefCleanup = () => {
Expand All @@ -108,7 +104,8 @@ export const hostRefCleanup = () => {
* Iterate through your `hostRefKeys` and determine if the key should be removed.
* We consider a key to be removed if:
*/
for (const key of hostRefKeys) { // You need to maintain these keys separately
for (const key of hostRefKeys) {
// You need to maintain these keys separately
/**
* it is an instance of an HTMLElement and
* it is not attached to the DOM anymore
Expand All @@ -124,10 +121,8 @@ export const hostRefCleanup = () => {
const elem = hostRefs.get(key as d.HostElement);
if (
elem &&
(
(elem.$hostElement$ && !isNodeAttached(elem.$hostElement$)) ||
(elem.$ancestorComponent$ && !isNodeAttached(elem.$ancestorComponent$))
)
((elem.$hostElement$ && !isNodeAttached(elem.$hostElement$)) ||
(elem.$ancestorComponent$ && !isNodeAttached(elem.$ancestorComponent$)))
) {
keysToRemove.push(key);
}
Expand Down
10 changes: 4 additions & 6 deletions src/runtime/disconnected-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ const disconnectInstance = (instance: any) => {
Promise.all(
callbackResult
.filter((item: unknown): item is object => typeof item === 'object')
.filter((promise) => 'then' in promise && typeof promise.then === 'function')
).finally(
() => setTimeout(() => hostRefCleanup())
);
.filter((promise) => 'then' in promise && typeof promise.then === 'function'),
).finally(() => setTimeout(() => hostRefCleanup()));
};

export const disconnectedCallback = async (elm: d.HostElement) => {
Expand Down Expand Up @@ -53,14 +51,14 @@ export const disconnectedCallback = async (elm: d.HostElement) => {
/**
* Remove the element from the `rootAppliedStyles` WeakMap
*/
if(rootAppliedStyles.has(elm)) {
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)) {
if (elm.shadowRoot && rootAppliedStyles.has(elm.shadowRoot as unknown as Element)) {
rootAppliedStyles.delete(elm.shadowRoot as unknown as Element);
}
};

0 comments on commit fb8335e

Please sign in to comment.