@vielzeug/stateit 2.0.0 → 2.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/README.md +54 -295
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -9
- package/dist/stateit.cjs +1 -1
- package/dist/stateit.cjs.map +1 -1
- package/dist/stateit.d.ts +17 -0
- package/dist/stateit.d.ts.map +1 -0
- package/dist/stateit.js +180 -236
- package/dist/stateit.js.map +1 -1
- package/dist/types.d.ts +19 -20
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/dist/batch.cjs +0 -2
- package/dist/batch.cjs.map +0 -1
- package/dist/batch.d.ts +0 -5
- package/dist/batch.d.ts.map +0 -1
- package/dist/batch.js +0 -28
- package/dist/batch.js.map +0 -1
- package/dist/computed.cjs +0 -2
- package/dist/computed.cjs.map +0 -1
- package/dist/computed.d.ts +0 -58
- package/dist/computed.d.ts.map +0 -1
- package/dist/computed.js +0 -65
- package/dist/computed.js.map +0 -1
- package/dist/effect.cjs +0 -2
- package/dist/effect.cjs.map +0 -1
- package/dist/effect.d.ts +0 -31
- package/dist/effect.d.ts.map +0 -1
- package/dist/effect.js +0 -53
- package/dist/effect.js.map +0 -1
- package/dist/runtime.cjs +0 -2
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.d.ts +0 -40
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -47
- package/dist/runtime.js.map +0 -1
- package/dist/signal.cjs +0 -2
- package/dist/signal.cjs.map +0 -1
- package/dist/signal.d.ts +0 -26
- package/dist/signal.d.ts.map +0 -1
- package/dist/signal.js +0 -40
- package/dist/signal.js.map +0 -1
- package/dist/store.cjs +0 -2
- package/dist/store.cjs.map +0 -1
- package/dist/store.d.ts +0 -32
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js +0 -51
- package/dist/store.js.map +0 -1
- package/dist/types.cjs +0 -2
- package/dist/types.cjs.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/watch.cjs +0 -2
- package/dist/watch.cjs.map +0 -1
- package/dist/watch.d.ts +0 -36
- package/dist/watch.d.ts.map +0 -1
- package/dist/watch.js +0 -32
- package/dist/watch.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,337 +1,96 @@
|
|
|
1
1
|
# @vielzeug/stateit
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@vielzeug/stateit) [](https://opensource.org/licenses/MIT)
|
|
6
|
-
|
|
7
|
-
**Stateit** is a tiny, zero-dependency reactive library with two complementary primitives:
|
|
8
|
-
|
|
9
|
-
- **Signals** — fine-grained reactive atoms with `signal()`, `computed()`, `effect()`, `watch()`, `batch()`, and more
|
|
10
|
-
- **Stores** — typed reactive object containers with partial patching, updater functions, selectors, and freeze
|
|
11
|
-
|
|
12
|
-
A `Store<T>` extends `Signal<T>`, so every signal primitive — `effect`, `watch`, `computed`, `batch` — works seamlessly on stores.
|
|
3
|
+
Tiny reactive state with direct singleton primitives.
|
|
13
4
|
|
|
14
5
|
## Installation
|
|
15
6
|
|
|
16
7
|
```sh
|
|
17
8
|
pnpm add @vielzeug/stateit
|
|
18
|
-
# npm install @vielzeug/stateit
|
|
19
|
-
# yarn add @vielzeug/stateit
|
|
20
9
|
```
|
|
21
10
|
|
|
22
|
-
##
|
|
11
|
+
## Usage
|
|
23
12
|
|
|
24
|
-
|
|
13
|
+
Stateit exports singleton primitives directly.
|
|
25
14
|
|
|
26
|
-
```
|
|
27
|
-
import {
|
|
15
|
+
```ts
|
|
16
|
+
import { batch, computed, effect, signal } from '@vielzeug/stateit';
|
|
28
17
|
|
|
29
18
|
const count = signal(0);
|
|
30
19
|
const doubled = computed(() => count.value * 2);
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
console.log(`count=${count.value}, doubled=${doubled.value}`);
|
|
21
|
+
const stop = effect(() => {
|
|
22
|
+
console.log(count.value, doubled.value);
|
|
35
23
|
});
|
|
36
|
-
// → count=0, doubled=0
|
|
37
24
|
|
|
38
|
-
count.value = 3;
|
|
39
|
-
// → count=3, doubled=6
|
|
40
|
-
|
|
41
|
-
// Update via function — shorthand for count.value = count.value + n
|
|
42
|
-
count.update((n) => n + 1);
|
|
43
|
-
// → count=4, doubled=8
|
|
44
|
-
|
|
45
|
-
// Watch explicitly (does not fire immediately by default)
|
|
46
|
-
const stopWatch = watch(count, (next, prev) => console.log(prev, '→', next));
|
|
47
|
-
count.value = 5; // → 4 → 5
|
|
48
|
-
|
|
49
|
-
// Batch coalesces notifications into one flush
|
|
50
25
|
batch(() => {
|
|
51
|
-
count.value =
|
|
52
|
-
count.value =
|
|
26
|
+
count.value = 1;
|
|
27
|
+
count.value = 2;
|
|
53
28
|
});
|
|
54
|
-
// One notification: → 5 → 20
|
|
55
29
|
|
|
56
|
-
|
|
30
|
+
stop();
|
|
57
31
|
doubled.dispose();
|
|
58
|
-
stopWatch.dispose();
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Stores
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
import { store, watch, batch } from '@vielzeug/stateit';
|
|
65
|
-
|
|
66
|
-
const counter = store({ count: 0, user: null as User | null });
|
|
67
|
-
|
|
68
|
-
// Read
|
|
69
|
-
console.log(counter.value); // { count: 0, user: null }
|
|
70
|
-
|
|
71
|
-
// Partial patch
|
|
72
|
-
counter.patch({ count: 1 });
|
|
73
|
-
|
|
74
|
-
// Updater function
|
|
75
|
-
counter.update((s) => ({ ...s, count: s.count + 1 }));
|
|
76
|
-
|
|
77
|
-
// Watch a slice — compose store.select() with watch()
|
|
78
|
-
const countSignal = counter.select((s) => s.count);
|
|
79
|
-
const stopWatch = watch(countSignal, (count, prev) => {
|
|
80
|
-
console.log('count:', prev, '→', count);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Batch updates into one notification
|
|
84
|
-
batch(() => {
|
|
85
|
-
counter.patch({ count: 10 });
|
|
86
|
-
counter.patch({ user: currentUser });
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Reset to initial state
|
|
90
|
-
counter.reset();
|
|
91
|
-
|
|
92
|
-
stopWatch.dispose();
|
|
93
|
-
counter.freeze();
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Features
|
|
97
|
-
|
|
98
|
-
- ✅ **Signals** — reactive atoms with `.value` getter/setter, `.update(fn)`, and `.peek()` for untracked reads
|
|
99
|
-
- ✅ **Computed** — lazy derived signals; call `.dispose()` to stop tracking dependencies
|
|
100
|
-
- ✅ **Effects** — run immediately and re-run when dependencies change; support cleanup returns; return a `Subscription`
|
|
101
|
-
- ✅ **Watch** — explicit subscriptions with `{ immediate?, once?, equals? }` options; returns a `Subscription`
|
|
102
|
-
- ✅ **Batch** — coalesce multiple writes into a single downstream notification
|
|
103
|
-
- ✅ **Untrack** — read signals without registering reactive dependencies
|
|
104
|
-
- ✅ **derived** — multi-source computed from an array of signals
|
|
105
|
-
- ✅ **nextValue** — `Promise` that resolves on the next matching signal emission
|
|
106
|
-
- ✅ **Custom equality** — `signal/computed/watch/store` all accept a custom `equals` function
|
|
107
|
-
- ✅ **Stores** — object state with `patch(partial)`, `update(fn)`, `reset()`, `select()`, and `freeze()`
|
|
108
|
-
- ✅ **Writable computed** — bidirectional computed with `writable(get, set)`
|
|
109
|
-
- ✅ **Symbol.dispose** — all dispose handles support `using` declarations (TC39 explicit resource management)
|
|
110
|
-
- ✅ **Type guards** — `isSignal(v)` and `isStore(v)`
|
|
111
|
-
- ✅ **Zero dependencies** — no supply-chain risk, minimal bundle size
|
|
112
|
-
- ✅ **Framework agnostic** — works in React, Vue, Svelte, or plain TypeScript
|
|
113
|
-
|
|
114
|
-
## Usage
|
|
115
|
-
|
|
116
|
-
### Signals
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
import { signal, readonly } from '@vielzeug/stateit';
|
|
120
|
-
|
|
121
|
-
const count = signal(0);
|
|
122
|
-
count.value = 5;
|
|
123
|
-
count.peek(); // read without tracking
|
|
124
|
-
count.update((n) => n + 1); // derive next value in place
|
|
125
|
-
|
|
126
|
-
// Narrow to read-only view (no proxy overhead)
|
|
127
|
-
const ro = readonly(count);
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Computed
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
import { signal, computed } from '@vielzeug/stateit';
|
|
134
|
-
|
|
135
|
-
const first = signal('Ada');
|
|
136
|
-
const last = signal('Lovelace');
|
|
137
|
-
const full = computed(() => `${first.value} ${last.value}`);
|
|
138
|
-
|
|
139
|
-
console.log(full.value); // 'Ada Lovelace'
|
|
140
|
-
full.stale; // false — just computed
|
|
141
|
-
first.value = 'Grace';
|
|
142
|
-
full.stale; // true — deps changed, not yet re-read
|
|
143
|
-
|
|
144
|
-
// Dispose (stop tracking dependencies)
|
|
145
|
-
full.dispose();
|
|
146
|
-
// or: using full = computed(...) — TC39 using declaration
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Effects
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
import { signal, effect, onCleanup } from '@vielzeug/stateit';
|
|
153
|
-
|
|
154
|
-
const name = signal('Ada');
|
|
155
|
-
|
|
156
|
-
const sub = effect(() => {
|
|
157
|
-
console.log('Hello,', name.value);
|
|
158
|
-
return () => console.log('cleanup'); // optional teardown
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
name.value = 'Grace'; // logs 'cleanup' then 'Hello, Grace'
|
|
162
|
-
sub.dispose(); // logs 'cleanup', effect is removed
|
|
163
32
|
```
|
|
164
33
|
|
|
165
|
-
|
|
34
|
+
## Store As Small Recipe
|
|
166
35
|
|
|
167
|
-
|
|
168
|
-
import { signal, store, watch } from '@vielzeug/stateit';
|
|
36
|
+
`store()` is a thin object helper over `signal()` with immutable-style updates.
|
|
169
37
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// Plain watch
|
|
173
|
-
const sub = watch(count, (next, prev) => console.log(prev, '→', next));
|
|
174
|
-
|
|
175
|
-
// Slice watch — compose with store.select()
|
|
176
|
-
const user = store({ name: 'Ada', age: 30 });
|
|
177
|
-
const nameSig = user.select((s) => s.name);
|
|
178
|
-
watch(nameSig, (name) => console.log('name:', name));
|
|
38
|
+
```ts
|
|
39
|
+
import { store } from '@vielzeug/stateit';
|
|
179
40
|
|
|
180
|
-
|
|
181
|
-
watch(count, (v) => console.log(v), { immediate: true, once: true });
|
|
41
|
+
const user = store({ profile: { name: 'Ada' }, count: 0 });
|
|
182
42
|
|
|
183
|
-
|
|
43
|
+
user.patch({ count: 1 });
|
|
44
|
+
user.update((state) => ({ ...state, count: state.count + 1 }));
|
|
45
|
+
user.reset();
|
|
184
46
|
```
|
|
185
47
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
```typescript
|
|
189
|
-
import { store, watch, batch } from '@vielzeug/stateit';
|
|
190
|
-
|
|
191
|
-
const cart = store({ items: [] as string[], total: 0 });
|
|
48
|
+
## Watch Selector Overload
|
|
192
49
|
|
|
193
|
-
|
|
194
|
-
cart.patch({ total: 42 });
|
|
50
|
+
No intermediate selector signal is required.
|
|
195
51
|
|
|
196
|
-
|
|
197
|
-
|
|
52
|
+
```ts
|
|
53
|
+
import { store, watch } from '@vielzeug/stateit';
|
|
198
54
|
|
|
199
|
-
|
|
200
|
-
const totalSignal = cart.select((s) => s.total);
|
|
55
|
+
const cart = store({ count: 0, label: 'x' });
|
|
201
56
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
cart.patch({ total: 0 });
|
|
208
|
-
cart.update((s) => ({ ...s, items: [] }));
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
cart.reset();
|
|
212
|
-
cart.freeze();
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Writable Computed
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
import { signal, writable } from '@vielzeug/stateit';
|
|
219
|
-
|
|
220
|
-
const celsius = signal(0);
|
|
221
|
-
const fahrenheit = writable(
|
|
222
|
-
() => (celsius.value * 9) / 5 + 32,
|
|
223
|
-
(f) => {
|
|
224
|
-
celsius.value = ((f - 32) * 5) / 9;
|
|
57
|
+
const stop = watch(
|
|
58
|
+
cart,
|
|
59
|
+
(state) => state.count,
|
|
60
|
+
(next, prev) => {
|
|
61
|
+
console.log(prev, '->', next);
|
|
225
62
|
},
|
|
226
63
|
);
|
|
227
64
|
|
|
228
|
-
|
|
229
|
-
console.log(celsius.value); // 100
|
|
230
|
-
|
|
231
|
-
fahrenheit.update((f) => f + 10); // increment via fn
|
|
232
|
-
fahrenheit.dispose();
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
### `nextValue` — Async Watch
|
|
236
|
-
|
|
237
|
-
```typescript
|
|
238
|
-
import { signal, nextValue } from '@vielzeug/stateit';
|
|
239
|
-
|
|
240
|
-
const status = signal<'idle' | 'loading' | 'done'>('idle');
|
|
241
|
-
|
|
242
|
-
// Wait for the next change (any value)
|
|
243
|
-
const next = await nextValue(status);
|
|
244
|
-
|
|
245
|
-
// Wait for a specific condition
|
|
246
|
-
const done = await nextValue(status, (v) => v === 'done');
|
|
247
|
-
|
|
248
|
-
// Abortable wait
|
|
249
|
-
const controller = new AbortController();
|
|
250
|
-
const p = nextValue(status, (v) => v === 'done', { signal: controller.signal });
|
|
251
|
-
controller.abort(new Error('cancelled'));
|
|
65
|
+
stop();
|
|
252
66
|
```
|
|
253
67
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
```typescript
|
|
257
|
-
import { signal, computed } from '@vielzeug/stateit';
|
|
68
|
+
## Strict Runtime Rules
|
|
258
69
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// Computed suppresses downstream when result is structurally unchanged
|
|
263
|
-
const sorted = computed(() => [...tags.value].sort(), { equals: (a, b) => a.join() === b.join() });
|
|
264
|
-
```
|
|
70
|
+
- `onCleanup()` throws when called outside an active effect.
|
|
71
|
+
- Reading a disposed computed signal throws.
|
|
72
|
+
- Store misuse (non-object values) throws.
|
|
265
73
|
|
|
266
74
|
## API
|
|
267
75
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
|
288
|
-
|
|
289
|
-
| `_resetContextForTesting` | `_resetContextForTesting()` | `void` |
|
|
290
|
-
|
|
291
|
-
### Store Functions
|
|
292
|
-
|
|
293
|
-
| Export | Signature | Returns |
|
|
294
|
-
| ------- | -------------------------- | ---------- |
|
|
295
|
-
| `store` | `store(initial, options?)` | `Store<T>` |
|
|
296
|
-
|
|
297
|
-
### `Store<T>` Methods
|
|
298
|
-
|
|
299
|
-
| Member | Description |
|
|
300
|
-
| ----------------------------- | ----------------------------------------------------------------------- |
|
|
301
|
-
| `.value` | Read the current state (tracked) |
|
|
302
|
-
| `.peek()` | Read the current state (untracked) |
|
|
303
|
-
| `.update(fn)` | Derive next state via `fn(copy) => next` |
|
|
304
|
-
| `.patch(partial)` | Shallow-merge a `Partial<T>` into state |
|
|
305
|
-
| `.reset()` | Restore the original initial state |
|
|
306
|
-
| `.select(selector, options?)` | Lazily derived `ComputedSignal<U>` from a slice; compose with `watch()` |
|
|
307
|
-
| `.frozen` | `true` after `freeze()` has been called |
|
|
308
|
-
| `.freeze()` | Freeze the store; further writes are silently ignored |
|
|
309
|
-
|
|
310
|
-
### Types
|
|
311
|
-
|
|
312
|
-
| Type | Description |
|
|
313
|
-
| -------------------- | ------------------------------------------------------------------------------------ |
|
|
314
|
-
| `Signal<T>` | Readable/writable reactive atom with `.update(fn)` |
|
|
315
|
-
| `ReadonlySignal<T>` | Read-only signal (no setter) |
|
|
316
|
-
| `ComputedSignal<T>` | `ReadonlySignal<T> & Disposable` — has `.stale`, `.dispose()` |
|
|
317
|
-
| `WritableSignal<T>` | `Signal<T> & Disposable` — has `.stale`, `.update(fn)`, `.dispose()` |
|
|
318
|
-
| `Store<T>` | Object store extending `Signal<T>` |
|
|
319
|
-
| `Subscription` | Callable + `.dispose()` + `[Symbol.dispose]` — returned by `effect`/`watch` |
|
|
320
|
-
| `Disposable` | `.dispose()` + `[Symbol.dispose]` — implemented by `ComputedSignal`/`WritableSignal` |
|
|
321
|
-
| `CleanupFn` | `() => void` |
|
|
322
|
-
| `EffectCallback` | `() => CleanupFn \| void` |
|
|
323
|
-
| `EffectOptions` | `{ maxIterations?, onError? }` |
|
|
324
|
-
| `EqualityFn<T>` | `(a: T, b: T) => boolean` |
|
|
325
|
-
| `ReactiveOptions<T>` | `{ equals?: EqualityFn<T> }` |
|
|
326
|
-
| `WatchOptions<T>` | `{ immediate?, once?, equals? }` |
|
|
327
|
-
| `StoreOptions<T>` | `{ equals?: EqualityFn<T> }` |
|
|
328
|
-
|
|
329
|
-
## Documentation
|
|
330
|
-
|
|
331
|
-
Full docs at **[vielzeug.dev/stateit](https://vielzeug.dev/stateit)**
|
|
332
|
-
|
|
333
|
-
| | |
|
|
334
|
-
| ------------------------------------------------- | -------------------------------------- |
|
|
335
|
-
| [Usage Guide](https://vielzeug.dev/stateit/usage) | Concepts, patterns, and best practices |
|
|
336
|
-
| [API Reference](https://vielzeug.dev/stateit/api) | Complete type signatures |
|
|
337
|
-
| [Examples](https://vielzeug.dev/stateit/examples) | Framework integrations and recipes |
|
|
76
|
+
```ts
|
|
77
|
+
signal<T>(initial: T, options?: { equals?: (a: T, b: T) => boolean }): Signal<T>;
|
|
78
|
+
computed<T>(compute: () => T, options?: { equals?: (a: T, b: T) => boolean }): ComputedSignal<T>;
|
|
79
|
+
effect(fn: () => void | (() => void), options?: { maxIterations?: number }): Subscription;
|
|
80
|
+
watch<T>(source: ReadonlySignal<T>, cb: (value: T, prev: T) => void, options?: WatchOptions<T>): Subscription;
|
|
81
|
+
watch<S, T>(
|
|
82
|
+
source: ReadonlySignal<S>,
|
|
83
|
+
selector: (value: S) => T,
|
|
84
|
+
cb: (value: T, prev: T) => void,
|
|
85
|
+
options?: WatchOptions<T>,
|
|
86
|
+
): Subscription;
|
|
87
|
+
batch<T>(fn: () => T): T;
|
|
88
|
+
untrack<T>(fn: () => T): T;
|
|
89
|
+
onCleanup(fn: () => void): void;
|
|
90
|
+
store<T extends object>(initial: T, options?: { equals?: (a: T, b: T) => boolean }): Store<T>;
|
|
91
|
+
readonly<T>(input: ReadonlySignal<T>): ReadonlySignal<T>;
|
|
92
|
+
writable<T>(input: Signal<T>): Signal<T>;
|
|
93
|
+
isSignal<T>(value: unknown): value is ReadonlySignal<T>;
|
|
94
|
+
peekValue<T>(input: T | ReadonlySignal<T>): T;
|
|
95
|
+
toValue<T>(input: T | ReadonlySignal<T> | (() => T)): T;
|
|
96
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./stateit.cjs`);exports.batch=e.batch,exports.computed=e.computed,exports.effect=e.effect,exports.isSignal=e.isSignal,exports.onCleanup=e.onCleanup,exports.peekValue=e.peekValue,exports.readonly=e.readonly,exports.signal=e.signal,exports.store=e.store,exports.toValue=e.toValue,exports.untrack=e.untrack,exports.watch=e.watch,exports.writable=e.writable;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
* Reactive primitives:
|
|
4
|
-
* Signal<T> -- synchronous, fine-grained reactive atom
|
|
5
|
-
* ReadonlySignal<T> -- read-only view of a signal
|
|
6
|
-
* Store<T> -- object-state store with set/freeze/reset/select
|
|
7
|
-
*
|
|
8
|
-
* All primitives interoperate: computed, derived, effect, watch, batch,
|
|
9
|
-
* untrack, onCleanup, toValue, configureStateit work uniformly
|
|
10
|
-
* on Signal<T> and Store<T>.
|
|
11
|
-
*/
|
|
12
|
-
export * from './batch';
|
|
13
|
-
export * from './computed';
|
|
14
|
-
export * from './effect';
|
|
15
|
-
export { _resetContextForTesting, configureStateit } from './runtime';
|
|
16
|
-
export * from './signal';
|
|
17
|
-
export * from './store';
|
|
1
|
+
export { batch, computed, effect, isSignal, onCleanup, peekValue, readonly, signal, store, toValue, untrack, watch, writable, } from './stateit';
|
|
18
2
|
export * from './types';
|
|
19
|
-
export * from './watch';
|
|
20
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,EACR,MAAM,EACN,KAAK,EACL,OAAO,EACP,OAAO,EACP,KAAK,EACL,QAAQ,GACT,MAAM,WAAW,CAAC;AAEnB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { _SIGNAL_BRAND as i, _STORE_BRAND as a } from "./types.js";
|
|
4
|
-
import { ComputedNode as o, WritableNode as s, computed as c, derived as l, writable as u } from "./computed.js";
|
|
5
|
-
import { effect as d, onCleanup as f, untrack as p } from "./effect.js";
|
|
6
|
-
import { SignalImpl as m, isSignal as h, peekValue as g, readonly as _, signal as v, toValue as y } from "./signal.js";
|
|
7
|
-
import { isStore as b, shallowEqual as x, store as S } from "./store.js";
|
|
8
|
-
import { nextValue as C, watch as w } from "./watch.js";
|
|
9
|
-
export { o as ComputedNode, m as SignalImpl, s as WritableNode, i as _SIGNAL_BRAND, a as _STORE_BRAND, n as _flushPending, e as _resetContextForTesting, r as batch, c as computed, t as configureStateit, l as derived, d as effect, h as isSignal, b as isStore, C as nextValue, f as onCleanup, g as peekValue, _ as readonly, x as shallowEqual, v as signal, S as store, y as toValue, p as untrack, w as watch, u as writable };
|
|
1
|
+
import { batch as e, computed as t, effect as n, isSignal as r, onCleanup as i, peekValue as a, readonly as o, signal as s, store as c, toValue as l, untrack as u, watch as d, writable as f } from "./stateit.js";
|
|
2
|
+
export { e as batch, t as computed, n as effect, r as isSignal, i as onCleanup, a as peekValue, o as readonly, s as signal, c as store, l as toValue, u as untrack, d as watch, f as writable };
|
package/dist/stateit.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(`stateit.uninitialized`),t=
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(`stateit.uninitialized`),t=100,n=e=>Object.assign(e,{dispose:e,[Symbol.dispose]:e}),r=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t)},i=e=>structuredClone(e),a=(e,t)=>{let n=[];for(let t of e)try{t()}catch(e){n.push(e)}if(n.length===1)throw n[0];if(n.length>1)throw AggregateError(n,`[stateit] ${t}`)},o=e=>{let t=[];for(let n of[...e])try{n()}catch(e){t.push(e)}if(t.length===1)throw t[0];if(t.length>1)throw AggregateError(t,`[stateit] subscriber errors`)},s={cleanups:null,deps:null,effect:null},c=(e,t,n,r)=>{let i=s;s={cleanups:n,deps:t,effect:e};try{return r()}finally{s=i}},l=0,u=new Set,d=()=>{for(;u.size>0;){let e=[...u];u.clear(),o(new Set(e))}},f=class{subscribers=new Set;track(){!s.effect||!s.deps||(this.subscribers.add(s.effect),s.deps.add(()=>this.subscribers.delete(s.effect)))}hasSubscribers(){return this.subscribers.size>0}notify(){if(this.subscribers.size!==0){if(l>0){for(let e of this.subscribers)u.add(e);return}o(this.subscribers)}}},p=class extends f{value_;equals_;constructor(e,t){super(),this.value_=e,this.equals_=t??Object.is}get value(){return this.track(),this.value_}set value(e){this.equals_(this.value_,e)||(this.value_=e,this.notify())}update(e){this.value=e(this.value_)}},m=class extends f{value_=e;dirty_=!0;disposed_=!1;deps_=new Set;compute_;equals_;onDepChange=()=>{if(!this.disposed_){if(this.subscribers.size===0){this.dirty_=!0;return}this.recompute()&&this.notify()}};constructor(e,t){super(),this.compute_=e,this.equals_=t??Object.is,this.recompute()}recompute(){for(let e of this.deps_)e();this.deps_.clear();let t=c(this.onDepChange,this.deps_,null,this.compute_);return this.dirty_=!1,this.value_===e||!this.equals_(this.value_,t)?(this.value_=t,!0):!1}get value(){if(this.disposed_)throw Error(`[stateit] Cannot read disposed computed signal`);return this.dirty_&&this.recompute(),this.track(),this.value_}get stale(){return this.dirty_}dispose(){if(!this.disposed_){this.disposed_=!0,this.dirty_=!0;for(let e of this.deps_)e();this.deps_.clear()}}[Symbol.dispose](){this.dispose()}},h=(e,t)=>new p(e,t?.equals),g=(e,t)=>{let n=new m(e,t?.equals);return s.effect!==null&&s.cleanups!==null&&b(()=>n.dispose()),n},_=e=>{l++;try{let t=e();return--l===0&&d(),t}catch(e){throw--l===0&&d(),e}},v=(e,r)=>{let i,o=new Set,s=!1,l=!1,u=!1,d=r?.maxIterations??t,f=()=>{let e=[];i&&e.push(i),i=void 0;for(let t of o)e.push(t);o.clear(),a(e,`effect teardown errors`)},p=()=>{if(!u){if(s){l=!0;return}s=!0;try{let t=0;do{if(++t>d)throw Error(`[stateit] infinite effect loop (> ${d} iterations)`);l=!1,f();let n=[],r=c(p,o,n,e);r&&n.push(r),n.length>0&&(i=()=>{a(n,`effect cleanup errors`)})}while(l&&!u)}finally{s=!1}}};return p(),n(()=>{u||(u=!0,f())})},y=e=>c(null,null,null,e),b=e=>{if(s.cleanups===null)throw Error(`[stateit] onCleanup() must be called from inside an active effect.`);s.cleanups.push(e)},x=(e,t,n)=>{let r=n?.equals??Object.is,i=y(()=>e.value);n?.immediate&&t(i,i);let a=v(()=>{let o=e.value;if(r(i,o))return;let s=i;i=o,t(o,s),n?.once&&a()});return a};function S(e,t,r,i){if(typeof r==`function`){let a=t,o=r,s=g(()=>a(e.value)),c=x(s,o,i);return n(()=>{c(),s.dispose()})}return x(e,t,r)}var C=(e,t)=>{r(e,`[stateit] store() requires a plain object initial state.`);let n=i(e),a=h(i(e),t);return{patch(e){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`[stateit] store.patch() requires a plain object partial.`);a.value={...a.value,...e}},reset(){a.value=i(n)},update(e){let t=e(a.value);r(t,`[stateit] store.update() must return a plain object.`),a.value=t},get value(){return a.value},set value(e){r(e,`[stateit] Store value must always be a plain object.`),a.value=e}}},w=e=>e,T=e=>e,E=e=>typeof e!=`object`||!e?!1:`value`in e,D=e=>E(e)?e.value:e,O=e=>E(e)?e.value:typeof e==`function`?e():e;exports.batch=_,exports.computed=g,exports.effect=v,exports.isSignal=E,exports.onCleanup=b,exports.peekValue=D,exports.readonly=w,exports.signal=h,exports.store=C,exports.toValue=O,exports.untrack=y,exports.watch=S,exports.writable=T;
|
|
2
2
|
//# sourceMappingURL=stateit.cjs.map
|
package/dist/stateit.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateit.cjs","names":["#subscribers","#onDepChange","#dirty","#compute","#equals","#recompute","#deps","#value","#disposed","#set","#value","#equals","#initial","#frozen"],"sources":["../src/runtime.ts","../src/batch.ts","../src/types.ts","../src/computed.ts","../src/effect.ts","../src/signal.ts","../src/store.ts","../src/watch.ts"],"sourcesContent":["import type { CleanupFn, EffectCallback } from './types';\n\n/** @internal True outside of production builds; gates dev-only warnings. */\nexport const _DEV = import.meta.env.DEV;\n\nexport const _UNINITIALIZED = Symbol('stateit.uninitialized');\n\n/** @internal Active reactive tracking scope — null outside any effect/computed. */\nexport const scope = {\n cleanups: null as CleanupFn[] | null,\n deps: null as Set<CleanupFn> | null,\n effect: null as EffectCallback | null,\n};\n\n/** @internal Deferred notification queue — active only during batch(). */\nexport const queue = {\n depth: 0,\n pending: new Set<EffectCallback>(),\n};\n\nexport let _maxEffectIterations = 100;\n\n/**\n * Configures global stateit behaviour.\n * @example configureStateit({ maxEffectIterations: 200 });\n */\nexport const configureStateit = (opts: { maxEffectIterations?: number }): void => {\n if (opts.maxEffectIterations !== undefined) _maxEffectIterations = opts.maxEffectIterations;\n};\n\n/**\n * Resets the shared reactive context. Use in test setup/teardown to prevent state\n * leaks between tests when a batch or effect throws without being fully cleaned up.\n */\nexport const _resetContextForTesting = (): void => {\n queue.depth = 0;\n scope.deps = null;\n scope.effect = null;\n scope.cleanups = null;\n queue.pending.clear();\n};\n\n/** @internal Base reactive node: manages a subscriber set and batch-aware notification. */\nexport class ReactiveNode {\n #subscribers = new Set<EffectCallback>();\n\n /** Register the current tracking scope as a subscriber and store an unsubscribe\n * function in scope.deps for automatic cleanup when the effect re-runs. */\n protected _track(): void {\n if (scope.deps !== null && scope.effect !== null) {\n const fn = scope.effect;\n\n this.#subscribers.add(fn);\n scope.deps.add(() => this.#subscribers.delete(fn));\n }\n }\n\n /** Notify all subscribers. Respects batch queue depth. */\n protected _notify(): void {\n if (this.#subscribers.size === 0) return;\n\n if (queue.depth > 0) {\n for (const fn of this.#subscribers) queue.pending.add(fn);\n\n return;\n }\n\n const errors: unknown[] = [];\n\n for (const fn of [...this.#subscribers]) {\n try {\n fn();\n } catch (e) {\n errors.push(e);\n }\n }\n\n if (errors.length) {\n throw errors.length === 1 ? errors[0] : new AggregateError(errors, '[stateit] multiple subscriber errors');\n }\n }\n}\n\n/** @internal Save scope fields, swap to new tracking context, call fn, restore. */\nexport const _withCtx = <T>(\n eff: EffectCallback | null,\n deps: Set<CleanupFn> | null,\n cleanups: CleanupFn[] | null,\n fn: () => T,\n): T => {\n const pe = scope.effect;\n const pd = scope.deps;\n const pc = scope.cleanups;\n\n scope.effect = eff;\n scope.deps = deps;\n scope.cleanups = cleanups;\n\n try {\n return fn();\n } finally {\n scope.effect = pe;\n scope.deps = pd;\n scope.cleanups = pc;\n }\n};\n","import { _DEV, queue } from './runtime';\n\n/** @internal Drain and run all pending effects from the batch queue, collecting errors. */\nexport const _flushPending = (): void => {\n const toFlush = [...queue.pending];\n\n queue.pending.clear();\n\n const errors: unknown[] = [];\n\n for (const f of toFlush) {\n try {\n f();\n } catch (e) {\n errors.push(e);\n }\n }\n\n if (errors.length) throw errors.length === 1 ? errors[0] : new AggregateError(errors, '[stateit] batch errors');\n};\n\n/** Runs fn and defers all Signal notifications until fn returns, then flushes once. */\nexport const batch = <T>(fn: () => T): T => {\n queue.depth++;\n\n try {\n const result = fn();\n\n if (--queue.depth === 0) _flushPending();\n\n return result;\n } catch (e) {\n if (--queue.depth === 0) {\n try {\n _flushPending();\n } catch (flushErr) {\n if (_DEV)\n console.error(\n '[stateit] batch: a secondary flush error was suppressed (callback error takes precedence)',\n flushErr,\n );\n }\n }\n\n throw e;\n }\n};\n","/** A function that tears down a subscription or effect. */\nexport type CleanupFn = () => void;\n\n/** The shape of a function passed to `effect()`. Can return an optional cleanup. */\nexport type EffectCallback = () => CleanupFn | void;\n\nexport type EqualityFn<T> = (a: T, b: T) => boolean;\n\n/** Options accepted by signal(), computed(), writable(), and store(). */\nexport type ReactiveOptions<T> = { equals?: EqualityFn<T> };\n\n/** Shared interface for disposable reactive values (computed, writable). Supports the TC39 `using` declaration. */\nexport interface Disposable {\n dispose(): void;\n [Symbol.dispose](): void;\n}\n\n/**\n * A callable subscription handle returned by `effect()` and `watch()`.\n * Can be called directly or via `.dispose()` to stop the subscription.\n * Supports the TC39 `using` declaration via `[Symbol.dispose]`.\n */\nexport interface Subscription {\n (): void;\n dispose(): void;\n [Symbol.dispose](): void;\n}\n\nexport const _SIGNAL_BRAND = Symbol('stateit.signal');\nexport const _STORE_BRAND = Symbol('stateit.store');\n\n/** Public read-only signal interface. */\nexport interface ReadonlySignal<T> {\n readonly [_SIGNAL_BRAND]: true;\n readonly value: T;\n peek(): T;\n}\n\n/** Public read/write signal interface. */\nexport interface Signal<T> extends ReadonlySignal<T> {\n value: T;\n /** Update the value by applying a function to the current value. */\n update(fn: (current: T) => T): void;\n}\n","import { ReactiveNode, _DEV, _UNINITIALIZED, _withCtx } from './runtime';\nimport {\n type CleanupFn,\n type Disposable,\n type EffectCallback,\n type EqualityFn,\n type ReactiveOptions,\n type ReadonlySignal,\n type Signal,\n _SIGNAL_BRAND,\n} from './types';\n\n/** A derived read-only signal with an explicit dispose method. */\nexport interface ComputedSignal<T> extends ReadonlySignal<T>, Disposable {\n /** True when the computed value is stale (deps changed but not yet re-read) or disposed. */\n readonly stale: boolean;\n}\n\n/** @internal\n * Lazy computed node. Seeded once at construction so .peek() is immediately valid\n * (unless { lazy: true } is passed, in which case first compute defers to first read).\n * - On dep change: marks dirty, notifies downstream (no recompute yet).\n * - On .value read: recomputes if dirty, re-tracks fresh deps.\n * - After dispose: _track() is skipped to prevent leaking outer effects.\n */\nexport class ComputedNode<T> extends ReactiveNode implements ComputedSignal<T> {\n readonly [_SIGNAL_BRAND] = true as const;\n #compute: () => T;\n #value: T | typeof _UNINITIALIZED = _UNINITIALIZED;\n #dirty = true;\n #disposed = false;\n #equals: EqualityFn<T>;\n #deps = new Set<CleanupFn>();\n\n readonly #onDepChange: EffectCallback = () => {\n if (!this.#dirty) {\n this.#dirty = true;\n this._notify();\n }\n };\n\n constructor(compute: () => T, options?: ReactiveOptions<T> & { lazy?: boolean }) {\n super();\n this.#compute = compute;\n this.#equals = options?.equals ?? Object.is;\n\n if (!options?.lazy) this.#recompute(); // seed: ensures peek() is valid immediately\n }\n\n #recompute(): void {\n for (const unsub of this.#deps) unsub();\n this.#deps.clear();\n\n const result = _withCtx(this.#onDepChange, this.#deps, null, this.#compute);\n\n this.#dirty = false;\n\n if (this.#value === _UNINITIALIZED || !this.#equals(this.#value as T, result)) {\n this.#value = result;\n }\n }\n\n get value(): T {\n if (this.#disposed) {\n if (_DEV) console.warn('[stateit] Reading a disposed ComputedSignal returns a stale value.');\n\n return this.#value as T;\n }\n\n if (this.#dirty) this.#recompute();\n\n this._track();\n\n return this.#value as T;\n }\n\n peek(): T {\n if (this.#value === _UNINITIALIZED) {\n if (this.#disposed) {\n if (_DEV)\n console.warn(\n '[stateit] peek() called on a disposed lazy ComputedSignal that was never read — returning undefined.',\n );\n\n return undefined as unknown as T;\n }\n\n this.#recompute();\n }\n\n return this.#value as T;\n }\n\n get stale(): boolean {\n return this.#dirty || this.#disposed;\n }\n\n dispose(): void {\n if (this.#disposed) return;\n\n this.#disposed = true;\n for (const unsub of this.#deps) unsub();\n this.#deps.clear();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n}\n\n/** Creates a derived read-only Signal whose value is recomputed lazily on `.value` read\n * when dependencies have changed. Call `.dispose()` to stop tracking and free dependencies.\n * Pass `{ lazy: true }` to defer the initial computation until the first `.value` read. */\nexport const computed = <T>(compute: () => T, options?: ReactiveOptions<T> & { lazy?: boolean }): ComputedSignal<T> =>\n new ComputedNode(compute, options);\n\n/** A bidirectional computed Signal with an explicit dispose method. */\nexport interface WritableSignal<T> extends Signal<T>, Disposable {\n /** True when the backing computed value is stale (deps changed but not yet re-read) or disposed. */\n readonly stale: boolean;\n}\n\n/** @internal */\nexport class WritableNode<T> extends ComputedNode<T> implements WritableSignal<T> {\n readonly #set: (v: T) => void;\n\n constructor(get: () => T, set: (v: T) => void, options?: ReactiveOptions<T>) {\n super(get, options);\n this.#set = set;\n }\n\n override get value(): T {\n return super.value;\n }\n\n set value(v: T) {\n this.#set(v);\n }\n\n update(fn: (current: T) => T): void {\n this.#set(fn(this.peek()));\n }\n}\n\n/** Creates a bidirectional computed Signal. Reads track the getter reactively;\n * writes are forwarded to `set`. Call `.dispose()` to stop tracking and free dependencies. */\nexport const writable = <T>(get: () => T, set: (value: T) => void, options?: ReactiveOptions<T>): WritableSignal<T> =>\n new WritableNode(get, set, options);\n\n/**\n * Creates a derived ComputedSignal by combining multiple source signals through a projector\n * function. Each source is passed as a positional argument to `fn`; the projector is\n * re-evaluated whenever any source changes.\n *\n * @example\n * const total = derived([price, quantity, discount], (p, q, d) => p * q * (1 - d));\n */\nexport const derived = <const Srcs extends ReadonlyArray<ReadonlySignal<unknown>>, R>(\n sources: Srcs,\n fn: (...values: { [K in keyof Srcs]: Srcs[K] extends ReadonlySignal<infer V> ? V : never }) => R,\n options?: ReactiveOptions<R>,\n): ComputedSignal<R> => computed(() => (fn as (...args: any[]) => R)(...sources.map((s) => s.value)), options);\n","import { _DEV, _maxEffectIterations, _withCtx, scope } from './runtime';\nimport { type CleanupFn, type EffectCallback, type Subscription } from './types';\n\n/** Options for the `effect()` primitive. */\nexport type EffectOptions = {\n /**\n * Maximum re-entrant iterations before throwing to prevent infinite loops.\n * Overrides the global value set via `configureStateit` for this specific effect.\n */\n maxIterations?: number;\n /**\n * Called when the effect function throws. When provided, the effect is automatically\n * disposed after the first error — it won't re-run on subsequent dependency changes.\n */\n onError?: (error: unknown) => void;\n};\n\n/** Runs fn immediately and re-runs it whenever any Signal read inside it changes. Returns a dispose handle. */\nexport const effect = (fn: EffectCallback, options?: EffectOptions): Subscription => {\n let cleanup: CleanupFn | undefined;\n const deps = new Set<CleanupFn>();\n let running = false;\n let dirty = false;\n let disposed = false;\n const maxIter = options?.maxIterations ?? _maxEffectIterations;\n\n /** Tears down the current run: calls cleanup and unsubscribes all deps. */\n const teardown = (): void => {\n cleanup?.();\n cleanup = undefined;\n for (const unsub of deps) unsub();\n deps.clear();\n };\n\n /** Runs a single iteration: tears down previous deps/cleanup, re-executes fn, registers fresh deps.\n * Returns true if onError handled a throw (caller should break the loop). */\n const runIteration = (): boolean => {\n dirty = false;\n teardown();\n\n const cleanups: CleanupFn[] = [];\n let thrownError: unknown;\n let threw = false;\n\n try {\n _withCtx(runner, deps, cleanups, () => {\n const result = fn();\n\n if (typeof result === 'function') cleanups.push(result);\n });\n } catch (e) {\n if (options?.onError) {\n threw = true;\n thrownError = e;\n } else throw e;\n }\n\n cleanup =\n cleanups.length > 0\n ? () => {\n for (const c of cleanups) c();\n }\n : undefined;\n\n if (threw) {\n teardown(); // flush onCleanup registrations from the throwing run\n options!.onError!(thrownError);\n disposed = true;\n }\n\n return threw;\n };\n\n const runner: EffectCallback = () => {\n if (disposed || running) {\n if (running) dirty = true;\n\n return;\n }\n\n running = true;\n\n try {\n let iterations = 0;\n\n do {\n if (++iterations > maxIter)\n throw new Error(`[stateit] effect: possible infinite reactive loop (> ${maxIter} iterations)`);\n\n if (runIteration()) break;\n } while (dirty);\n } finally {\n running = false;\n }\n };\n\n runner();\n\n const dispose = (): void => {\n if (disposed) return;\n\n disposed = true;\n teardown();\n };\n\n return Object.assign(dispose, { dispose, [Symbol.dispose]: dispose }) as Subscription;\n};\n\n/** Runs fn without registering any reactive dependencies. */\nexport const untrack = <T>(fn: () => T): T => _withCtx(null, null, null, fn);\n\n/**\n * Registers a cleanup function within the currently running effect.\n * Called before the effect re-runs and on final dispose.\n * Allows nested helpers to register teardown without needing the effect's return value.\n *\n * @example\n * effect(() => {\n * const id = setInterval(() => { ... }, 1000);\n * onCleanup(() => clearInterval(id));\n * });\n */\nexport const onCleanup = (fn: CleanupFn): void => {\n if (_DEV && scope.cleanups === null) {\n console.warn('[stateit] onCleanup() called outside of an active effect — the cleanup will never run.');\n }\n\n scope.cleanups?.push(fn);\n};\n","import { ReactiveNode } from './runtime';\nimport { type EqualityFn, type ReactiveOptions, type ReadonlySignal, type Signal, _SIGNAL_BRAND } from './types';\n\n/** @internal */\nexport class SignalImpl<T> extends ReactiveNode implements Signal<T> {\n readonly [_SIGNAL_BRAND] = true as const;\n #value: T;\n #equals: EqualityFn<T>;\n\n constructor(initial: T, options?: ReactiveOptions<T>) {\n super();\n this.#value = initial;\n this.#equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n this._track();\n\n return this.#value;\n }\n\n set value(next: T) {\n if (this.#equals(this.#value, next)) return;\n\n this.#value = next;\n this._notify();\n }\n\n update(fn: (current: T) => T): void {\n this.value = fn(this.#value);\n }\n\n peek(): T {\n return this.#value;\n }\n}\n\n/** Creates a reactive signal holding a single value. */\nexport const signal = <T>(initial: T, options?: ReactiveOptions<T>): Signal<T> => new SignalImpl(initial, options);\n\nconst _readonlyCache = new WeakMap<object, ReadonlySignal<unknown>>();\n\n/**\n * Returns a stable read-only view of a signal. Hides the setter at both type and runtime\n * level. The wrapper is cached — repeated calls with the same signal return the same reference.\n */\nexport const readonly = <T>(sig: ReadonlySignal<T>): ReadonlySignal<T> => {\n const cached = _readonlyCache.get(sig as object);\n\n if (cached) return cached as ReadonlySignal<T>;\n\n const wrapper: ReadonlySignal<T> = {\n get [_SIGNAL_BRAND]() {\n return true as const;\n },\n peek: () => sig.peek(),\n get value() {\n return sig.value;\n },\n };\n\n _readonlyCache.set(sig as object, wrapper as ReadonlySignal<unknown>);\n\n return wrapper;\n};\n\n/** Type guard -- identifies Signal instances (works through composition and subclasses). */\nexport const isSignal = <T = unknown>(value: unknown): value is ReadonlySignal<T> =>\n typeof value === 'object' && value !== null && _SIGNAL_BRAND in (value as object);\n\n/** Unwraps a plain value or Signal to its current value. Reads are tracked if called inside an effect. */\nexport const toValue = <T>(v: T | ReadonlySignal<T>): T => (isSignal<T>(v) ? v.value : v);\n\n/** Unwraps a plain value or Signal to its current value without registering a reactive subscription. */\nexport const peekValue = <T>(v: T | ReadonlySignal<T>): T => (isSignal<T>(v) ? v.peek() : v);\n","import { type ComputedSignal, computed } from './computed';\nimport { _DEV } from './runtime';\nimport { SignalImpl } from './signal';\nimport { type EqualityFn, type ReactiveOptions, type Signal, _STORE_BRAND } from './types';\n\n/**\n * Shallow structural equality — compares own enumerable keys by reference.\n * This is the default equality function used by `store()`. Export it to avoid\n * reimplementation when composing custom `StoreOptions.equals`.\n */\nexport const shallowEqual: EqualityFn<unknown> = (a, b) => {\n if (a === b) return true;\n\n if (a == null || b == null) return a === b;\n\n if (typeof a !== 'object' || typeof b !== 'object') return false;\n\n const keysA = Object.keys(a as object);\n const keysB = Object.keys(b as object);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!Object.is((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key])) return false;\n }\n\n return true;\n};\n\nexport type StoreOptions<T extends object> = {\n /** Custom equality for top-level change detection. Default: shallowEqual */\n equals?: EqualityFn<T>;\n};\n\n/** Reactive store for object state. Implements Signal<T> so all signal primitives work natively. */\nexport interface Store<T extends object> extends Signal<T> {\n readonly frozen: boolean;\n /** Shallow-merge a partial object into the current state. */\n patch(partial: Partial<T>): void;\n /** Derive the next state from the current state via an updater function.\n * Receives a shallow copy of the current state — mutations in the updater are safe. */\n update(fn: (s: T) => T): void;\n /** Reset to the original initial state. */\n reset(): void;\n /** Create a lazily recomputed derived signal from a slice of this store's state. */\n select<U>(selector: (s: T) => U, options?: ReactiveOptions<U>): ComputedSignal<U>;\n /** Freeze the store. Further writes via patch/update/reset are silently ignored. */\n freeze(): void;\n}\n\n/** @internal */\nclass StoreImpl<T extends object> extends SignalImpl<T> implements Store<T> {\n readonly [_STORE_BRAND] = true as const;\n\n readonly #initial: T;\n #frozen = false;\n\n constructor(initial: T, options?: StoreOptions<T>) {\n super(initial, { equals: options?.equals ?? (shallowEqual as EqualityFn<T>) });\n this.#initial = { ...initial }; // defensive copy — external mutation cannot corrupt reset()\n }\n\n get frozen(): boolean {\n return this.#frozen;\n }\n\n override get value(): T {\n return super.value;\n }\n\n override set value(next: T) {\n if (this.#frozen) {\n if (_DEV) console.warn('[stateit] store is frozen — write ignored.');\n\n return;\n }\n\n super.value = next;\n }\n\n patch(partial: Partial<T>): void {\n this.value = { ...this.peek(), ...partial };\n }\n\n update(fn: (s: T) => T): void {\n this.value = fn({ ...this.peek() });\n }\n\n reset(): void {\n this.value = { ...this.#initial };\n }\n\n select<U>(selector: (s: T) => U, options?: ReactiveOptions<U>): ComputedSignal<U> {\n return computed(() => selector(this.value), options);\n }\n\n freeze(): void {\n this.#frozen = true;\n }\n}\n\n/** Creates a reactive store for the object state. */\nexport const store = <T extends object>(initial: T, options?: StoreOptions<T>): Store<T> =>\n new StoreImpl(initial, options);\n\n/** Type guard -- identifies Store instances. */\nexport const isStore = <T extends object = Record<string, unknown>>(value: unknown): value is Store<T> =>\n typeof value === 'object' && value !== null && _STORE_BRAND in value;\n","import { effect } from './effect';\nimport { type EqualityFn, type ReadonlySignal, type Subscription } from './types';\n\nexport type WatchOptions<T> = {\n /** Custom equality; suppresses the callback when old and new values are equal. Default: Object.is */\n equals?: EqualityFn<T>;\n /** Fire the callback immediately with the current value on subscribe. */\n immediate?: boolean;\n /**\n * Auto-unsubscribe after the first *change* invocation.\n * When combined with `immediate`, the immediate call does not count against this quota —\n * the callback may fire up to twice total.\n */\n once?: boolean;\n};\n\n/**\n * Watches a Signal and calls cb when its value changes. Returns a dispose handle.\n * Does not fire on initial subscription unless `{ immediate: true }` is passed.\n * To watch a derived slice, compose with `store.select()` or `computed()`:\n *\n * @example\n * const stop = watch(count, (next, prev) => console.log(prev, '->', next));\n * const stop = watch(userStore.select(s => s.name), (name) => ...);\n */\nexport const watch = <T>(\n source: ReadonlySignal<T>,\n cb: (value: T, prev: T) => void,\n options?: WatchOptions<T>,\n): Subscription => {\n const eq: EqualityFn<T> = options?.equals ?? Object.is;\n let prev = source.peek();\n\n if (options?.immediate) cb(prev, prev);\n\n // Use `let` so the stop reference is readable inside the callback without TDZ risk.\n let stop: Subscription;\n\n // eslint-disable-next-line prefer-const\n stop = effect(() => {\n const next = source.value;\n\n if (!eq(prev, next)) {\n const old = prev;\n\n prev = next;\n cb(next, old);\n\n if (options?.once) stop();\n }\n });\n\n return stop;\n};\n\n/**\n * Returns a Promise that resolves with the next value of `source` that satisfies the optional predicate.\n * Disposes automatically after one emission — no cleanup needed.\n * Pass `{ signal: AbortSignal }` to cancel early; the promise rejects with the abort reason.\n *\n * @example\n * const name = await nextValue(userStore.select(s => s.name));\n * const nonZero = await nextValue(count, v => v > 0, { signal: AbortSignal.timeout(5000) });\n */\nexport const nextValue = <T>(\n source: ReadonlySignal<T>,\n predicate?: (v: T) => boolean,\n options?: { signal?: AbortSignal },\n): Promise<T> =>\n new Promise<T>((resolve, reject) => {\n const signal = options?.signal;\n\n try {\n signal?.throwIfAborted();\n } catch (err) {\n reject(err);\n\n return;\n }\n\n const stop = watch(source, (v) => {\n if (!predicate || predicate(v)) {\n stop();\n signal?.removeEventListener('abort', onAbort);\n resolve(v);\n }\n });\n\n const onAbort = () => {\n stop();\n reject(signal!.reason);\n };\n\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n"],"mappings":"mEAKA,IAAa,EAAiB,OAAO,wBAAwB,CAGhD,EAAQ,CACnB,SAAU,KACV,KAAM,KACN,OAAQ,KACT,CAGY,EAAQ,CACnB,MAAO,EACP,QAAS,IAAI,IACd,CAEU,EAAuB,IAMrB,EAAoB,GAAiD,CAC5E,EAAK,sBAAwB,IAAA,KAAW,EAAuB,EAAK,sBAO7D,MAAsC,CACjD,EAAM,MAAQ,EACd,EAAM,KAAO,KACb,EAAM,OAAS,KACf,EAAM,SAAW,KACjB,EAAM,QAAQ,OAAO,EAIV,EAAb,KAA0B,CACxB,GAAe,IAAI,IAInB,QAAyB,CACvB,GAAI,EAAM,OAAS,MAAQ,EAAM,SAAW,KAAM,CAChD,IAAM,EAAK,EAAM,OAEjB,MAAA,EAAkB,IAAI,EAAG,CACzB,EAAM,KAAK,QAAU,MAAA,EAAkB,OAAO,EAAG,CAAC,EAKtD,SAA0B,CACxB,GAAI,MAAA,EAAkB,OAAS,EAAG,OAElC,GAAI,EAAM,MAAQ,EAAG,CACnB,IAAK,IAAM,KAAM,MAAA,EAAmB,EAAM,QAAQ,IAAI,EAAG,CAEzD,OAGF,IAAM,EAAoB,EAAE,CAE5B,IAAK,IAAM,IAAM,CAAC,GAAG,MA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3,"file":"stateit.cjs","names":[],"sources":["../src/stateit.ts"],"sourcesContent":["import type {\n CleanupFn,\n ComputedSignal,\n EffectCallback,\n EffectOptions,\n EqualityFn,\n ReactiveOptions,\n ReadonlySignal,\n Signal,\n Store,\n Subscription,\n WatchOptions,\n} from './types';\n\n// === CONSTANTS ===\nconst UNINITIALIZED = Symbol('stateit.uninitialized');\nconst DEFAULT_MAX_ITERATIONS = 100;\n\n// === HELPERS ===\nconst toSubscription = (dispose: () => void): Subscription =>\n Object.assign(dispose, { dispose, [Symbol.dispose]: dispose }) as Subscription;\n\nconst ensureObject = (value: unknown, message: string): void => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(message);\n }\n};\n\nconst clone = <T>(value: T): T => structuredClone(value);\n\n// === UNIFIED ERROR HANDLING ===\nconst runCallbacks = (callbacks: CleanupFn[], context: string): void => {\n const errors: unknown[] = [];\n\n for (const callback of callbacks) {\n try {\n callback();\n } catch (e) {\n errors.push(e);\n }\n }\n\n if (errors.length === 1) throw errors[0];\n\n if (errors.length > 1) {\n throw new AggregateError(errors, `[stateit] ${context}`);\n }\n};\n\nconst runSubscribers = (subscribers: Set<EffectCallback>): void => {\n const errors: unknown[] = [];\n\n for (const fn of [...subscribers]) {\n try {\n fn();\n } catch (e) {\n errors.push(e);\n }\n }\n\n if (errors.length === 1) throw errors[0];\n\n if (errors.length > 1) {\n throw new AggregateError(errors, '[stateit] subscriber errors');\n }\n};\n\n// === GLOBAL REACTIVE GRAPH ===\ninterface EffectScope {\n effect: EffectCallback | null;\n deps: Set<CleanupFn> | null;\n cleanups: CleanupFn[] | null;\n}\n\nlet currentScope: EffectScope = {\n cleanups: null,\n deps: null,\n effect: null,\n};\n\nconst withScope = <T>(\n effect: EffectCallback | null,\n deps: Set<CleanupFn> | null,\n cleanups: CleanupFn[] | null,\n fn: () => T,\n): T => {\n const prev = currentScope;\n\n currentScope = { cleanups, deps, effect };\n\n try {\n return fn();\n } finally {\n currentScope = prev;\n }\n};\n\n// === BATCH QUEUE ===\nlet batchDepth = 0;\nconst batchQueue = new Set<EffectCallback>();\n\nconst flushBatch = (): void => {\n while (batchQueue.size > 0) {\n const pending = [...batchQueue];\n\n batchQueue.clear();\n\n runSubscribers(new Set(pending));\n }\n};\n\n// === BASE REACTIVE NODE ===\nclass ReactiveNode {\n protected subscribers = new Set<EffectCallback>();\n\n protected track(): void {\n if (!currentScope.effect || !currentScope.deps) return;\n\n this.subscribers.add(currentScope.effect);\n currentScope.deps.add(() => this.subscribers.delete(currentScope.effect!));\n }\n\n protected hasSubscribers(): boolean {\n return this.subscribers.size > 0;\n }\n\n protected notify(): void {\n if (this.subscribers.size === 0) return;\n\n if (batchDepth > 0) {\n for (const fn of this.subscribers) batchQueue.add(fn);\n\n return;\n }\n\n runSubscribers(this.subscribers);\n }\n}\n\n// === SIGNAL IMPLEMENTATION ===\nclass SignalImpl<T> extends ReactiveNode implements Signal<T> {\n private value_: T;\n private equals_: EqualityFn<T>;\n\n constructor(initial: T, equals?: EqualityFn<T>) {\n super();\n this.value_ = initial;\n this.equals_ = equals ?? Object.is;\n }\n\n get value(): T {\n this.track();\n\n return this.value_;\n }\n\n set value(next: T) {\n if (this.equals_(this.value_, next)) return;\n\n this.value_ = next;\n this.notify();\n }\n\n update(fn: (current: T) => T): void {\n this.value = fn(this.value_);\n }\n}\n\n// === COMPUTED IMPLEMENTATION ===\nclass ComputedImpl<T> extends ReactiveNode implements ComputedSignal<T> {\n private value_: T | typeof UNINITIALIZED = UNINITIALIZED;\n private dirty_ = true;\n private disposed_ = false;\n private deps_ = new Set<CleanupFn>();\n private compute_: () => T;\n private equals_: EqualityFn<T>;\n\n private readonly onDepChange: EffectCallback = () => {\n if (this.disposed_) return;\n\n if (this.subscribers.size === 0) {\n this.dirty_ = true;\n\n return;\n }\n\n if (this.recompute()) this.notify();\n };\n\n constructor(compute: () => T, equals?: EqualityFn<T>) {\n super();\n this.compute_ = compute;\n this.equals_ = equals ?? Object.is;\n this.recompute();\n }\n\n private recompute(): boolean {\n for (const unsub of this.deps_) unsub();\n this.deps_.clear();\n\n const next = withScope(this.onDepChange, this.deps_, null, this.compute_);\n\n this.dirty_ = false;\n\n if (this.value_ === UNINITIALIZED || !this.equals_(this.value_ as T, next)) {\n this.value_ = next;\n\n return true;\n }\n\n return false;\n }\n\n get value(): T {\n if (this.disposed_) {\n throw new Error('[stateit] Cannot read disposed computed signal');\n }\n\n if (this.dirty_) this.recompute();\n\n this.track();\n\n return this.value_ as T;\n }\n\n get stale(): boolean {\n return this.dirty_;\n }\n\n dispose(): void {\n if (this.disposed_) return;\n\n this.disposed_ = true;\n this.dirty_ = true;\n for (const unsub of this.deps_) unsub();\n this.deps_.clear();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n}\n\n// === CORE API ===\n\nexport const signal = <T>(initial: T, options?: ReactiveOptions<T>): Signal<T> =>\n new SignalImpl(initial, options?.equals);\n\nexport const computed = <T>(compute: () => T, options?: ReactiveOptions<T>): ComputedSignal<T> => {\n const comp = new ComputedImpl(compute, options?.equals);\n\n // Auto-dispose when created inside effect\n if (currentScope.effect !== null && currentScope.cleanups !== null) {\n onCleanup(() => comp.dispose());\n }\n\n return comp;\n};\n\nexport const batch = <T>(fn: () => T): T => {\n batchDepth++;\n\n try {\n const result = fn();\n\n if (--batchDepth === 0) flushBatch();\n\n return result;\n } catch (e) {\n if (--batchDepth === 0) flushBatch();\n\n throw e;\n }\n};\n\nexport const effect = (fn: EffectCallback, options?: EffectOptions): Subscription => {\n let cleanup: CleanupFn | undefined;\n const deps = new Set<CleanupFn>();\n let isRunning = false;\n let isDirty = false;\n let isDisposed = false;\n const maxIterations = options?.maxIterations ?? DEFAULT_MAX_ITERATIONS;\n\n const teardown = (): void => {\n const callbacks: CleanupFn[] = [];\n\n if (cleanup) callbacks.push(cleanup);\n\n cleanup = undefined;\n\n for (const unsub of deps) callbacks.push(unsub);\n deps.clear();\n\n runCallbacks(callbacks, 'effect teardown errors');\n };\n\n const run = (): void => {\n if (isDisposed) return;\n\n if (isRunning) {\n isDirty = true;\n\n return;\n }\n\n isRunning = true;\n\n try {\n let iterations = 0;\n\n do {\n if (++iterations > maxIterations) {\n throw new Error(`[stateit] infinite effect loop (> ${maxIterations} iterations)`);\n }\n\n isDirty = false;\n teardown();\n\n const localCleanups: CleanupFn[] = [];\n const returnedCleanup = withScope(run, deps, localCleanups, fn);\n\n if (returnedCleanup) localCleanups.push(returnedCleanup);\n\n if (localCleanups.length > 0) {\n cleanup = () => {\n runCallbacks(localCleanups, 'effect cleanup errors');\n };\n }\n } while (isDirty && !isDisposed);\n } finally {\n isRunning = false;\n }\n };\n\n run();\n\n return toSubscription(() => {\n if (isDisposed) return;\n\n isDisposed = true;\n teardown();\n });\n};\n\nexport const untrack = <T>(fn: () => T): T => {\n return withScope(null, null, null, fn);\n};\n\nexport const onCleanup = (fn: CleanupFn): void => {\n if (currentScope.cleanups === null) {\n throw new Error('[stateit] onCleanup() must be called from inside an active effect.');\n }\n\n currentScope.cleanups.push(fn);\n};\n\nconst watchBase = <T>(\n source: ReadonlySignal<T>,\n cb: (value: T, prev: T) => void,\n watchOptions?: WatchOptions<T>,\n): Subscription => {\n const equals = watchOptions?.equals ?? Object.is;\n let prev = untrack(() => source.value);\n\n if (watchOptions?.immediate) cb(prev, prev);\n\n const stop = effect(() => {\n const next = source.value;\n\n if (equals(prev, next)) return;\n\n const old = prev;\n\n prev = next;\n cb(next, old);\n\n if (watchOptions?.once) stop();\n });\n\n return stop;\n};\n\nfunction watch<T>(\n source: ReadonlySignal<T>,\n cb: (value: T, prev: T) => void,\n watchOptions?: WatchOptions<T>,\n): Subscription;\nfunction watch<S, T>(\n source: ReadonlySignal<S>,\n selector: (value: S) => T,\n cb: (value: T, prev: T) => void,\n watchOptions?: WatchOptions<T>,\n): Subscription;\nfunction watch<S, T>(\n source: ReadonlySignal<S>,\n selectorOrCb: ((value: S) => T) | ((value: S, prev: S) => void),\n maybeCb?: ((value: T, prev: T) => void) | WatchOptions<S>,\n maybeOptions?: WatchOptions<T>,\n): Subscription {\n if (typeof maybeCb === 'function') {\n const selector = selectorOrCb as (value: S) => T;\n const cb = maybeCb as (value: T, prev: T) => void;\n const selected = computed(() => selector(source.value));\n const stop = watchBase(selected, cb, maybeOptions);\n\n return toSubscription(() => {\n stop();\n selected.dispose();\n });\n }\n\n const cb = selectorOrCb as (value: S, prev: S) => void;\n\n return watchBase(source, cb, maybeCb as WatchOptions<S> | undefined);\n}\n\nexport { watch };\n\nexport const store = <T extends object>(initial: T, storeOptions?: ReactiveOptions<T>): Store<T> => {\n ensureObject(initial, '[stateit] store() requires a plain object initial state.');\n\n const initialSnapshot = clone(initial);\n const state = signal(clone(initial), storeOptions);\n\n return {\n patch(partial: Partial<T>): void {\n if (typeof partial !== 'object' || partial === null || Array.isArray(partial)) {\n throw new TypeError('[stateit] store.patch() requires a plain object partial.');\n }\n\n state.value = { ...state.value, ...partial };\n },\n reset(): void {\n state.value = clone(initialSnapshot);\n },\n update(fn: (current: T) => T): void {\n const next = fn(state.value);\n\n ensureObject(next, '[stateit] store.update() must return a plain object.');\n state.value = next;\n },\n get value(): T {\n return state.value;\n },\n set value(next: T) {\n ensureObject(next, '[stateit] Store value must always be a plain object.');\n state.value = next;\n },\n };\n};\n\n// === TYPE HELPERS ===\n\nexport const readonly = <T>(input: ReadonlySignal<T>): ReadonlySignal<T> => input;\n\nexport const writable = <T>(input: Signal<T>): Signal<T> => input;\n\nexport const isSignal = <T = unknown>(value: unknown): value is ReadonlySignal<T> => {\n if (typeof value !== 'object' || value === null) return false;\n\n const candidate = value as Partial<ReadonlySignal<T>>;\n\n return 'value' in candidate;\n};\n\nexport const peekValue = <T>(input: T | ReadonlySignal<T>): T => (isSignal<T>(input) ? input.value : input);\n\nexport const toValue = <T>(input: T | ReadonlySignal<T> | (() => T)): T => {\n if (isSignal<T>(input)) return input.value;\n\n if (typeof input === 'function') return (input as () => T)();\n\n return input;\n};\n"],"mappings":"mEAeA,IAAM,EA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AS,EAE9C,OAAc,CACZ,EAAM,MAAQ,EAAM,EAAgB,EAEtC,OAAO,EAA6B,CAClC,IAAM,EAAO,EAAG,EAAM,MAAM,CAE5B,EAAa,EAAM,uDAAuD,CAC1E,EAAM,MAAQ,GAEhB,IAAI,OAAW,CACb,OAAO,EAAM,OAEf,IAAI,MAAM,EAAS,CACjB,EAAa,EAAM,uDAAuD,CAC1E,EAAM,MAAQ,GAEjB,EAKU,EAAe,GAAgD,EAE/D,EAAe,GAAgC,EAE/C,EAAyB,GAChC,OAAO,GAAU,WAAY,EAAuB,GAIjD,UAFW,EAKP,EAAgB,GAAqC,EAAY,EAAM,CAAG,EAAM,MAAQ,EAExF,EAAc,GACrB,EAAY,EAAM,CAAS,EAAM,MAEjC,OAAO,GAAU,WAAoB,GAAmB,CAErD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CleanupFn, ComputedSignal, EffectCallback, EffectOptions, ReactiveOptions, ReadonlySignal, Signal, Store, Subscription, WatchOptions } from './types';
|
|
2
|
+
export declare const signal: <T>(initial: T, options?: ReactiveOptions<T>) => Signal<T>;
|
|
3
|
+
export declare const computed: <T>(compute: () => T, options?: ReactiveOptions<T>) => ComputedSignal<T>;
|
|
4
|
+
export declare const batch: <T>(fn: () => T) => T;
|
|
5
|
+
export declare const effect: (fn: EffectCallback, options?: EffectOptions) => Subscription;
|
|
6
|
+
export declare const untrack: <T>(fn: () => T) => T;
|
|
7
|
+
export declare const onCleanup: (fn: CleanupFn) => void;
|
|
8
|
+
declare function watch<T>(source: ReadonlySignal<T>, cb: (value: T, prev: T) => void, watchOptions?: WatchOptions<T>): Subscription;
|
|
9
|
+
declare function watch<S, T>(source: ReadonlySignal<S>, selector: (value: S) => T, cb: (value: T, prev: T) => void, watchOptions?: WatchOptions<T>): Subscription;
|
|
10
|
+
export { watch };
|
|
11
|
+
export declare const store: <T extends object>(initial: T, storeOptions?: ReactiveOptions<T>) => Store<T>;
|
|
12
|
+
export declare const readonly: <T>(input: ReadonlySignal<T>) => ReadonlySignal<T>;
|
|
13
|
+
export declare const writable: <T>(input: Signal<T>) => Signal<T>;
|
|
14
|
+
export declare const isSignal: <T = unknown>(value: unknown) => value is ReadonlySignal<T>;
|
|
15
|
+
export declare const peekValue: <T>(input: T | ReadonlySignal<T>) => T;
|
|
16
|
+
export declare const toValue: <T>(input: T | ReadonlySignal<T> | (() => T)) => T;
|
|
17
|
+
//# sourceMappingURL=stateit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateit.d.ts","sourceRoot":"","sources":["../src/stateit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,cAAc,EACd,aAAa,EAEb,eAAe,EACf,cAAc,EACd,MAAM,EACN,KAAK,EACL,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAC;AAyOjB,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,SAAS,CAAC,EAAE,UAAU,eAAe,CAAC,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,CACnC,CAAC;AAE3C,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,SAAS,MAAM,CAAC,EAAE,UAAU,eAAe,CAAC,CAAC,CAAC,KAAG,cAAc,CAAC,CAAC,CAS5F,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,IAAI,MAAM,CAAC,KAAG,CActC,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,IAAI,cAAc,EAAE,UAAU,aAAa,KAAG,YAmEpE,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,IAAI,MAAM,CAAC,KAAG,CAExC,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,IAAI,SAAS,KAAG,IAMzC,CAAC;AA4BF,iBAAS,KAAK,CAAC,CAAC,EACd,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EACzB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,E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