@pyreon/react-compat 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Vit Bokisch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # @pyreon/react-compat
2
+
3
+ React-compatible API shim that runs on Pyreon's signal-based reactive engine. Migrate React code by swapping the import path.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add @pyreon/react-compat
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ // Replace:
15
+ // import { useState, useEffect } from "react"
16
+ // With:
17
+ import { useState, useEffect } from "@pyreon/react-compat"
18
+
19
+ function Counter() {
20
+ const [count, setCount] = useState(0)
21
+ useEffect(() => {
22
+ console.log("count changed:", count())
23
+ })
24
+ return <button onClick={() => setCount((c) => c + 1)}>{count}</button>
25
+ }
26
+ ```
27
+
28
+ ## Key Differences from React
29
+
30
+ - **No hooks rules.** Call hooks anywhere -- in loops, conditions, nested functions.
31
+ - **Components run once** (setup phase only), not on every render.
32
+ - **`useEffect` deps are ignored.** Pyreon tracks reactive dependencies automatically. Pass `[]` to run once on mount.
33
+ - **`useCallback` and `memo` are no-ops.** No re-renders means no stale closures.
34
+
35
+ ## API
36
+
37
+ ### State and Reducers
38
+
39
+ - **`useState(initial)`** -- returns `[getter, setter]`. Call `getter()` to read.
40
+ - **`useReducer(reducer, initial)`** -- returns `[getter, dispatch]`.
41
+
42
+ ### Effects and Lifecycle
43
+
44
+ - **`useEffect(fn, deps?)`** -- reactive effect. `[]` deps means mount-only.
45
+ - **`useLayoutEffect`** -- alias for `onMount`.
46
+ - **`onMount`, `onUnmount`, `onUpdate`** -- Pyreon-native lifecycle hooks.
47
+
48
+ ### Memoization
49
+
50
+ - **`useMemo(fn, deps?)`** -- returns a computed getter. Deps are ignored.
51
+ - **`useCallback(fn, deps?)`** -- returns `fn` as-is (no-op).
52
+
53
+ ### Refs and Context
54
+
55
+ - **`useRef(initial?)`** -- returns `{ current }`.
56
+ - **`createContext(defaultValue)`**, **`useContext(ctx)`** -- same API as React.
57
+ - **`useId()`** -- stable unique string per component instance.
58
+
59
+ ### Components
60
+
61
+ - **`memo(component)`** -- returns component unchanged (no-op).
62
+ - **`lazy(loader)`** -- dynamic import wrapper. Pair with `<Suspense>`.
63
+ - **`Suspense`**, **`ErrorBoundary`** -- boundary components.
64
+ - **`createPortal(children, target)`** -- portal rendering.
65
+
66
+ ### Optimization (no-ops for compatibility)
67
+
68
+ - **`useTransition()`** -- returns `[false, (fn) => fn()]`.
69
+ - **`useDeferredValue(value)`** -- returns value as-is.
70
+ - **`useImperativeHandle(ref, init)`** -- exposes methods via ref.
71
+
72
+ ### Utilities
73
+
74
+ - **`batch(fn)`** -- coalesce multiple signal writes.
75
+ - **`useErrorBoundary`** -- alias for `onErrorCaptured`.
76
+ - **`createSelector`** -- O(1) equality selector from `@pyreon/reactivity`.
77
+ - **`createElement` / `h`**, **`Fragment`** -- JSX runtime.