@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,54 @@
1
+ import {
2
+ useDispatch,
3
+ useLocalModule
4
+ } from "./chunk-PYWHL7TA.js";
5
+ import {
6
+ useModule,
7
+ useSelector
8
+ } from "./chunk-UFFCJGSZ.js";
9
+ import {
10
+ RuntimeProvider
11
+ } from "./chunk-JXAJTWSZ.js";
12
+
13
+ // src/ReactPlatform.ts
14
+ import React from "react";
15
+ var ReactPlatform = {
16
+ /**
17
+ * Creates a React component that provides the Logix runtime to its children.
18
+ */
19
+ Provider: RuntimeProvider,
20
+ /**
21
+ * Hook to use a module from the provided runtime.
22
+ */
23
+ useModule,
24
+ /**
25
+ * Hook to create and use a local module instance.
26
+ */
27
+ useLocalModule,
28
+ /**
29
+ * Hook to select a slice of state from a module.
30
+ */
31
+ useSelector,
32
+ /**
33
+ * Hook to get the dispatch function for a module.
34
+ */
35
+ useDispatch,
36
+ /**
37
+ * Creates a root provider component for a given runtime.
38
+ *
39
+ * The caller is responsible for constructing and managing the Runtime lifecycle
40
+ * (typically via Logix.Runtime.make). ReactPlatform only provides that Runtime within the React tree.
41
+ */
42
+ createRoot: (runtime) => {
43
+ return ({ children }) => {
44
+ return React.createElement(RuntimeProvider, {
45
+ runtime,
46
+ children
47
+ });
48
+ };
49
+ }
50
+ };
51
+
52
+ export {
53
+ ReactPlatform
54
+ };
@@ -0,0 +1,95 @@
1
+ import {
2
+ useModule,
3
+ useRuntime
4
+ } from "./chunk-UFFCJGSZ.js";
5
+ import {
6
+ RuntimeProvider
7
+ } from "./chunk-JXAJTWSZ.js";
8
+
9
+ // src/ModuleScope.ts
10
+ import React from "react";
11
+ import * as Logix from "@logixjs/core";
12
+ var makeModuleScope = (handle, defaults) => {
13
+ const Context = React.createContext(null);
14
+ const toUseModuleOptions = (options) => {
15
+ const { scopeId, ...rest } = options;
16
+ return scopeId != null ? { ...rest, key: scopeId } : rest;
17
+ };
18
+ const getRegistryOrThrow = (runtime, where) => {
19
+ try {
20
+ const registry = runtime.runSync(Logix.ScopeRegistry.ScopeRegistryTag);
21
+ if (!registry) {
22
+ throw new Error("ScopeRegistry service is undefined");
23
+ }
24
+ return registry;
25
+ } catch {
26
+ throw new Error(
27
+ `${where} Missing Logix.ScopeRegistry in current runtime. If you are using Logix.Runtime.make, it should be provided by default. If you are using ManagedRuntime.make, include Logix.ScopeRegistry.layer() in your Layer.`
28
+ );
29
+ }
30
+ };
31
+ const moduleToken = Logix.Module.hasImpl(handle) ? handle.tag : handle.module;
32
+ const Provider = ({ children, options }) => {
33
+ const runtime = useRuntime();
34
+ const merged = defaults || options ? { ...defaults ?? {}, ...options ?? {} } : void 0;
35
+ const ref = merged ? useModule(handle, toUseModuleOptions(merged)) : useModule(handle);
36
+ const scopeId = merged?.scopeId;
37
+ React.useEffect(() => {
38
+ if (!scopeId) return;
39
+ const registry = getRegistryOrThrow(runtime, "[ModuleScope]");
40
+ const leaseRuntime = registry.register(scopeId, Logix.ScopeRegistry.ScopedRuntimeTag, runtime);
41
+ const leaseModule = registry.register(scopeId, moduleToken, ref.runtime);
42
+ return () => {
43
+ leaseModule.release();
44
+ leaseRuntime.release();
45
+ };
46
+ }, [runtime, scopeId, ref.runtime]);
47
+ return React.createElement(Context.Provider, { value: ref }, children);
48
+ };
49
+ const use = () => {
50
+ const ref = React.useContext(Context);
51
+ if (!ref) {
52
+ throw new Error("[ModuleScope] Provider not found");
53
+ }
54
+ return ref;
55
+ };
56
+ const useImported = (module) => {
57
+ const host = use();
58
+ return host.imports.get(module);
59
+ };
60
+ const Bridge = ({ scopeId, children }) => {
61
+ const runtime = useRuntime();
62
+ const registry = getRegistryOrThrow(runtime, "[ModuleScope.Bridge]");
63
+ const scopedRuntime = registry.get(scopeId, Logix.ScopeRegistry.ScopedRuntimeTag);
64
+ const moduleRuntime = registry.get(
65
+ scopeId,
66
+ moduleToken
67
+ );
68
+ if (!scopedRuntime || !moduleRuntime) {
69
+ throw new Error(
70
+ `[ModuleScope.Bridge] Scope "${scopeId}" is not registered (or has been disposed). Ensure you have a corresponding <ModuleScope.Provider options={{ scopeId }}> mounted.`
71
+ );
72
+ }
73
+ return React.createElement(
74
+ RuntimeProvider,
75
+ { runtime: scopedRuntime },
76
+ React.createElement(BridgeInner, { moduleRuntime, Context }, children)
77
+ );
78
+ };
79
+ const BridgeInner = ({
80
+ moduleRuntime,
81
+ Context: Context2,
82
+ children
83
+ }) => {
84
+ const ref = useModule(moduleRuntime);
85
+ return React.createElement(Context2.Provider, { value: ref }, children);
86
+ };
87
+ return { Provider, use, useImported, Context, Bridge };
88
+ };
89
+ var ModuleScope = {
90
+ make: makeModuleScope
91
+ };
92
+
93
+ export {
94
+ ModuleScope
95
+ };