[ci] format

This commit is contained in:
natemoo-re 2022-08-10 19:13:28 +00:00 committed by fredkbot
parent bfbd32588f
commit d186c406b9
4 changed files with 38 additions and 29 deletions

View file

@ -1,5 +1,5 @@
import { sharedConfig } from 'solid-js'; import { sharedConfig } from 'solid-js';
import { hydrate, render, createComponent } from 'solid-js/web'; import { createComponent, hydrate, render } from 'solid-js/web';
export default (element: HTMLElement) => export default (element: HTMLElement) =>
(Component: any, props: any, slotted: any, { client }: { client: string }) => { (Component: any, props: any, slotted: any, { client }: { client: string }) => {
@ -39,7 +39,7 @@ export default (element: HTMLElement) =>
}), }),
element, element,
{ {
renderId renderId,
} }
); );
}; };

View file

@ -3,7 +3,7 @@ import type { RendererContext } from './types';
type Context = { type Context = {
id: string; id: string;
c: number; c: number;
} };
const contexts = new WeakMap<RendererContext['result'], Context>(); const contexts = new WeakMap<RendererContext['result'], Context>();
@ -15,7 +15,7 @@ export function getContext(result: RendererContext['result']): Context {
c: 0, c: 0,
get id() { get id() {
return 's' + this.c.toString(); return 's' + this.c.toString();
} },
}; };
contexts.set(result, ctx); contexts.set(result, ctx);
return ctx; return ctx;

View file

@ -1,6 +1,6 @@
import type { RendererContext } from './types'; import { createComponent, renderToString, ssr } from 'solid-js/web';
import { renderToString, ssr, createComponent } from 'solid-js/web';
import { getContext, incrementId } from './context.js'; import { getContext, incrementId } from './context.js';
import type { RendererContext } from './types';
const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase()); const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
@ -10,10 +10,17 @@ function check(this: RendererContext, Component: any, props: Record<string, any>
return typeof html === 'string'; return typeof html === 'string';
} }
function renderToStaticMarkup(this: RendererContext, Component: any, props: Record<string, any>, { default: children, ...slotted }: any, metadata?: undefined | Record<string, any>) { function renderToStaticMarkup(
this: RendererContext,
Component: any,
props: Record<string, any>,
{ default: children, ...slotted }: any,
metadata?: undefined | Record<string, any>
) {
const renderId = metadata?.hydrate ? incrementId(getContext(this.result)) : ''; const renderId = metadata?.hydrate ? incrementId(getContext(this.result)) : '';
const html = renderToString(() => { const html = renderToString(
() => {
const slots: Record<string, any> = {}; const slots: Record<string, any> = {};
for (const [key, value] of Object.entries(slotted)) { for (const [key, value] of Object.entries(slotted)) {
const name = slotName(key); const name = slotName(key);
@ -28,14 +35,16 @@ function renderToStaticMarkup(this: RendererContext, Component: any, props: Reco
}; };
return createComponent(Component, newProps); return createComponent(Component, newProps);
}, { },
renderId {
}); renderId,
}
);
return { return {
attrs: { attrs: {
'data-solid-render-id': renderId 'data-solid-render-id': renderId,
}, },
html html,
}; };
} }