mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
37021044dd
* Render async SolidJS components * Add renderer-specific hydration script to allow for proper SolidJS hydration * Add support for Solid.js 1.8.x * Address documentation feedback * Rebuild pnpm lock file based on main branch * Address PR feedback from ematipico --------- Co-authored-by: Johannes Spohr <johannes.spohr@futurice.com> Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
28 lines
529 B
TypeScript
28 lines
529 B
TypeScript
import type { RendererContext } from './types.js';
|
|
|
|
type Context = {
|
|
id: string;
|
|
c: number;
|
|
};
|
|
|
|
const contexts = new WeakMap<RendererContext['result'], Context>();
|
|
|
|
export function getContext(result: RendererContext['result']): Context {
|
|
if (contexts.has(result)) {
|
|
return contexts.get(result)!;
|
|
}
|
|
let ctx: Context = {
|
|
c: 0,
|
|
get id() {
|
|
return 's' + this.c.toString();
|
|
},
|
|
};
|
|
contexts.set(result, ctx);
|
|
return ctx;
|
|
}
|
|
|
|
export function incrementId(ctx: Context): string {
|
|
let id = ctx.id;
|
|
ctx.c++;
|
|
return id;
|
|
}
|