[ci] format

This commit is contained in:
natemoo-re 2023-08-29 14:32:02 +00:00 committed by astrobot-houston
parent 1f58a7a1be
commit 51e67e0ab0
5 changed files with 19 additions and 13 deletions

View file

@ -52,10 +52,14 @@ declare const Astro: {
public hydrator: any; public hydrator: any;
static observedAttributes = ['props']; static observedAttributes = ['props'];
disconnectedCallback() { disconnectedCallback() {
document.addEventListener('astro:after-swap', () => { document.addEventListener(
// If element wasn't persisted, fire unmount event 'astro:after-swap',
if (!this.isConnected) this.dispatchEvent(new CustomEvent('astro:unmount')) () => {
}, { once: true }) // If element wasn't persisted, fire unmount event
if (!this.isConnected) this.dispatchEvent(new CustomEvent('astro:unmount'));
},
{ once: true }
);
} }
connectedCallback() { connectedCallback() {
if (!this.hasAttribute('await-children') || this.firstChild) { if (!this.hasAttribute('await-children') || this.firstChild) {

View file

@ -1,6 +1,6 @@
import type { SignalLike } from './types'; import { h, hydrate, render } from 'preact';
import { h, render, hydrate } from 'preact';
import StaticHtml from './static-html.js'; import StaticHtml from './static-html.js';
import type { SignalLike } from './types';
const sharedSignalMap = new Map<string, SignalLike>(); const sharedSignalMap = new Map<string, SignalLike>();
@ -32,9 +32,9 @@ export default (element: HTMLElement) =>
bootstrap( bootstrap(
h(Component, props, children != null ? h(StaticHtml, { value: children }) : children), h(Component, props, children != null ? h(StaticHtml, { value: children }) : children),
element, element
); );
// Preact has no "unmount" option, but you can use `render(null, element)` // Preact has no "unmount" option, but you can use `render(null, element)`
element.addEventListener('astro:unmount', () => render(null, element), { once: true }) element.addEventListener('astro:unmount', () => render(null, element), { once: true });
}; };

View file

@ -16,5 +16,7 @@ export default (element) =>
const isHydrate = client !== 'only'; const isHydrate = client !== 'only';
const bootstrap = isHydrate ? hydrate : render; const bootstrap = isHydrate ? hydrate : render;
bootstrap(componentEl, element); bootstrap(componentEl, element);
element.addEventListener('astro:unmount', () => unmountComponentAtNode(element), { once: true }); element.addEventListener('astro:unmount', () => unmountComponentAtNode(element), {
once: true,
});
}; };

View file

@ -43,5 +43,5 @@ export default (element: HTMLElement) =>
} }
); );
element.addEventListener('astro:unmount', () => dispose(), { once: true }) element.addEventListener('astro:unmount', () => dispose(), { once: true });
}; };

View file

@ -24,8 +24,8 @@ export default (target) => {
hydrate: client !== 'only', hydrate: client !== 'only',
$$inline: true, $$inline: true,
}); });
element.addEventListener('astro:unmount', () => component.$destroy(), { once: true }) element.addEventListener('astro:unmount', () => component.$destroy(), { once: true });
} catch (e) { } catch (e) {
} finally { } finally {
if (import.meta.env.DEV) finishUsingConsoleFilter(); if (import.meta.env.DEV) finishUsingConsoleFilter();