[ci] format
This commit is contained in:
parent
c9d8b10a85
commit
e02c72f445
8 changed files with 61 additions and 59 deletions
|
@ -94,4 +94,3 @@ test.describe('Nested Frameworks in Solid', () => {
|
|||
await expect(count, 'count incremented by 1').toHaveText('1');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
const HYDRATE_KEY = `astro:hydrate`;
|
||||
function debounce<T extends (...args: any[]) => any>(cb: T, wait = 20) {
|
||||
let h = 0;
|
||||
let callable = (...args: any) => {
|
||||
clearTimeout(h);
|
||||
h = setTimeout(() => cb(...args), wait) as unknown as number;
|
||||
};
|
||||
return callable as T;
|
||||
let h = 0;
|
||||
let callable = (...args: any) => {
|
||||
clearTimeout(h);
|
||||
h = setTimeout(() => cb(...args), wait) as unknown as number;
|
||||
};
|
||||
return callable as T;
|
||||
}
|
||||
|
||||
export const notify = debounce(() => {
|
||||
|
@ -14,7 +14,8 @@ export const notify = debounce(() => {
|
|||
}
|
||||
});
|
||||
|
||||
export const listen = (cb: (...args: any[]) => any) => window.addEventListener(HYDRATE_KEY, cb, { once: true });
|
||||
export const listen = (cb: (...args: any[]) => any) =>
|
||||
window.addEventListener(HYDRATE_KEY, cb, { once: true });
|
||||
|
||||
if (!(window as any)[HYDRATE_KEY]) {
|
||||
if ('MutationObserver' in window) {
|
||||
|
|
|
@ -14,7 +14,7 @@ export default async function onIdle(
|
|||
let hydrate: Awaited<ReturnType<GetHydrateCallback>>;
|
||||
|
||||
async function idle() {
|
||||
listen(idle)
|
||||
listen(idle);
|
||||
const cb = async () => {
|
||||
const roots = document.querySelectorAll(`astro-root[ssr][uid="${astroId}"]`);
|
||||
if (roots.length === 0) return;
|
||||
|
|
|
@ -13,7 +13,7 @@ export default async function onMedia(
|
|||
let hydrate: Awaited<ReturnType<GetHydrateCallback>>;
|
||||
|
||||
async function media() {
|
||||
listen(media)
|
||||
listen(media);
|
||||
const cb = async () => {
|
||||
const roots = document.querySelectorAll(`astro-root[ssr][uid="${astroId}"]`);
|
||||
if (roots.length === 0) return;
|
||||
|
|
|
@ -16,7 +16,7 @@ export default async function onVisible(
|
|||
let hydrate: Awaited<ReturnType<GetHydrateCallback>>;
|
||||
|
||||
async function visible() {
|
||||
listen(visible)
|
||||
listen(visible);
|
||||
const roots = document.querySelectorAll(`astro-root[ssr][uid="${astroId}"]`);
|
||||
const cb = async () => {
|
||||
if (roots.length === 0) return;
|
||||
|
|
|
@ -7,4 +7,4 @@ export default (element) => (Component, props, children) => {
|
|||
h(Component, props, children != null ? h(StaticHtml, { value: children }) : children),
|
||||
element
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,36 +1,37 @@
|
|||
import { sharedConfig } from 'solid-js';
|
||||
import { hydrate, render, createComponent } from 'solid-js/web';
|
||||
|
||||
export default (element) => (Component, props, childHTML, { client }) => {
|
||||
// Prepare global object expected by Solid's hydration logic
|
||||
if (!window._$HY) {
|
||||
window._$HY = { events: [], completed: new WeakSet(), r: {} };
|
||||
}
|
||||
if (!element.hasAttribute('ssr')) return;
|
||||
export default (element) =>
|
||||
(Component, props, childHTML, { client }) => {
|
||||
// Prepare global object expected by Solid's hydration logic
|
||||
if (!window._$HY) {
|
||||
window._$HY = { events: [], completed: new WeakSet(), r: {} };
|
||||
}
|
||||
if (!element.hasAttribute('ssr')) return;
|
||||
|
||||
const fn = client === 'only' ? render : hydrate;
|
||||
|
||||
// Perform actual hydration
|
||||
let children;
|
||||
fn(
|
||||
() =>
|
||||
createComponent(Component, {
|
||||
...props,
|
||||
get children() {
|
||||
if (childHTML != null) {
|
||||
// hydrating
|
||||
if (sharedConfig.context) {
|
||||
children = element.querySelector('astro-fragment');
|
||||
}
|
||||
const fn = client === 'only' ? render : hydrate;
|
||||
|
||||
if (children == null) {
|
||||
children = document.createElement('astro-fragment');
|
||||
children.innerHTML = childHTML;
|
||||
// Perform actual hydration
|
||||
let children;
|
||||
fn(
|
||||
() =>
|
||||
createComponent(Component, {
|
||||
...props,
|
||||
get children() {
|
||||
if (childHTML != null) {
|
||||
// hydrating
|
||||
if (sharedConfig.context) {
|
||||
children = element.querySelector('astro-fragment');
|
||||
}
|
||||
|
||||
if (children == null) {
|
||||
children = document.createElement('astro-fragment');
|
||||
children.innerHTML = childHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
return children;
|
||||
},
|
||||
}),
|
||||
element
|
||||
);
|
||||
};
|
||||
return children;
|
||||
},
|
||||
}),
|
||||
element
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
import { h, createSSRApp, createApp } from 'vue';
|
||||
import StaticHtml from './static-html.js';
|
||||
|
||||
export default (element) => (Component, props, children, { client }) => {
|
||||
delete props['class'];
|
||||
if (!element.hasAttribute('ssr')) return;
|
||||
export default (element) =>
|
||||
(Component, props, children, { client }) => {
|
||||
delete props['class'];
|
||||
if (!element.hasAttribute('ssr')) return;
|
||||
|
||||
// Expose name on host component for Vue devtools
|
||||
const name = Component.name ? `${Component.name} Host` : undefined;
|
||||
const slots = {};
|
||||
if (children != null) {
|
||||
slots.default = () => h(StaticHtml, { value: children });
|
||||
}
|
||||
if (client === 'only') {
|
||||
const app = createApp({ name, render: () => h(Component, props, slots) });
|
||||
app.mount(element, false);
|
||||
} else {
|
||||
const app = createSSRApp({ name, render: () => h(Component, props, slots) });
|
||||
app.mount(element, true);
|
||||
}
|
||||
};
|
||||
// Expose name on host component for Vue devtools
|
||||
const name = Component.name ? `${Component.name} Host` : undefined;
|
||||
const slots = {};
|
||||
if (children != null) {
|
||||
slots.default = () => h(StaticHtml, { value: children });
|
||||
}
|
||||
if (client === 'only') {
|
||||
const app = createApp({ name, render: () => h(Component, props, slots) });
|
||||
app.mount(element, false);
|
||||
} else {
|
||||
const app = createSSRApp({ name, render: () => h(Component, props, slots) });
|
||||
app.mount(element, true);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue