revojs 0.0.15 → 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>;
@@ -68,10 +68,10 @@ export interface CustomElementConstructor<TEvents extends Events, TAttributes ex
68
68
  new (): CustomElement<TEvents, TAttributes>;
69
69
  }
70
70
  export declare const isTemplate: (value: object) => value is Template;
71
- export declare const createElement: <TEvents extends Events, TAttributes extends Attributes>(input: string | ComponentConstructor<TEvents, TAttributes>, attributes?: AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
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();
@@ -216,7 +212,8 @@ const isTemplate = (value) => {
216
212
  return "tag" in value && "attributes" in value && "children" in value;
217
213
  };
218
214
  const createElement = (input, attributes, ...children) => {
219
- return {
215
+ if (typeof input === "object") return input;
216
+ else return {
220
217
  tag: typeof input === "function" ? input.$name : input,
221
218
  attributes: attributes ?? {},
222
219
  children
@@ -367,10 +364,10 @@ const defineComponent = (options) => {
367
364
  this.host = host;
368
365
  }
369
366
  getContext = (input) => {
370
- return this.context.get(descriptor(input)) ?? {};
367
+ return this.context.get(input) ?? {};
371
368
  };
372
369
  setContext = (input, value) => {
373
- this.context.set(descriptor(input), value);
370
+ this.context.set(input, value);
374
371
  };
375
372
  onMounted = (invoke) => {
376
373
  return this.hooks.on(this.scope, MOUNTED_HOOK, invoke);
@@ -457,7 +454,7 @@ const isServer = () => typeof window === "undefined";
457
454
  const preventDefault = (event) => event.preventDefault();
458
455
  const stopPropagation = (event) => event.stopPropagation();
459
456
  const stopImmediatePropagation = (event) => event.stopImmediatePropagation();
460
- const MOUNTED_HOOK = defineHook("MOUNTED_HOOK");
457
+ const MOUNTED_HOOK = defineHook();
461
458
  const components = new Map();
462
459
 
463
460
  //#endregion
@@ -708,9 +705,7 @@ const createRuntime = async () => {
708
705
  if (typeof route === "object") return route.fetch(event);
709
706
  if (route) {
710
707
  const slot = await import("#virtual/client").then((module) => module.index);
711
- const context = new Map();
712
- context.set(descriptor(RUNTIME_CONTEXT), { event });
713
- return sendHtml(event, await renderToString(slot, context));
708
+ return sendHtml(event, await renderToString(slot, new Map().set(RUNTIME_CONTEXT, { event })));
714
709
  }
715
710
  } }));
716
711
  }
@@ -745,7 +740,7 @@ const createRuntime = async () => {
745
740
  }
746
741
  };
747
742
  };
748
- const RUNTIME_CONTEXT = defineContext("RUNTIME_CONTEXT");
743
+ const RUNTIME_CONTEXT = defineContext();
749
744
 
750
745
  //#endregion
751
746
  //#region src/router/index.tsx
@@ -786,4 +781,4 @@ const anchorNavigate = (event) => {
786
781
  };
787
782
 
788
783
  //#endregion
789
- 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 };
@@ -364,4 +364,4 @@ export declare namespace JSX {
364
364
  }
365
365
  export declare const svgElements: Set<string>;
366
366
  export declare const namespace: (tag: string) => "http://www.w3.org/1999/xhtml" | "http://www.w3.org/2000/svg";
367
- export declare const h: <TEvents extends import("..").Events, TAttributes extends import("..").Attributes>(input: string | import("..").ComponentConstructor<TEvents, TAttributes>, attributes?: import("..").AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
367
+ export declare const h: <TEvents extends import("..").Events, TAttributes extends import("..").Attributes>(input: string | import("..").Template | import("..").ComponentConstructor<TEvents, TAttributes>, attributes?: import("..").AttributeInput<TAttributes>, ...children: Array<Slot>) => Slot;
package/dist/jsx/index.js CHANGED
@@ -1,19 +1,20 @@
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
8
8
  //#region src/html/index.ts
9
9
  const createElement = (input, attributes, ...children) => {
10
- return {
10
+ if (typeof input === "object") return input;
11
+ else return {
11
12
  tag: typeof input === "function" ? input.$name : input,
12
13
  attributes: attributes ?? {},
13
14
  children
14
15
  };
15
16
  };
16
- const MOUNTED_HOOK = defineHook("MOUNTED_HOOK");
17
+ const MOUNTED_HOOK = defineHook();
17
18
 
18
19
  //#endregion
19
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.15",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",