@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
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @logixjs/react
2
+
3
+ > Logix Runtime 的 React 适配层(Alpha 阶段:仓库内 API 已稳定,正式发版前仍可能微调)。
4
+
5
+ ## 功能亮点
6
+
7
+ - **RuntimeProvider**:
8
+ - `runtime={Logix.Runtime.make(root, { layer })}` 启动完整应用 Runtime,并自动注入 `ReactPlatformLayer`(推荐用法;`root` 可为 program module 或其 `.impl`);
9
+ - `layer={Layer}` 在父 Runtime 上叠加局部服务(页面/组件级 DI);
10
+ - `runtime` / `value` 直接复用已有 `ManagedRuntime`,常用于测试或集成场景。
11
+ - **并发安全的 Hooks**:`useModule` 返回稳定的 `ModuleRuntime`;`useModule(handle, selector)` / `useSelector(handle | runtime, selector, equalityFn?)` 基于 `useSyncExternalStore` 实现,默认 `Object.is` 比较,可自定义 `equalityFn`,避免并发渲染撕裂。
12
+ - **稳定派发器**:`useDispatch(handle | runtime)` 复用当前 Runtime Scope,保证回调引用稳定。
13
+ - **局部模块(实验特性)**:`useLocalModule` 让 Module Scope 绑定到组件生命周期,适合表单/页面级状态。
14
+
15
+ ## 快速上手
16
+
17
+ ```tsx
18
+ import { RuntimeProvider, ReactPlatformLayer } from "@logixjs/react"
19
+ import * as Logix from "@logixjs/core"
20
+ import { Layer } from "effect"
21
+
22
+ const RootDef = Logix.Module.make("Root", { state: RootState, actions: RootActions })
23
+ const RootModule = RootDef.implement({
24
+ initial: { /* ... */ },
25
+ imports: [/* ModuleImpls / Service Layers */],
26
+ processes: [/* Coordinators / Links */]
27
+ })
28
+
29
+ const appRuntime = Logix.Runtime.make(RootModule, {
30
+ layer: Layer.mergeAll(AppInfraLayer, ReactPlatformLayer)
31
+ })
32
+
33
+ export function App() {
34
+ return (
35
+ <RuntimeProvider runtime={appRuntime}>
36
+ <Router />
37
+ </RuntimeProvider>
38
+ )
39
+ }
40
+ ```
41
+
42
+ 在组件中使用 Hooks:
43
+
44
+ ```tsx
45
+ import { useModule, useSelector, useDispatch } from "@logixjs/react"
46
+
47
+ function Counter() {
48
+ const runtime = useModule(CounterModule)
49
+ const count = useModule(CounterModule, (s) => s.count)
50
+ const dispatch = useDispatch(runtime)
51
+
52
+ return <button onClick={() => dispatch({ _tag: "inc" })}>{count}</button>
53
+ }
54
+ ```
55
+
56
+ ## 文档与规划
57
+
58
+ 详细规范见 `.codex/skills/project-guide/references/runtime-logix/logix-react/01-react-integration.md`,关键目标包括:
59
+
60
+ 1. React 组件只负责意图事件,所有状态/流程逻辑收敛到 Logix 模块;
61
+ 2. Hooks 必须兼容 Concurrent Mode(`useSyncExternalStore`)并提供稳定 Runtime 引用;
62
+ 3. RuntimeProvider 的 `runtime + layer` 组合与 Effect `Layer` 语义一致,方便 LLM / 工具链自动推断依赖注入。
63
+
64
+ 更多迁移策略、生命周期说明以及 ReactPlatform 细节,请参阅上述规范文档。