@praxisjs/shared 0.1.0 → 0.2.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @praxisjs/shared
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bb0d4f8: **Refactor decorator system and component architecture across PraxisJS packages**
8
+
9
+ - Replaced legacy decorator signatures (`constructor`, `target`, `propertyKey`, method descriptor) with the standard TC39 decorator context API (`ClassDecoratorContext`, `ClassFieldDecoratorContext`, `ClassMethodDecoratorContext`) across `@praxisjs/decorators`, `@praxisjs/store`, `@praxisjs/concurrent`, `@praxisjs/router`, `@praxisjs/motion`, `@praxisjs/di`, and `@praxisjs/fsm`.
10
+ - Introduced `StatefulComponent` and `StatelessComponent` as the new base classes, replacing the deprecated `BaseComponent`/`Function Component` pattern, across `@praxisjs/core`, `@praxisjs/runtime`, `@praxisjs/devtools`, and templates.
11
+ - Implemented core rendering functionality in `@praxisjs/runtime` (`mountChildren`, `mountComponent`, reactive scope management) and removed the deprecated `renderer.ts`.
12
+ - Refactored `@praxisjs/jsx` to delegate rendering to `@praxisjs/runtime` and improved type safety with `flattenChildren` and `isComponent` utilities.
13
+ - Updated internal module structure with new `internal` exports in `package.json` files for shared utilities and types.
14
+ - Removed `experimentalDecorators`/`emitDecoratorMetadata` from `tsconfig.json` in favor of native decorator support.
15
+
3
16
  ## 0.1.0
4
17
 
5
18
  ### Minor Changes
@@ -1,3 +1,2 @@
1
- import type { ChildrenInternal } from "./types/children";
2
- export declare const flattenChildren: (children: ChildrenInternal | ChildrenInternal[], out?: ChildrenInternal[]) => ChildrenInternal[];
1
+ export declare const flattenChildren: (children: unknown, out?: unknown[]) => unknown[];
3
2
  //# sourceMappingURL=children.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../src/children.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,eAAO,MAAM,eAAe,GAC1B,UAAU,gBAAgB,GAAG,gBAAgB,EAAE,EAC/C,MAAK,gBAAgB,EAAO,uBAU7B,CAAC"}
1
+ {"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../src/children.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,GAAI,UAAU,OAAO,EAAE,MAAK,OAAO,EAAO,KAAG,OAAO,EAS/E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"children.js","sourceRoot":"","sources":["../src/children.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,QAA+C,EAC/C,MAA0B,EAAE,EAC5B,EAAE;IACF,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
1
+ {"version":3,"file":"children.js","sourceRoot":"","sources":["../src/children.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAiB,EAAE,MAAiB,EAAE,EAAa,EAAE;IACnF,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ComponentConstructor } from "./types/children";
2
+ export declare const isComponent: (source: unknown) => source is ComponentConstructor;
3
+ //# sourceMappingURL=component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,eAAO,MAAM,WAAW,GAAI,QAAQ,OAAO,KAAG,MAAM,IAAI,oBAEvD,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const isComponent = (source) => {
2
+ return typeof source === "function" && "__isComponent" in source;
3
+ };
4
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAe,EAAkC,EAAE;IAC7E,OAAO,OAAO,MAAM,KAAK,UAAU,IAAI,eAAe,IAAI,MAAM,CAAC;AACnE,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export { isSignal, isComputed } from "./signal";
1
+ export type { Children, ComponentElement } from "./types/children";
2
2
  export type { Computed, Signal } from "./types/signal";
3
- export { flattenChildren } from "./children";
4
- export type { VNode, Children, ChildrenInternal, FunctionComponent, ComponentConstructor, ComponentInstance, Component, } from "./types/children";
5
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAChD,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EACV,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,GACV,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACnE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
- export { isSignal, isComputed } from "./signal";
2
- export { flattenChildren } from "./children";
1
+ export {};
3
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export { isSignal, isComputed, isReactive } from "./signal";
2
+ export { flattenChildren } from "./children";
3
+ export type { ComponentConstructor, ComponentInstance, Cleanup, } from "./types/children";
4
+ export type { BaseReactive } from "./types/signal";
5
+ export { isComponent } from "./component";
6
+ export type { ReactiveChildren } from "./types/children";
7
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,OAAO,GACR,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { isSignal, isComputed, isReactive } from "./signal";
2
+ export { flattenChildren } from "./children";
3
+ export { isComponent } from "./component";
4
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAO7C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
package/dist/signal.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Computed, Signal } from "./types/signal";
2
- export declare function isSignal<T>(source: Signal<T> | Computed<T> | (() => T)): boolean;
3
- export declare function isComputed(source: unknown): source is Function & Record<"subscribe", unknown>;
1
+ export declare function isSignal(source: unknown): boolean;
2
+ export declare function isComputed(source: unknown): source is Function & Record<"__isComputed", unknown>;
3
+ export declare function isReactive(source: unknown): boolean;
4
4
  //# sourceMappingURL=signal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEvD,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAC1C,OAAO,CAET;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,qDAEzC"}
1
+ {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AACA,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAEjD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,wDAEzC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,WAEzC"}
package/dist/signal.js CHANGED
@@ -1,7 +1,10 @@
1
1
  export function isSignal(source) {
2
- return typeof source.set === "function";
2
+ return typeof source === "function" && "__isSignal" in source;
3
3
  }
4
4
  export function isComputed(source) {
5
- return typeof source === "function" && "subscribe" in source;
5
+ return typeof source === "function" && "__isComputed" in source;
6
+ }
7
+ export function isReactive(source) {
8
+ return isComputed(source) || isSignal(source);
6
9
  }
7
10
  //# sourceMappingURL=signal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signal.js","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CACtB,MAA2C;IAE3C,OAAO,OAAQ,MAAoB,CAAC,GAAG,KAAK,UAAU,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAe;IACxC,OAAO,OAAO,MAAM,KAAK,UAAU,IAAI,WAAW,IAAI,MAAM,CAAC;AAC/D,CAAC"}
1
+ {"version":3,"file":"signal.js","sourceRoot":"","sources":["../src/signal.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,QAAQ,CAAC,MAAe;IACtC,OAAO,OAAO,MAAM,KAAK,UAAU,IAAI,YAAY,IAAI,MAAM,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAe;IACxC,OAAO,OAAO,MAAM,KAAK,UAAU,IAAI,cAAc,IAAI,MAAM,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAe;IACxC,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC"}
@@ -1,29 +1,22 @@
1
+ import type { Computed, Signal } from "./signal";
1
2
  export type Primitive = string | number | boolean | bigint | symbol | null | undefined;
2
- export type ReactiveChildren = () => Primitive | VNode | VNode[] | ReactiveChildren[];
3
- export type ChildrenInternal = Primitive | VNode | ReactiveChildren | ChildrenInternal[];
4
- export type Children = ChildrenInternal | ChildrenInternal[];
5
- export type Component = FunctionComponent | ComponentConstructor;
6
- export interface VNode {
7
- type: string | Component;
8
- props: Record<string, unknown>;
9
- children: ChildrenInternal[];
10
- key?: string | number;
11
- }
12
- export type FunctionComponent<P = Record<string, unknown>> = (props: P & {
13
- children?: Children;
14
- }) => VNode | null;
3
+ export type RenderedValue = Primitive | Signal<unknown> | Computed<unknown> | Node | Node[];
4
+ export type ReactiveChildren = () => RenderedValue | RenderedValue[] | ReactiveChildren[];
5
+ export type Children = Primitive | Node | ReactiveChildren | Children[];
6
+ export type Cleanup = () => void;
15
7
  export interface ComponentConstructor<P = Record<string, unknown>> {
16
8
  new (props: P): ComponentInstance;
17
- isComponent: true;
9
+ __isComponent: true;
10
+ __isStateless: boolean;
11
+ name: string;
18
12
  }
13
+ export type ComponentElement = new (...args: any[]) => ComponentInstance;
19
14
  export interface ComponentInstance {
20
15
  _mounted: boolean;
21
- _stateDirty: boolean;
22
- _lastResolvedProps?: Record<string, unknown>;
23
- _isMemorized?: boolean;
24
- _arePropsEqual?: (prevProps: Record<string, unknown>, nextProps: Record<string, unknown>) => boolean;
16
+ _anchor?: Comment;
17
+ _stateDirty?: boolean;
25
18
  _setProps(p: Record<string, unknown>): void;
26
- render(): VNode | null;
19
+ render(): Node | Node[] | null;
27
20
  onBeforeMount?(): void;
28
21
  onMount?(): void;
29
22
  onUnmount?(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../../src/types/children.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,GACN,IAAI,GACJ,SAAS,CAAC;AAEd,MAAM,MAAM,gBAAgB,GAAG,MAC3B,SAAS,GACT,KAAK,GACL,KAAK,EAAE,GACP,gBAAgB,EA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AAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5C,MAAM,IAAI,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC/B,aAAa,CAAC,IAAI,IAAI,CAAC;IACvB,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,SAAS,CAAC,IAAI,IAAI,CAAC;IACnB,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CAC1B"}
@@ -1,11 +1,13 @@
1
- export interface Computed<T> {
1
+ export interface BaseReactive<T> {
2
2
  (): T;
3
3
  subscribe(effect: (value: T) => void): () => void;
4
4
  }
5
- export interface Signal<T> {
6
- (): T;
5
+ export interface Computed<T> extends BaseReactive<T> {
6
+ __isComputed: true;
7
+ }
8
+ export interface Signal<T> extends BaseReactive<T> {
7
9
  set(value: T): void;
8
10
  update(updater: (prev: T) => T): void;
9
- subscribe(effect: (value: T) => void): () => void;
11
+ __isSignal: true;
10
12
  }
11
13
  //# sourceMappingURL=signal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/types/signal.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,IAAI,CAAC,CAAC;IACN,SAAS,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,IAAI,CAAC,CAAC;IACN,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACtC,SAAS,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACnD"}
1
+ {"version":3,"file":"signal.d.ts","sourceRoot":"","sources":["../../src/types/signal.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,IAAI,CAAC,CAAC;IACN,SAAS,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACnD;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAClD,YAAY,EAAE,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;IAChD,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACtC,UAAU,EAAE,IAAI,CAAC;CAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praxisjs/shared",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,6 +8,10 @@
8
8
  ".": {
9
9
  "import": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts"
11
+ },
12
+ "./internal": {
13
+ "import": "./dist/internal.js",
14
+ "types": "./dist/internal.d.ts"
11
15
  }
12
16
  },
13
17
  "devDependencies": {
package/src/children.ts CHANGED
@@ -1,9 +1,4 @@
1
- import type { ChildrenInternal } from "./types/children";
2
-
3
- export const flattenChildren = (
4
- children: ChildrenInternal | ChildrenInternal[],
5
- out: ChildrenInternal[] = [],
6
- ) => {
1
+ export const flattenChildren = (children: unknown, out: unknown[] = []): unknown[] => {
7
2
  if (Array.isArray(children)) {
8
3
  for (const child of children) {
9
4
  flattenChildren(child, out);
@@ -0,0 +1,5 @@
1
+ import type { ComponentConstructor } from "./types/children";
2
+
3
+ export const isComponent = (source: unknown): source is ComponentConstructor => {
4
+ return typeof source === "function" && "__isComponent" in source;
5
+ };
package/src/index.ts CHANGED
@@ -1,12 +1,2 @@
1
- export { isSignal, isComputed } from "./signal";
1
+ export type { Children, ComponentElement } from "./types/children";
2
2
  export type { Computed, Signal } from "./types/signal";
3
- export { flattenChildren } from "./children";
4
- export type {
5
- VNode,
6
- Children,
7
- ChildrenInternal,
8
- FunctionComponent,
9
- ComponentConstructor,
10
- ComponentInstance,
11
- Component,
12
- } from "./types/children";
@@ -0,0 +1,10 @@
1
+ export { isSignal, isComputed, isReactive } from "./signal";
2
+ export { flattenChildren } from "./children";
3
+ export type {
4
+ ComponentConstructor,
5
+ ComponentInstance,
6
+ Cleanup,
7
+ } from "./types/children";
8
+ export type { BaseReactive } from "./types/signal";
9
+ export { isComponent } from "./component";
10
+ export type { ReactiveChildren } from "./types/children";
package/src/signal.ts CHANGED
@@ -1,11 +1,12 @@
1
- import type { Computed, Signal } from "./types/signal";
2
1
 
3
- export function isSignal<T>(
4
- source: Signal<T> | Computed<T> | (() => T),
5
- ): boolean {
6
- return typeof (source as Signal<T>).set === "function";
2
+ export function isSignal(source: unknown): boolean {
3
+ return typeof source === "function" && "__isSignal" in source;
7
4
  }
8
5
 
9
6
  export function isComputed(source: unknown) {
10
- return typeof source === "function" && "subscribe" in source;
7
+ return typeof source === "function" && "__isComputed" in source;
8
+ }
9
+
10
+ export function isReactive(source: unknown) {
11
+ return isComputed(source) || isSignal(source);
11
12
  }
@@ -1,3 +1,5 @@
1
+ import type { Computed, Signal } from "./signal";
2
+
1
3
  export type Primitive =
2
4
  | string
3
5
  | number
@@ -7,49 +9,38 @@ export type Primitive =
7
9
  | null
8
10
  | undefined;
9
11
 
10
- export type ReactiveChildren = () =>
11
- | Primitive
12
- | VNode
13
- | VNode[]
14
- | ReactiveChildren[];
15
-
16
- export type ChildrenInternal =
12
+ export type RenderedValue =
17
13
  | Primitive
18
- | VNode
19
- | ReactiveChildren
20
- | ChildrenInternal[];
14
+ | Signal<unknown>
15
+ | Computed<unknown>
16
+ | Node
17
+ | Node[];
21
18
 
22
- export type Children = ChildrenInternal | ChildrenInternal[];
19
+ export type ReactiveChildren = () =>
20
+ | RenderedValue
21
+ | RenderedValue[]
22
+ | ReactiveChildren[];
23
23
 
24
- export type Component = FunctionComponent | ComponentConstructor;
24
+ export type Children = Primitive | Node | ReactiveChildren | Children[];
25
25
 
26
- export interface VNode {
27
- type: string | Component;
28
- props: Record<string, unknown>;
29
- children: ChildrenInternal[];
30
- key?: string | number;
31
- }
32
-
33
- export type FunctionComponent<P = Record<string, unknown>> = (
34
- props: P & { children?: Children },
35
- ) => VNode | null;
26
+ export type Cleanup = () => void;
36
27
 
37
28
  export interface ComponentConstructor<P = Record<string, unknown>> {
38
29
  new (props: P): ComponentInstance;
39
- isComponent: true;
30
+ __isComponent: true;
31
+ __isStateless: boolean;
32
+ name: string;
40
33
  }
41
34
 
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ export type ComponentElement = new (...args: any[]) => ComponentInstance;
37
+
42
38
  export interface ComponentInstance {
43
39
  _mounted: boolean;
44
- _stateDirty: boolean;
45
- _lastResolvedProps?: Record<string, unknown>;
46
- _isMemorized?: boolean;
47
- _arePropsEqual?: (
48
- prevProps: Record<string, unknown>,
49
- nextProps: Record<string, unknown>,
50
- ) => boolean;
40
+ _anchor?: Comment;
41
+ _stateDirty?: boolean;
51
42
  _setProps(p: Record<string, unknown>): void;
52
- render(): VNode | null;
43
+ render(): Node | Node[] | null;
53
44
  onBeforeMount?(): void;
54
45
  onMount?(): void;
55
46
  onUnmount?(): void;
@@ -1,11 +1,14 @@
1
- export interface Computed<T> {
1
+ export interface BaseReactive<T> {
2
2
  (): T;
3
3
  subscribe(effect: (value: T) => void): () => void;
4
4
  }
5
5
 
6
- export interface Signal<T> {
7
- (): T;
6
+ export interface Computed<T> extends BaseReactive<T> {
7
+ __isComputed: true;
8
+ }
9
+
10
+ export interface Signal<T> extends BaseReactive<T> {
8
11
  set(value: T): void;
9
12
  update(updater: (prev: T) => T): void;
10
- subscribe(effect: (value: T) => void): () => void;
13
+ __isSignal: true;
11
14
  }