@pyreon/reactivity 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 +73 -0
- package/lib/analysis/index.js.html +5406 -0
- package/lib/index.js +838 -0
- package/lib/index.js.map +1 -0
- package/lib/types/index.d.ts +725 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index2.d.ts +342 -0
- package/lib/types/index2.d.ts.map +1 -0
- package/package.json +40 -0
- package/src/batch.ts +44 -0
- package/src/cell.ts +71 -0
- package/src/computed.ts +71 -0
- package/src/createSelector.ts +56 -0
- package/src/debug.ts +134 -0
- package/src/effect.ts +152 -0
- package/src/index.ts +15 -0
- package/src/reconcile.ts +98 -0
- package/src/resource.ts +66 -0
- package/src/scope.ts +80 -0
- package/src/signal.ts +125 -0
- package/src/store.ts +139 -0
- package/src/tests/batch.test.ts +69 -0
- package/src/tests/bind.test.ts +84 -0
- package/src/tests/branches.test.ts +343 -0
- package/src/tests/cell.test.ts +111 -0
- package/src/tests/computed.test.ts +146 -0
- package/src/tests/createSelector.test.ts +119 -0
- package/src/tests/debug.test.ts +196 -0
- package/src/tests/effect.test.ts +256 -0
- package/src/tests/resource.test.ts +133 -0
- package/src/tests/scope.test.ts +202 -0
- package/src/tests/signal.test.ts +120 -0
- package/src/tests/store.test.ts +136 -0
- package/src/tests/tracking.test.ts +158 -0
- package/src/tests/watch.test.ts +146 -0
- package/src/tracking.ts +103 -0
- package/src/watch.ts +69 -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,73 @@
|
|
|
1
|
+
# @pyreon/reactivity
|
|
2
|
+
|
|
3
|
+
Signal-based fine-grained reactivity primitives for the Pyreon framework.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @pyreon/reactivity
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { signal, computed, effect, batch } from "@pyreon/reactivity"
|
|
15
|
+
|
|
16
|
+
const count = signal(0)
|
|
17
|
+
const doubled = computed(() => count() * 2)
|
|
18
|
+
|
|
19
|
+
effect(() => {
|
|
20
|
+
console.log("doubled:", doubled())
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
batch(() => {
|
|
24
|
+
count.set(1)
|
|
25
|
+
count.set(2)
|
|
26
|
+
})
|
|
27
|
+
// logs "doubled: 4" once
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API
|
|
31
|
+
|
|
32
|
+
### Signals
|
|
33
|
+
|
|
34
|
+
- **`signal<T>(initial: T): Signal<T>`** -- Callable getter with `.set(value)` and `.update(fn)` methods.
|
|
35
|
+
- **`computed<T>(fn, options?): Computed<T>`** -- Derived signal that recomputes lazily when dependencies change.
|
|
36
|
+
- **`cell<T>(initial: T): Cell<T>`** -- Lightweight reactive cell.
|
|
37
|
+
|
|
38
|
+
### Effects
|
|
39
|
+
|
|
40
|
+
- **`effect(fn): Effect`** -- Runs `fn` and re-runs it whenever its tracked dependencies change.
|
|
41
|
+
- **`renderEffect(fn): Effect`** -- Like `effect`, but scheduled for render timing.
|
|
42
|
+
- **`watch(source, callback, options?): WatchOptions`** -- Watches a reactive source and calls back on change.
|
|
43
|
+
- **`setErrorHandler(handler)`** -- Sets a global error handler for effect errors.
|
|
44
|
+
|
|
45
|
+
### Batching
|
|
46
|
+
|
|
47
|
+
- **`batch(fn)`** -- Groups multiple signal writes; subscribers notified once at the end.
|
|
48
|
+
- **`nextTick(): Promise<void>`** -- Resolves after the current batch of updates flushes.
|
|
49
|
+
|
|
50
|
+
### Tracking
|
|
51
|
+
|
|
52
|
+
- **`runUntracked(fn)`** -- Runs `fn` without tracking any signal reads.
|
|
53
|
+
|
|
54
|
+
### Scopes
|
|
55
|
+
|
|
56
|
+
- **`effectScope(): EffectScope`** -- Creates a scope that collects effects for bulk disposal.
|
|
57
|
+
- **`getCurrentScope(): EffectScope | undefined`** -- Returns the active effect scope.
|
|
58
|
+
- **`setCurrentScope(scope)`** -- Manually sets the current effect scope.
|
|
59
|
+
|
|
60
|
+
### Selectors and Resources
|
|
61
|
+
|
|
62
|
+
- **`createSelector(source)`** -- Creates an efficient selector for keyed comparisons.
|
|
63
|
+
- **`createResource(fetcher): Resource<T>`** -- Wraps an async data source in a reactive resource.
|
|
64
|
+
|
|
65
|
+
### Stores
|
|
66
|
+
|
|
67
|
+
- **`createStore(initial)`** -- Creates a deeply reactive store object.
|
|
68
|
+
- **`isStore(value): boolean`** -- Checks whether a value is a reactive store.
|
|
69
|
+
- **`reconcile(target, source)`** -- Efficiently patches a store to match a new value.
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|