@logixjs/react 0.1.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.
Files changed (42) hide show
  1. package/README.md +64 -0
  2. package/dist/Hooks.cjs +2194 -0
  3. package/dist/Hooks.d.cts +77 -0
  4. package/dist/Hooks.d.ts +77 -0
  5. package/dist/Hooks.js +27 -0
  6. package/dist/ModuleRef-wZSQ3Wwo.d.cts +73 -0
  7. package/dist/ModuleRef-wZSQ3Wwo.d.ts +73 -0
  8. package/dist/ModuleScope.cjs +2695 -0
  9. package/dist/ModuleScope.d.cts +62 -0
  10. package/dist/ModuleScope.d.ts +62 -0
  11. package/dist/ModuleScope.js +9 -0
  12. package/dist/Platform.cjs +60 -0
  13. package/dist/Platform.d.cts +6 -0
  14. package/dist/Platform.d.ts +6 -0
  15. package/dist/Platform.js +6 -0
  16. package/dist/ReactPlatform.cjs +2813 -0
  17. package/dist/ReactPlatform.d.cts +40 -0
  18. package/dist/ReactPlatform.d.ts +40 -0
  19. package/dist/ReactPlatform.js +11 -0
  20. package/dist/RuntimeProvider.cjs +1618 -0
  21. package/dist/RuntimeProvider.d.cts +66 -0
  22. package/dist/RuntimeProvider.d.ts +66 -0
  23. package/dist/RuntimeProvider.js +8 -0
  24. package/dist/chunk-2WFULYPJ.js +856 -0
  25. package/dist/chunk-4G7H66OY.js +54 -0
  26. package/dist/chunk-G5MRIFKK.js +95 -0
  27. package/dist/chunk-JXAJTWSZ.js +773 -0
  28. package/dist/chunk-PYWHL7TA.js +351 -0
  29. package/dist/chunk-UFFCJGSZ.js +981 -0
  30. package/dist/chunk-VFWWMK67.js +0 -0
  31. package/dist/chunk-ZANGOPUQ.js +34 -0
  32. package/dist/global.d.cjs +1 -0
  33. package/dist/global.d.d.cts +9 -0
  34. package/dist/global.d.d.ts +9 -0
  35. package/dist/global.d.js +0 -0
  36. package/dist/index.cjs +3118 -0
  37. package/dist/index.d.cts +10 -0
  38. package/dist/index.d.ts +10 -0
  39. package/dist/index.js +44 -0
  40. package/dist/useDispatch-BnzYVkRE.d.ts +81 -0
  41. package/dist/useDispatch-CnO5-66H.d.cts +81 -0
  42. package/package.json +58 -0
@@ -0,0 +1,77 @@
1
+ import { Layer, ManagedRuntime, Effect } from 'effect';
2
+ export { c as useDispatch, a as useLocalModule, u as useModule, b as useSelector } from './useDispatch-CnO5-66H.cjs';
3
+ import React from 'react';
4
+ import * as Logix from '@logixjs/core';
5
+ import { c as ModuleRef, b as ModuleDispatchersOfShape } from './ModuleRef-wZSQ3Wwo.cjs';
6
+ export { M as ModuleActions, a as ModuleDispatchers } from './ModuleRef-wZSQ3Wwo.cjs';
7
+
8
+ interface UseRuntimeOptions {
9
+ readonly layer?: Layer.Layer<any, any, never>;
10
+ readonly layers?: ReadonlyArray<Layer.Layer<any, any, never>>;
11
+ }
12
+ declare function useRuntime(): ManagedRuntime.ManagedRuntime<any, any>;
13
+ declare function useRuntime(options: UseRuntimeOptions): ManagedRuntime.ManagedRuntime<any, any>;
14
+
15
+ /**
16
+ * Creates a local ModuleRuntime from an already assembled Module Layer (e.g. RegionLive).
17
+ *
18
+ * Use cases:
19
+ * - On the effect side, you already built the full Layer via `Module.live(initial, ...logics)`.
20
+ * - A React component wants to "just consume" that Layer without caring about initial/logics details.
21
+ */
22
+ declare function useLayerModule<Id extends string, Sh extends Logix.AnyModuleShape>(module: Logix.ModuleTagType<Id, Sh>, layer: Layer.Layer<Logix.ModuleRuntime<Logix.StateOf<Sh>, Logix.ActionOf<Sh>>, never, any>, deps?: React.DependencyList): ModuleRef<Logix.StateOf<Sh>, Logix.ActionOf<Sh>>;
23
+
24
+ /**
25
+ * A hook to manage a dynamic list of Module instances.
26
+ * It ensures that the Module instance for a given ID remains stable across renders,
27
+ * which is crucial for preserving the identity of the module (and its state/subscriptions).
28
+ *
29
+ * @param items The source data array.
30
+ * @param keyFn A function to extract a unique key (ID) from an item.
31
+ * @param factory A function to create a new Module instance for a given ID and item.
32
+ * @returns An array of Module instances corresponding to the items.
33
+ */
34
+ declare function useModuleList<T, M>(items: T[], keyFn: (item: T) => string, factory: (id: string, item: T) => M): M[];
35
+
36
+ /**
37
+ * Resolves a child module runtime provided by imports from the "parent module instance scope".
38
+ *
39
+ * Typical usage:
40
+ * - const host = useModule(HostImpl, { key })
41
+ * - const query = useImportedModule(host, SearchQuery.tag)
42
+ * - const status = useSelector(query, s => s.search.status)
43
+ */
44
+ declare function useImportedModule<Id extends string, Sh extends Logix.AnyModuleShape>(parent: Logix.ModuleRuntime<any, any> | ModuleRef<any, any>, module: Logix.ModuleTagType<Id, Sh>): ModuleRef<Logix.StateOf<Sh>, Logix.ActionOf<Sh>, keyof Sh['actionMap'] & string, Logix.ModuleTagType<Id, Sh>, ModuleDispatchersOfShape<Sh>>;
45
+
46
+ interface UseProcessesOptions {
47
+ /**
48
+ * Stable identifier for a UI subtree scope.
49
+ *
50
+ * - Recommended: a domain boundary id (e.g. route / feature key) for diagnostics and filtering.
51
+ * - Default: derived from React.useId() (stable for the same tree position; reusable under StrictMode).
52
+ */
53
+ readonly subtreeId?: string;
54
+ /**
55
+ * Keep-alive time (ms) after unmount, to absorb StrictMode / Suspense jitter:
56
+ * - We do not stop immediately on unmount; we close the scope after gcTime (and refCount is still 0).
57
+ */
58
+ readonly gcTime?: number;
59
+ /**
60
+ * Restart semantics for stop -> start:
61
+ * - switch (default): if the previous instance is still stopping, ensure the "current install intent" resumes after stopping finishes.
62
+ * - exhaust: ignore this install while stopping; it will only resume on the next install.
63
+ */
64
+ readonly mode?: 'switch' | 'exhaust';
65
+ readonly deps?: React.DependencyList;
66
+ }
67
+ declare function useProcesses(processes: ReadonlyArray<Effect.Effect<void, any, any>>, options?: UseProcessesOptions): void;
68
+
69
+ /**
70
+ * `shallow`: a common `useSelector(..., equalityFn)` implementation.
71
+ *
72
+ * Semantics: shallow-compare Array / Object / Map / Set (uses `Object.is` for leaf values),
73
+ * useful when a selector returns a "new object/array" with unchanged contents to skip meaningless re-renders.
74
+ */
75
+ declare const shallow: <T>(previous: T, next: T) => boolean;
76
+
77
+ export { ModuleDispatchersOfShape, ModuleRef, type UseProcessesOptions, type UseRuntimeOptions, shallow, useImportedModule, useLayerModule, useModuleList, useProcesses, useRuntime };
@@ -0,0 +1,77 @@
1
+ import { Layer, ManagedRuntime, Effect } from 'effect';
2
+ export { c as useDispatch, a as useLocalModule, u as useModule, b as useSelector } from './useDispatch-BnzYVkRE.js';
3
+ import React from 'react';
4
+ import * as Logix from '@logixjs/core';
5
+ import { c as ModuleRef, b as ModuleDispatchersOfShape } from './ModuleRef-wZSQ3Wwo.js';
6
+ export { M as ModuleActions, a as ModuleDispatchers } from './ModuleRef-wZSQ3Wwo.js';
7
+
8
+ interface UseRuntimeOptions {
9
+ readonly layer?: Layer.Layer<any, any, never>;
10
+ readonly layers?: ReadonlyArray<Layer.Layer<any, any, never>>;
11
+ }
12
+ declare function useRuntime(): ManagedRuntime.ManagedRuntime<any, any>;
13
+ declare function useRuntime(options: UseRuntimeOptions): ManagedRuntime.ManagedRuntime<any, any>;
14
+
15
+ /**
16
+ * Creates a local ModuleRuntime from an already assembled Module Layer (e.g. RegionLive).
17
+ *
18
+ * Use cases:
19
+ * - On the effect side, you already built the full Layer via `Module.live(initial, ...logics)`.
20
+ * - A React component wants to "just consume" that Layer without caring about initial/logics details.
21
+ */
22
+ declare function useLayerModule<Id extends string, Sh extends Logix.AnyModuleShape>(module: Logix.ModuleTagType<Id, Sh>, layer: Layer.Layer<Logix.ModuleRuntime<Logix.StateOf<Sh>, Logix.ActionOf<Sh>>, never, any>, deps?: React.DependencyList): ModuleRef<Logix.StateOf<Sh>, Logix.ActionOf<Sh>>;
23
+
24
+ /**
25
+ * A hook to manage a dynamic list of Module instances.
26
+ * It ensures that the Module instance for a given ID remains stable across renders,
27
+ * which is crucial for preserving the identity of the module (and its state/subscriptions).
28
+ *
29
+ * @param items The source data array.
30
+ * @param keyFn A function to extract a unique key (ID) from an item.
31
+ * @param factory A function to create a new Module instance for a given ID and item.
32
+ * @returns An array of Module instances corresponding to the items.
33
+ */
34
+ declare function useModuleList<T, M>(items: T[], keyFn: (item: T) => string, factory: (id: string, item: T) => M): M[];
35
+
36
+ /**
37
+ * Resolves a child module runtime provided by imports from the "parent module instance scope".
38
+ *
39
+ * Typical usage:
40
+ * - const host = useModule(HostImpl, { key })
41
+ * - const query = useImportedModule(host, SearchQuery.tag)
42
+ * - const status = useSelector(query, s => s.search.status)
43
+ */
44
+ declare function useImportedModule<Id extends string, Sh extends Logix.AnyModuleShape>(parent: Logix.ModuleRuntime<any, any> | ModuleRef<any, any>, module: Logix.ModuleTagType<Id, Sh>): ModuleRef<Logix.StateOf<Sh>, Logix.ActionOf<Sh>, keyof Sh['actionMap'] & string, Logix.ModuleTagType<Id, Sh>, ModuleDispatchersOfShape<Sh>>;
45
+
46
+ interface UseProcessesOptions {
47
+ /**
48
+ * Stable identifier for a UI subtree scope.
49
+ *
50
+ * - Recommended: a domain boundary id (e.g. route / feature key) for diagnostics and filtering.
51
+ * - Default: derived from React.useId() (stable for the same tree position; reusable under StrictMode).
52
+ */
53
+ readonly subtreeId?: string;
54
+ /**
55
+ * Keep-alive time (ms) after unmount, to absorb StrictMode / Suspense jitter:
56
+ * - We do not stop immediately on unmount; we close the scope after gcTime (and refCount is still 0).
57
+ */
58
+ readonly gcTime?: number;
59
+ /**
60
+ * Restart semantics for stop -> start:
61
+ * - switch (default): if the previous instance is still stopping, ensure the "current install intent" resumes after stopping finishes.
62
+ * - exhaust: ignore this install while stopping; it will only resume on the next install.
63
+ */
64
+ readonly mode?: 'switch' | 'exhaust';
65
+ readonly deps?: React.DependencyList;
66
+ }
67
+ declare function useProcesses(processes: ReadonlyArray<Effect.Effect<void, any, any>>, options?: UseProcessesOptions): void;
68
+
69
+ /**
70
+ * `shallow`: a common `useSelector(..., equalityFn)` implementation.
71
+ *
72
+ * Semantics: shallow-compare Array / Object / Map / Set (uses `Object.is` for leaf values),
73
+ * useful when a selector returns a "new object/array" with unchanged contents to skip meaningless re-renders.
74
+ */
75
+ declare const shallow: <T>(previous: T, next: T) => boolean;
76
+
77
+ export { ModuleDispatchersOfShape, ModuleRef, type UseProcessesOptions, type UseRuntimeOptions, shallow, useImportedModule, useLayerModule, useModuleList, useProcesses, useRuntime };
package/dist/Hooks.js ADDED
@@ -0,0 +1,27 @@
1
+ import {
2
+ useDispatch,
3
+ useImportedModule,
4
+ useLayerModule,
5
+ useLocalModule,
6
+ useModuleList,
7
+ useProcesses
8
+ } from "./chunk-PYWHL7TA.js";
9
+ import {
10
+ shallow,
11
+ useModule,
12
+ useRuntime,
13
+ useSelector
14
+ } from "./chunk-UFFCJGSZ.js";
15
+ import "./chunk-2WFULYPJ.js";
16
+ export {
17
+ shallow,
18
+ useDispatch,
19
+ useImportedModule,
20
+ useLayerModule,
21
+ useLocalModule,
22
+ useModule,
23
+ useModuleList,
24
+ useProcesses,
25
+ useRuntime,
26
+ useSelector
27
+ };
@@ -0,0 +1,73 @@
1
+ import * as Logix from '@logixjs/core';
2
+
3
+ type Dispatch<A> = ((action: A) => void) & {
4
+ readonly batch: (actions: ReadonlyArray<A>) => void;
5
+ readonly lowPriority: (action: A) => void;
6
+ };
7
+ type ActionArgs<P> = [P] extends [void] ? [] | [P] : [P];
8
+ type ActionFn<P, Out> = (...args: ActionArgs<P>) => Out;
9
+ type ActionTag<A> = A extends {
10
+ readonly _tag: infer T;
11
+ } ? T : A extends {
12
+ readonly type: infer T;
13
+ } ? T : never;
14
+ type ActionTags<A> = Extract<ActionTag<A>, string>;
15
+ type ActionPayload<A, K> = Extract<A, {
16
+ readonly _tag: K;
17
+ } | {
18
+ readonly type: K;
19
+ }> extends {
20
+ readonly payload?: infer P;
21
+ } ? P : never;
22
+ type AnyActionToken = Logix.Action.ActionToken<string, any, any>;
23
+ type ModuleDispatchersOfShape<Sh extends Logix.AnyModuleShape> = Sh['actionMap'];
24
+ type ModuleActions<A, Tags extends string = ActionTags<A>> = {
25
+ readonly dispatch: Dispatch<A>;
26
+ } & ([ActionTags<A>] extends [never] ? {} : {
27
+ readonly [K in Tags & ActionTags<A>]: ActionFn<ActionPayload<A, K>, void>;
28
+ });
29
+ type ActionMapOfDef<Def> = Def extends {
30
+ readonly actions: infer ActionMap;
31
+ } ? ActionMap : never;
32
+ type ModuleDispatchers<A, Tags extends string = ActionTags<A>, Def = unknown> = [ActionMapOfDef<Def>] extends [
33
+ never
34
+ ] ? [ActionTags<A>] extends [never] ? {} : {
35
+ readonly [K in Tags & ActionTags<A>]: ActionFn<ActionPayload<A, K>, Extract<A, {
36
+ readonly _tag: K;
37
+ } | {
38
+ readonly type: K;
39
+ }>>;
40
+ } : ActionMapOfDef<Def> extends Record<string, AnyActionToken> ? ActionMapOfDef<Def> : [ActionTags<A>] extends [never] ? {} : {
41
+ readonly [K in Tags & ActionTags<A>]: ActionFn<ActionPayload<A, K>, Extract<A, {
42
+ readonly _tag: K;
43
+ } | {
44
+ readonly type: K;
45
+ }>>;
46
+ };
47
+ interface ModuleImports {
48
+ readonly get: <Id extends string, Sh extends Logix.AnyModuleShape>(module: Logix.ModuleTagType<Id, Sh>) => ModuleRef<Logix.StateOf<Sh>, Logix.ActionOf<Sh>, keyof Sh['actionMap'] & string, Logix.ModuleTagType<Id, Sh>, ModuleDispatchersOfShape<Sh>>;
49
+ }
50
+ interface ModuleRef<S, A, Tags extends string = ActionTags<A>, Def = unknown, Dispatchers = ModuleDispatchers<A, Tags, Def>> {
51
+ /**
52
+ * Definition anchor (typically a ModuleTag) for reflecting actions/reducers/source and other metadata.
53
+ * - DX: when `runtime.actions.*` can't jump to source, use `ref.def?.reducers?.xxx` / `ref.def?.actions.xxx` to locate definitions quickly.
54
+ */
55
+ readonly def?: Def;
56
+ readonly runtime: Logix.ModuleRuntime<S, A>;
57
+ readonly dispatch: Dispatch<A>;
58
+ readonly actions: ModuleActions<A, Tags>;
59
+ readonly dispatchers: Dispatchers;
60
+ /**
61
+ * Fractal module imports sugar:
62
+ * - host.imports.get(ChildModule) resolves a child module instance within the host instance scope.
63
+ * - strict by default: throws when scope is missing, avoiding accidentally routing to a global instance.
64
+ */
65
+ readonly imports: ModuleImports;
66
+ readonly getState: Logix.ModuleRuntime<S, A>['getState'];
67
+ readonly setState: Logix.ModuleRuntime<S, A>['setState'];
68
+ readonly actions$: Logix.ModuleRuntime<S, A>['actions$'];
69
+ readonly changes: Logix.ModuleRuntime<S, A>['changes'];
70
+ readonly ref: Logix.ModuleRuntime<S, A>['ref'];
71
+ }
72
+
73
+ export type { Dispatch as D, ModuleActions as M, ModuleDispatchers as a, ModuleDispatchersOfShape as b, ModuleRef as c };
@@ -0,0 +1,73 @@
1
+ import * as Logix from '@logixjs/core';
2
+
3
+ type Dispatch<A> = ((action: A) => void) & {
4
+ readonly batch: (actions: ReadonlyArray<A>) => void;
5
+ readonly lowPriority: (action: A) => void;
6
+ };
7
+ type ActionArgs<P> = [P] extends [void] ? [] | [P] : [P];
8
+ type ActionFn<P, Out> = (...args: ActionArgs<P>) => Out;
9
+ type ActionTag<A> = A extends {
10
+ readonly _tag: infer T;
11
+ } ? T : A extends {
12
+ readonly type: infer T;
13
+ } ? T : never;
14
+ type ActionTags<A> = Extract<ActionTag<A>, string>;
15
+ type ActionPayload<A, K> = Extract<A, {
16
+ readonly _tag: K;
17
+ } | {
18
+ readonly type: K;
19
+ }> extends {
20
+ readonly payload?: infer P;
21
+ } ? P : never;
22
+ type AnyActionToken = Logix.Action.ActionToken<string, any, any>;
23
+ type ModuleDispatchersOfShape<Sh extends Logix.AnyModuleShape> = Sh['actionMap'];
24
+ type ModuleActions<A, Tags extends string = ActionTags<A>> = {
25
+ readonly dispatch: Dispatch<A>;
26
+ } & ([ActionTags<A>] extends [never] ? {} : {
27
+ readonly [K in Tags & ActionTags<A>]: ActionFn<ActionPayload<A, K>, void>;
28
+ });
29
+ type ActionMapOfDef<Def> = Def extends {
30
+ readonly actions: infer ActionMap;
31
+ } ? ActionMap : never;
32
+ type ModuleDispatchers<A, Tags extends string = ActionTags<A>, Def = unknown> = [ActionMapOfDef<Def>] extends [
33
+ never
34
+ ] ? [ActionTags<A>] extends [never] ? {} : {
35
+ readonly [K in Tags & ActionTags<A>]: ActionFn<ActionPayload<A, K>, Extract<A, {
36
+ readonly _tag: K;
37
+ } | {
38
+ readonly type: K;
39
+ }>>;
40
+ } : ActionMapOfDef<Def> extends Record<string, AnyActionToken> ? ActionMapOfDef<Def> : [ActionTags<A>] extends [never] ? {} : {
41
+ readonly [K in Tags & ActionTags<A>]: ActionFn<ActionPayload<A, K>, Extract<A, {
42
+ readonly _tag: K;
43
+ } | {
44
+ readonly type: K;
45
+ }>>;
46
+ };
47
+ interface ModuleImports {
48
+ readonly get: <Id extends string, Sh extends Logix.AnyModuleShape>(module: Logix.ModuleTagType<Id, Sh>) => ModuleRef<Logix.StateOf<Sh>, Logix.ActionOf<Sh>, keyof Sh['actionMap'] & string, Logix.ModuleTagType<Id, Sh>, ModuleDispatchersOfShape<Sh>>;
49
+ }
50
+ interface ModuleRef<S, A, Tags extends string = ActionTags<A>, Def = unknown, Dispatchers = ModuleDispatchers<A, Tags, Def>> {
51
+ /**
52
+ * Definition anchor (typically a ModuleTag) for reflecting actions/reducers/source and other metadata.
53
+ * - DX: when `runtime.actions.*` can't jump to source, use `ref.def?.reducers?.xxx` / `ref.def?.actions.xxx` to locate definitions quickly.
54
+ */
55
+ readonly def?: Def;
56
+ readonly runtime: Logix.ModuleRuntime<S, A>;
57
+ readonly dispatch: Dispatch<A>;
58
+ readonly actions: ModuleActions<A, Tags>;
59
+ readonly dispatchers: Dispatchers;
60
+ /**
61
+ * Fractal module imports sugar:
62
+ * - host.imports.get(ChildModule) resolves a child module instance within the host instance scope.
63
+ * - strict by default: throws when scope is missing, avoiding accidentally routing to a global instance.
64
+ */
65
+ readonly imports: ModuleImports;
66
+ readonly getState: Logix.ModuleRuntime<S, A>['getState'];
67
+ readonly setState: Logix.ModuleRuntime<S, A>['setState'];
68
+ readonly actions$: Logix.ModuleRuntime<S, A>['actions$'];
69
+ readonly changes: Logix.ModuleRuntime<S, A>['changes'];
70
+ readonly ref: Logix.ModuleRuntime<S, A>['ref'];
71
+ }
72
+
73
+ export type { Dispatch as D, ModuleActions as M, ModuleDispatchers as a, ModuleDispatchersOfShape as b, ModuleRef as c };