revojs 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,13 +45,13 @@ export interface ComponentOptions<TEvents extends Events, TAttributes extends At
45
45
  export interface Component<TEvents extends Events, TAttributes extends Attributes> {
46
46
  readonly scope: Scope;
47
47
  readonly hooks: Hooks;
48
- readonly context: Map<string, unknown>;
48
+ readonly context: Map<symbol, unknown>;
49
49
  readonly events: EventOutput<TEvents>;
50
50
  readonly attributes: State<AttributeOutput<TAttributes>>;
51
51
  readonly shadowRoot: false | ShadowRootInit;
52
52
  readonly host?: CustomElement<TEvents, TAttributes>;
53
- getContext: <T>(input: string | Descriptor<T>) => T;
54
- setContext: <T>(input: string | Descriptor<T>, value: T) => void;
53
+ getContext: <T>(input: Descriptor<T>) => T;
54
+ setContext: <T>(input: Descriptor<T>, value: T) => void;
55
55
  onMounted: (invoke: (input: HTMLElement) => void | Promise<void>) => void;
56
56
  setup: () => Slot | Promise<Slot>;
57
57
  }
@@ -59,7 +59,7 @@ export interface ComponentConstructor<TEvents extends Events, TAttributes extend
59
59
  $name: string;
60
60
  $events: TEvents;
61
61
  $attributes: TAttributes;
62
- new (input?: Input<TEvents, TAttributes>, context?: Map<string, unknown>, host?: CustomElement<TEvents, TAttributes>): Component<TEvents, TAttributes>;
62
+ new (input?: Input<TEvents, TAttributes>, context?: Map<symbol, unknown>, host?: CustomElement<TEvents, TAttributes>): Component<TEvents, TAttributes>;
63
63
  }
64
64
  export interface CustomElement<TEvents extends Events, TAttributes extends Attributes> extends HTMLElement {
65
65
  readonly component: Component<TEvents, TAttributes>;
@@ -71,7 +71,7 @@ export declare const isTemplate: (value: object) => value is Template;
71
71
  export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | Template | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
72
72
  export declare const toString: (slot: Slot) => string;
73
73
  export declare const toFragment: (nodes: Array<Node>) => DocumentFragment;
74
- export declare const renderToString: (slot: Slot, context: Map<string, unknown>) => Promise<string>;
74
+ export declare const renderToString: (slot: Slot, context: Map<symbol, unknown>) => Promise<string>;
75
75
  export declare const renderToNode: (scope: Scope, slot: Slot) => Promise<Node>;
76
76
  export declare const defineComponent: <TEvents extends Events = {}, TAttributes extends Attributes = {}>(options: ComponentOptions<TEvents, TAttributes>) => ComponentConstructor<TEvents, TAttributes>;
77
77
  export declare const toCustomElement: <TEvents extends Events = {}, TAttributes extends Attributes = {}>(component: ComponentConstructor<TEvents, TAttributes>) => CustomElementConstructor<TEvents, TAttributes>;
package/dist/index.js CHANGED
@@ -113,14 +113,13 @@ var Hooks = class {
113
113
  this.hooks = new Map();
114
114
  }
115
115
  on = (scope, input, invoke) => {
116
- const key = descriptor(input);
117
- const invokes = this.hooks.get(key) ?? new Set();
116
+ const invokes = this.hooks.get(input) ?? new Set();
118
117
  invokes.add(invoke);
119
- this.hooks.set(key, invokes);
118
+ this.hooks.set(input, invokes);
120
119
  return scope.dispose.push(() => invokes.delete(invoke));
121
120
  };
122
121
  dispatch = (input, value) => {
123
- const invokes = this.hooks.get(descriptor(input));
122
+ const invokes = this.hooks.get(input);
124
123
  if (invokes) for (const invoke of invokes) invoke(value);
125
124
  };
126
125
  };
@@ -198,14 +197,11 @@ function fromValue(value) {
198
197
  if (value instanceof Function) return fromValue(value());
199
198
  return value;
200
199
  }
201
- function descriptor(descriptor$1) {
202
- return (typeof descriptor$1 === "object" ? descriptor$1.key : descriptor$1).toString();
200
+ function defineHook() {
201
+ return Symbol();
203
202
  }
204
- function defineHook(description) {
205
- return { key: Symbol(description) };
206
- }
207
- function defineContext(description) {
208
- return { key: Symbol(description) };
203
+ function defineContext() {
204
+ return Symbol();
209
205
  }
210
206
  let activeCompute;
211
207
  const targets = new WeakMap();
@@ -368,10 +364,10 @@ const defineComponent = (options) => {
368
364
  this.host = host;
369
365
  }
370
366
  getContext = (input) => {
371
- return this.context.get(descriptor(input)) ?? {};
367
+ return this.context.get(input) ?? {};
372
368
  };
373
369
  setContext = (input, value) => {
374
- this.context.set(descriptor(input), value);
370
+ this.context.set(input, value);
375
371
  };
376
372
  onMounted = (invoke) => {
377
373
  return this.hooks.on(this.scope, MOUNTED_HOOK, invoke);
@@ -458,7 +454,7 @@ const isServer = () => typeof window === "undefined";
458
454
  const preventDefault = (event) => event.preventDefault();
459
455
  const stopPropagation = (event) => event.stopPropagation();
460
456
  const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
461
- const MOUNTED_HOOK = defineHook("MOUNTED_HOOK");
457
+ const MOUNTED_HOOK = defineHook();
462
458
  const components = new Map();
463
459
 
464
460
  //#endregion
@@ -709,9 +705,7 @@ const createRuntime = async () => {
709
705
  if (typeof route === "object") return route.fetch(event);
710
706
  if (route) {
711
707
  const slot = await import("#virtual/client").then((module) => module.index);
712
- const context = new Map();
713
- context.set(descriptor(RUNTIME_CONTEXT), { event });
714
- return sendHtml(event, await renderToString(slot, context));
708
+ return sendHtml(event, await renderToString(slot, new Map().set(RUNTIME_CONTEXT, { event })));
715
709
  }
716
710
  } }));
717
711
  }
@@ -746,7 +740,7 @@ const createRuntime = async () => {
746
740
  }
747
741
  };
748
742
  };
749
- const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
743
+ const RUNTIME_CONTEXT = defineContext();
750
744
 
751
745
  //#endregion
752
746
  //#region src/router/index.tsx
@@ -787,4 +781,4 @@ const anchorNavigate = (event) => {
787
781
  };
788
782
 
789
783
  //#endregion
790
- export { $fetch, Compute, Handler, Hooks, MOUNTED_HOOK, Outlet, RUNTIME_CONTEXT, Radix, Scope, activeCompute, anchorNavigate, components, createApp, createCompute, createElement, createEvent, createMemo, createRuntime, createState, defineComponent, defineContext, defineHook, defineRoute, descriptor, fileName, fromValue, getAssets, getCookies, getCustomElement, getGlobalStyles, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, isClient, isServer, isTemplate, markdownToSlot, navigate, preventDefault, registerComponent, renderToNode, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toCustomElement, toFragment, toPath, toString };
784
+ export { $fetch, Compute, Handler, Hooks, MOUNTED_HOOK, Outlet, RUNTIME_CONTEXT, Radix, Scope, activeCompute, anchorNavigate, components, createApp, createCompute, createElement, createEvent, createMemo, createRuntime, createState, defineComponent, defineContext, defineHook, defineRoute, fileName, fromValue, getAssets, getCookies, getCustomElement, getGlobalStyles, getMimeType, getRequestUrl, getRoutes, getSetCookies, getVariables, isClient, isServer, isTemplate, markdownToSlot, navigate, preventDefault, registerComponent, renderToNode, renderToString, sendBadRequest, sendHtml, sendJson, sendRedirect, sendText, sendUnauthorized, setCookie, stopImmediatePropagation, stopPropagation, targets, toCustomElement, toFragment, toPath, toString };
package/dist/jsx/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  //#region src/signals/index.ts
3
- function defineHook(description) {
4
- return { key: Symbol(description) };
3
+ function defineHook() {
4
+ return Symbol();
5
5
  }
6
6
 
7
7
  //#endregion
@@ -14,7 +14,7 @@ const createElement = (input, attributes, ...children) => {
14
14
  children
15
15
  };
16
16
  };
17
- const MOUNTED_HOOK = defineHook("MOUNTED_HOOK");
17
+ const MOUNTED_HOOK = defineHook();
18
18
 
19
19
  //#endregion
20
20
  //#region src/jsx/index.ts
@@ -1,15 +1,16 @@
1
+ declare const descriptor: unique symbol;
1
2
  export type Value<T> = T | (() => Value<T>);
3
+ export type Descriptor<T> = symbol & {
4
+ [descriptor]: T;
5
+ };
2
6
  export interface State<T> {
3
7
  value: T;
4
8
  }
5
- export type Descriptor<T> = {
6
- key: symbol;
7
- };
8
9
  export declare class Hooks {
9
- readonly hooks: Map<string, Set<(value: any) => unknown>>;
10
+ readonly hooks: Map<symbol, Set<(value: any) => unknown>>;
10
11
  constructor();
11
- on: <T>(scope: Scope, input: string | Descriptor<T>, invoke: (value: T) => unknown) => number;
12
- dispatch: <T>(input: string | Descriptor<T>, value: T) => void;
12
+ on: <T>(scope: Scope, input: Descriptor<T>, invoke: (value: T) => unknown) => number;
13
+ dispatch: <T>(input: Descriptor<T>, value: T) => void;
13
14
  }
14
15
  export declare class Scope {
15
16
  readonly dispose: Array<(scope: Scope) => void>;
@@ -31,8 +32,8 @@ export declare function createState<T>(value: T): State<T>;
31
32
  export declare function createCompute<T>(scope: Scope, invoke: (scope: Scope) => T): T;
32
33
  export declare function createMemo<T>(scope: Scope, invoke: () => T): State<T>;
33
34
  export declare function fromValue<T>(value: Value<T>): T;
34
- export declare function descriptor<T>(descriptor: string | Descriptor<T>): string;
35
- export declare function defineHook<T>(description?: string | number): Descriptor<T>;
36
- export declare function defineContext<T>(description?: string | number): Descriptor<T>;
35
+ export declare function defineHook<T>(): Descriptor<T>;
36
+ export declare function defineContext<T>(): Descriptor<T>;
37
37
  export declare let activeCompute: Compute | undefined;
38
38
  export declare const targets: WeakMap<object, Map<string | symbol, Set<Compute<void>>>>;
39
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",