summaryrefslogtreecommitdiff
path: root/packages/integrations/solid/src/context.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/solid/src/context.ts')
-rw-r--r--packages/integrations/solid/src/context.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/integrations/solid/src/context.ts b/packages/integrations/solid/src/context.ts
new file mode 100644
index 000000000..c7b6cc392
--- /dev/null
+++ b/packages/integrations/solid/src/context.ts
@@ -0,0 +1,28 @@
+import type { RendererContext } from './types';
+
+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 = {
+ 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;
+}