@pyreon/preact-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 +21 -0
- package/README.md +76 -0
- package/lib/analysis/index.js.html +5406 -0
- package/lib/index.js +110 -0
- package/lib/index.js.map +1 -0
- package/lib/types/index.d.ts +61 -0
- package/lib/types/index.d.ts.map +1 -0
- package/package.json +59 -0
- package/src/hooks.ts +131 -0
- package/src/index.ts +167 -0
- package/src/signals.ts +92 -0
- package/src/tests/preact-compat.test.ts +522 -0
- package/src/tests/setup.ts +3 -0
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,76 @@
|
|
|
1
|
+
# @pyreon/preact-compat
|
|
2
|
+
|
|
3
|
+
Preact-compatible API shim that runs on Pyreon's signal-based reactive engine. Migrate Preact code by swapping the import path.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @pyreon/preact-compat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// Replace:
|
|
15
|
+
// import { h, render, useState } from "preact/compat"
|
|
16
|
+
// With:
|
|
17
|
+
import { h, render } from "@pyreon/preact-compat"
|
|
18
|
+
import { useState, useEffect } from "@pyreon/preact-compat/hooks"
|
|
19
|
+
|
|
20
|
+
function Counter() {
|
|
21
|
+
const [count, setCount] = useState(0)
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
console.log("count changed:", count())
|
|
24
|
+
})
|
|
25
|
+
return h("button", { onClick: () => setCount((c) => c + 1) }, count)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
render(h(Counter, null), document.getElementById("app")!)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Key Differences from Preact
|
|
32
|
+
|
|
33
|
+
- **No hooks rules.** Call hooks anywhere -- in loops, conditions, nested functions.
|
|
34
|
+
- **Components run once** (setup phase only), not on every render.
|
|
35
|
+
- **`useEffect` deps are ignored.** Pyreon tracks reactive dependencies automatically. Pass `[]` to run once on mount.
|
|
36
|
+
- **`useCallback` and `memo` are no-ops.** No re-renders means no stale closures.
|
|
37
|
+
|
|
38
|
+
## Entry Points
|
|
39
|
+
|
|
40
|
+
### `@pyreon/preact-compat`
|
|
41
|
+
|
|
42
|
+
Core Preact API.
|
|
43
|
+
|
|
44
|
+
- **`h` / `createElement`** -- JSX factory.
|
|
45
|
+
- **`Fragment`** -- fragment component.
|
|
46
|
+
- **`render(vnode, container)`** -- mount a tree into a DOM element.
|
|
47
|
+
- **`hydrate(vnode, container)`** -- hydrate server-rendered HTML.
|
|
48
|
+
- **`createContext` / `useContext`** -- context API.
|
|
49
|
+
- **`createRef`** -- mutable ref container.
|
|
50
|
+
- **`Component`** -- class component base (lifecycle methods supported).
|
|
51
|
+
- **`cloneElement(vnode, props, ...children)`** -- clone with overrides.
|
|
52
|
+
- **`toChildArray(children)`** -- normalize children to a flat array.
|
|
53
|
+
- **`isValidElement(x)`** -- type guard for VNodes.
|
|
54
|
+
|
|
55
|
+
### `@pyreon/preact-compat/hooks`
|
|
56
|
+
|
|
57
|
+
Hooks API (mirrors `preact/hooks`).
|
|
58
|
+
|
|
59
|
+
- **`useState(initial)`** -- returns `[getter, setter]`. Call `getter()` to read.
|
|
60
|
+
- **`useReducer(reducer, initial)`** -- returns `[getter, dispatch]`.
|
|
61
|
+
- **`useEffect(fn, deps?)`** -- reactive effect. `[]` deps means mount-only.
|
|
62
|
+
- **`useLayoutEffect`** -- alias for `useEffect`.
|
|
63
|
+
- **`useMemo(fn, deps?)`** -- returns a computed getter. Deps are ignored.
|
|
64
|
+
- **`useCallback(fn, deps?)`** -- returns `fn` as-is (no-op).
|
|
65
|
+
- **`useRef(initial?)`** -- returns `{ current }`.
|
|
66
|
+
- **`useId()`** -- stable unique string per component instance.
|
|
67
|
+
- **`useErrorBoundary`** -- alias for `onErrorCaptured`.
|
|
68
|
+
|
|
69
|
+
### `@pyreon/preact-compat/signals`
|
|
70
|
+
|
|
71
|
+
Preact Signals API (mirrors `@preact/signals`).
|
|
72
|
+
|
|
73
|
+
- **`signal(initial)`** -- returns `{ value }` read/write accessor.
|
|
74
|
+
- **`computed(fn)`** -- returns `{ value }` read-only accessor.
|
|
75
|
+
- **`effect(fn)`** -- reactive side effect, returns dispose function.
|
|
76
|
+
- **`batch(fn)`** -- coalesce multiple signal writes.
|