@vielzeug/ripple 1.3.0 → 2.0.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 +33 -72
- package/dist/_async.cjs +2 -0
- package/dist/_async.cjs.map +1 -0
- package/dist/_async.d.ts +40 -0
- package/dist/_async.d.ts.map +1 -0
- package/dist/_async.js +75 -0
- package/dist/_async.js.map +1 -0
- package/dist/_store.cjs +2 -0
- package/dist/_store.cjs.map +1 -0
- package/dist/_store.d.ts +20 -0
- package/dist/_store.d.ts.map +1 -0
- package/dist/_store.js +24 -0
- package/dist/_store.js.map +1 -0
- package/dist/_watch.cjs +2 -0
- package/dist/_watch.cjs.map +1 -0
- package/dist/_watch.d.ts +15 -0
- package/dist/_watch.d.ts.map +1 -0
- package/dist/_watch.js +18 -0
- package/dist/_watch.js.map +1 -0
- package/dist/async.cjs +1 -0
- package/dist/async.d.ts +3 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +2 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +2 -15
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +34 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -11
- package/dist/index.js.map +1 -0
- package/dist/ripple.cjs +1 -1
- package/dist/ripple.cjs.map +1 -1
- package/dist/ripple.iife.js +1 -1
- package/dist/ripple.iife.js.map +1 -1
- package/dist/ripple.js +1 -1
- package/dist/ripple.js.map +1 -1
- package/dist/runtime.cjs +2 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.ts +98 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +340 -0
- package/dist/runtime.js.map +1 -0
- package/dist/store.cjs +1 -2
- package/dist/store.d.ts +2 -57
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +2 -207
- package/dist/types.d.ts +37 -301
- package/dist/types.d.ts.map +1 -1
- package/dist/watch.cjs +1 -0
- package/dist/watch.d.ts +3 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +2 -0
- package/package.json +22 -21
- package/dist/_dev.cjs +0 -2
- package/dist/_dev.cjs.map +0 -1
- package/dist/_dev.d.ts +0 -2
- package/dist/_dev.d.ts.map +0 -1
- package/dist/_dev.js +0 -9
- package/dist/_dev.js.map +0 -1
- package/dist/_error-utils.cjs +0 -2
- package/dist/_error-utils.cjs.map +0 -1
- package/dist/_error-utils.d.ts +0 -24
- package/dist/_error-utils.d.ts.map +0 -1
- package/dist/_error-utils.js +0 -20
- package/dist/_error-utils.js.map +0 -1
- package/dist/_virtual/_rolldown/runtime.js +0 -7
- package/dist/async-computed.cjs +0 -2
- package/dist/async-computed.cjs.map +0 -1
- package/dist/async-computed.d.ts +0 -36
- package/dist/async-computed.d.ts.map +0 -1
- package/dist/async-computed.js +0 -62
- package/dist/async-computed.js.map +0 -1
- package/dist/computed.cjs +0 -2
- package/dist/computed.cjs.map +0 -1
- package/dist/computed.d.ts +0 -26
- package/dist/computed.d.ts.map +0 -1
- package/dist/computed.js +0 -113
- package/dist/computed.js.map +0 -1
- package/dist/devtools-hook.cjs +0 -2
- package/dist/devtools-hook.cjs.map +0 -1
- package/dist/devtools-hook.d.ts +0 -4
- package/dist/devtools-hook.d.ts.map +0 -1
- package/dist/devtools-hook.js +0 -8
- package/dist/devtools-hook.js.map +0 -1
- package/dist/devtools.d.ts +0 -50
- package/dist/devtools.d.ts.map +0 -1
- package/dist/effect.cjs +0 -2
- package/dist/effect.cjs.map +0 -1
- package/dist/effect.d.ts +0 -104
- package/dist/effect.d.ts.map +0 -1
- package/dist/effect.js +0 -174
- package/dist/effect.js.map +0 -1
- package/dist/execution-context.cjs +0 -2
- package/dist/execution-context.cjs.map +0 -1
- package/dist/execution-context.d.ts +0 -49
- package/dist/execution-context.d.ts.map +0 -1
- package/dist/execution-context.js +0 -32
- package/dist/execution-context.js.map +0 -1
- package/dist/history.d.ts +0 -56
- package/dist/history.d.ts.map +0 -1
- package/dist/reactive-base.cjs +0 -2
- package/dist/reactive-base.cjs.map +0 -1
- package/dist/reactive-base.d.ts +0 -60
- package/dist/reactive-base.d.ts.map +0 -1
- package/dist/reactive-base.js +0 -56
- package/dist/reactive-base.js.map +0 -1
- package/dist/scheduling.cjs +0 -2
- package/dist/scheduling.cjs.map +0 -1
- package/dist/scheduling.d.ts +0 -5
- package/dist/scheduling.d.ts.map +0 -1
- package/dist/scheduling.js +0 -57
- package/dist/scheduling.js.map +0 -1
- package/dist/signal.cjs +0 -2
- package/dist/signal.cjs.map +0 -1
- package/dist/signal.d.ts +0 -24
- package/dist/signal.d.ts.map +0 -1
- package/dist/signal.js +0 -54
- package/dist/signal.js.map +0 -1
- package/dist/src/devtools.cjs +0 -2
- package/dist/src/devtools.cjs.map +0 -1
- package/dist/src/devtools.js +0 -36
- package/dist/src/devtools.js.map +0 -1
- package/dist/src/history.cjs +0 -2
- package/dist/src/history.cjs.map +0 -1
- package/dist/src/history.js +0 -60
- package/dist/src/history.js.map +0 -1
- package/dist/src/ssr/index.cjs +0 -2
- package/dist/src/ssr/index.cjs.map +0 -1
- package/dist/src/ssr/index.js +0 -38
- package/dist/src/ssr/index.js.map +0 -1
- package/dist/ssr/index.d.ts +0 -56
- package/dist/ssr/index.d.ts.map +0 -1
- package/dist/store.cjs.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/subscription.cjs +0 -2
- package/dist/subscription.cjs.map +0 -1
- package/dist/subscription.d.ts +0 -22
- package/dist/subscription.d.ts.map +0 -1
- package/dist/subscription.js +0 -47
- package/dist/subscription.js.map +0 -1
- package/dist/symbols.cjs +0 -2
- package/dist/symbols.cjs.map +0 -1
- package/dist/symbols.d.ts +0 -6
- package/dist/symbols.d.ts.map +0 -1
- package/dist/symbols.js +0 -6
- package/dist/symbols.js.map +0 -1
- package/dist/tracking.cjs +0 -2
- package/dist/tracking.cjs.map +0 -1
- package/dist/tracking.d.ts +0 -51
- package/dist/tracking.d.ts.map +0 -1
- package/dist/tracking.js +0 -28
- package/dist/tracking.js.map +0 -1
- package/dist/utilities.cjs +0 -2
- package/dist/utilities.cjs.map +0 -1
- package/dist/utilities.d.ts +0 -56
- package/dist/utilities.d.ts.map +0 -1
- package/dist/utilities.js +0 -25
- package/dist/utilities.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,324 +1,60 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type
|
|
3
|
-
export type
|
|
4
|
-
export type EqualityFn<T> = (a: T, b: T) => boolean;
|
|
5
|
-
/**
|
|
6
|
-
* Controls when an effect re-runs after a dependency changes.
|
|
7
|
-
* - `'sync'` (default): runs immediately in the same flush.
|
|
8
|
-
* - `'microtask'`: deferred to the next microtask.
|
|
9
|
-
*/
|
|
10
|
-
export type EffectScheduler = 'microtask' | 'sync';
|
|
11
|
-
/** Options accepted by `computed()`. */
|
|
12
|
-
export type ComputedOptions<T> = {
|
|
13
|
-
equals?: EqualityFn<T>;
|
|
14
|
-
name?: string;
|
|
15
|
-
};
|
|
16
|
-
/** Options accepted by `signal()`. */
|
|
1
|
+
export type Cleanup = () => void;
|
|
2
|
+
export type Equality<T> = (previous: T, next: T) => boolean;
|
|
3
|
+
export type Unsubscribe = () => void;
|
|
17
4
|
export type SignalOptions<T> = {
|
|
18
|
-
equals?:
|
|
19
|
-
name?: string;
|
|
20
|
-
};
|
|
21
|
-
export type EffectOptions = {
|
|
5
|
+
equals?: Equality<T>;
|
|
22
6
|
name?: string;
|
|
23
|
-
scheduler?: EffectScheduler;
|
|
24
7
|
};
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
name?: string;
|
|
28
|
-
onError?: (error: unknown) => void;
|
|
29
|
-
};
|
|
30
|
-
export interface Subscription {
|
|
31
|
-
dispose(): void;
|
|
32
|
-
/** `true` after `dispose()` has been called. */
|
|
33
|
-
readonly disposed: boolean;
|
|
34
|
-
[Symbol.dispose](): void;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A snapshot of one reactive dependency recorded by an effect.
|
|
38
|
-
* Returned by `EffectHandle.getDependencies()`.
|
|
39
|
-
*/
|
|
40
|
-
export type DepInfo = {
|
|
41
|
-
readonly kind: 'computed' | 'signal';
|
|
42
|
-
readonly name?: string;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Extended handle returned by `effect()`.
|
|
46
|
-
* Extends `Subscription` with `getDependencies()` for reactive graph introspection.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const handle = effect(() => { console.log(count.value); });
|
|
51
|
-
* console.log(handle.getDependencies()); // [{ name: 'count' }]
|
|
52
|
-
* handle.dispose();
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export interface EffectHandle extends Subscription {
|
|
56
|
-
/**
|
|
57
|
-
* Returns the reactive sources the effect is currently subscribed to.
|
|
58
|
-
* Reflects the deps collected during the last completed run.
|
|
59
|
-
* Returns an empty array after `dispose()`.
|
|
60
|
-
*/
|
|
61
|
-
getDependencies(): ReadonlyArray<DepInfo>;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Extended async subscription returned by `effectAsync()`.
|
|
65
|
-
* Adds `run()` for structured concurrency — await the current async run before proceeding.
|
|
66
|
-
*
|
|
67
|
-
* Sanctioned hybrid disposal shape (see `.ai/core/conventions.md`'s Teardown section):
|
|
68
|
-
* `[Symbol.dispose]` (inherited from `Subscription`) aborts immediately and does
|
|
69
|
-
* **not** wait for in-flight async work to settle; `[Symbol.asyncDispose]` aborts
|
|
70
|
-
* **and** awaits full teardown. Pick `using` for a fire-and-forget stop, `await using`
|
|
71
|
-
* when you need to know the last run has actually finished before continuing.
|
|
72
|
-
*/
|
|
73
|
-
export interface AsyncSubscription extends Subscription {
|
|
74
|
-
/** Awaits the current async run without disposing the effect. Resolves immediately if idle. */
|
|
75
|
-
run(): Promise<void>;
|
|
76
|
-
/** ES2024 `await using` compatible async disposal. Stops the effect and awaits full teardown. */
|
|
77
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
78
|
-
}
|
|
79
|
-
export type WatchOptions<T> = {
|
|
80
|
-
equals?: EqualityFn<T>;
|
|
81
|
-
immediate?: boolean;
|
|
8
|
+
export type ComputedOptions<T> = {
|
|
9
|
+
equals?: Equality<T>;
|
|
82
10
|
name?: string;
|
|
83
|
-
/** Auto-dispose the watch after the first callback invocation. */
|
|
84
|
-
once?: boolean;
|
|
85
11
|
};
|
|
86
|
-
export type
|
|
87
|
-
/** Value exposed via `data` while the first run is loading. */
|
|
88
|
-
initialValue?: T;
|
|
89
|
-
/** Debug name for the internal effect and state signal. */
|
|
12
|
+
export type EffectOptions = {
|
|
90
13
|
name?: string;
|
|
14
|
+
scheduler?: 'microtask' | 'sync';
|
|
91
15
|
};
|
|
92
|
-
/**
|
|
93
|
-
* Discriminated-union state emitted by a `resource()` signal.
|
|
94
|
-
*
|
|
95
|
-
* - `'loading'` — async factory is in-flight. `data` carries the last fulfilled value (if any).
|
|
96
|
-
* - `'ready'` — factory resolved. `data` is the fulfilled value.
|
|
97
|
-
* - `'error'` — factory rejected. `error` holds the thrown value. `data` carries the last fulfilled value (if any).
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* const user = resource(async () => fetchUser(id.value));
|
|
102
|
-
*
|
|
103
|
-
* effect(() => {
|
|
104
|
-
* const s = user.value;
|
|
105
|
-
* if (s.status === 'loading') return showSpinner();
|
|
106
|
-
* if (s.status === 'error') return showError(s.error);
|
|
107
|
-
* renderUser(s.data);
|
|
108
|
-
* });
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
export type ResourceState<T> = {
|
|
112
|
-
readonly data?: T;
|
|
113
|
-
readonly status: 'loading';
|
|
114
|
-
} | {
|
|
115
|
-
readonly data: T;
|
|
116
|
-
readonly status: 'ready';
|
|
117
|
-
} | {
|
|
118
|
-
readonly data?: T;
|
|
119
|
-
readonly error: unknown;
|
|
120
|
-
readonly status: 'error';
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Disposable handle returned by `resource()`. Extends `Computed<ResourceState<T>>`
|
|
124
|
-
* with `refresh()` for manually forcing a re-fetch.
|
|
125
|
-
*/
|
|
126
|
-
export interface Resource<T> extends Computed<ResourceState<T>> {
|
|
127
|
-
/**
|
|
128
|
-
* Forces the factory to re-run immediately, aborting any in-flight run —
|
|
129
|
-
* even if no tracked dependency changed. No-op after `dispose()`.
|
|
130
|
-
*/
|
|
131
|
-
refresh(): void;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* A single snapshot entry in `StoreWithHistory`.
|
|
135
|
-
* Carries the frozen state and an optional label for annotated checkpoints.
|
|
136
|
-
*/
|
|
137
|
-
export type HistoryEntry<T> = {
|
|
138
|
-
readonly label?: string;
|
|
139
|
-
readonly state: Readonly<T>;
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* The minimal read-only contract for consuming any reactive value.
|
|
143
|
-
* Effects and computed functions read `.value` (tracked) or `peek()` (untracked).
|
|
144
|
-
* Use `subscribe()` for external imperative listeners.
|
|
145
|
-
*/
|
|
146
16
|
export interface Readable<T> {
|
|
147
|
-
/** `true` after the underlying node has been disposed. */
|
|
148
|
-
readonly disposed: boolean;
|
|
149
|
-
/** The debug name assigned at creation time, or `undefined` if unnamed. */
|
|
150
17
|
readonly name?: string;
|
|
151
18
|
peek(): T;
|
|
152
|
-
|
|
153
|
-
* Subscribes a listener to value change notifications.
|
|
154
|
-
* Implementations MUST NOT invoke `listener` synchronously during registration.
|
|
155
|
-
*/
|
|
156
|
-
subscribe(listener: () => void): Subscription;
|
|
19
|
+
subscribe(listener: () => void): Unsubscribe;
|
|
157
20
|
readonly value: T;
|
|
158
21
|
}
|
|
159
|
-
|
|
160
|
-
* A disposable derived value. The holder is responsible for calling `dispose()`.
|
|
161
|
-
* Returned by `computed()`, `readonly()`, and `resource()`.
|
|
162
|
-
*/
|
|
163
|
-
export interface Computed<T> extends Readable<T> {
|
|
164
|
-
dispose(): void;
|
|
165
|
-
[Symbol.dispose](): void;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* A writable owned signal. The holder can both read and write `.value`,
|
|
169
|
-
* and is responsible for calling `dispose()` when done.
|
|
170
|
-
*/
|
|
171
|
-
export interface Signal<T> extends Computed<T> {
|
|
22
|
+
export interface Signal<T> extends Readable<T> {
|
|
172
23
|
value: T;
|
|
173
24
|
}
|
|
174
|
-
|
|
175
|
-
* Extracts the value type at a dot-separated path `P` within object type `T`.
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* type City = PathValue<{ user: { address: { city: string } } }, 'user.address.city'>
|
|
179
|
-
* // → string
|
|
180
|
-
*/
|
|
181
|
-
export type PathValue<T, P extends string> = P extends keyof T ? T[P] : P extends `${infer K}.${infer Rest}` ? K extends keyof T ? PathValue<T[K], Rest> : never : never;
|
|
182
|
-
/**
|
|
183
|
-
* A fine-grained reactive store for objects.
|
|
184
|
-
* Extends `Computed<Readonly<T>>` — `store.value` provides a tracked whole-store read.
|
|
185
|
-
*
|
|
186
|
-
* `lens()` is the primary reactive read/write API — it returns a `Signal` for
|
|
187
|
-
* a specific property or nested path and registers fine-grained dependencies.
|
|
188
|
-
* `peek()` returns a non-reactive snapshot (useful for serialization).
|
|
189
|
-
* `subscribe()` fires on any mutation (useful for adapters like `storeWithHistory`).
|
|
190
|
-
*/
|
|
191
|
-
export interface Store<T extends object> extends Computed<Readonly<T>> {
|
|
192
|
-
/**
|
|
193
|
-
* Returns a writable `Signal` scoped to a single property or nested path.
|
|
194
|
-
* Reads register a fine-grained dependency on that property's signal —
|
|
195
|
-
* unrelated patches do NOT re-run effects watching this lens.
|
|
196
|
-
* Lenses are cached — `store.lens('x') === store.lens('x')`.
|
|
197
|
-
*/
|
|
198
|
-
lens<P extends string>(path: P): Signal<PathValue<T, P>>;
|
|
199
|
-
/** Atomic partial update — only changed keys notify their subscribers. */
|
|
200
|
-
patch(partial: Partial<T>): void;
|
|
201
|
-
/**
|
|
202
|
-
* Returns a non-reactive snapshot of the current state.
|
|
203
|
-
* Use for serialization or one-off reads outside reactive contexts.
|
|
204
|
-
*/
|
|
205
|
-
peek(): Readonly<T>;
|
|
206
|
-
/**
|
|
207
|
-
* Replaces the entire store state by passing the current state to `fn` and
|
|
208
|
-
* applying the returned value. Only changed properties trigger downstream effects.
|
|
209
|
-
*/
|
|
210
|
-
replace(fn: (state: Readonly<T>) => T): void;
|
|
211
|
-
/** Resets the store to its initial state. */
|
|
212
|
-
reset(): void;
|
|
213
|
-
/**
|
|
214
|
-
* Subscribes to any store mutation (patch / replace / reset / lens write).
|
|
215
|
-
* Used by external adapters — prefer `store.lens()` for reactive reads.
|
|
216
|
-
*/
|
|
217
|
-
subscribe(listener: () => void): Subscription;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* A lifecycle scope that collects cleanup functions and runs them on dispose.
|
|
221
|
-
* Effects and computeds created inside `scope.run()` auto-register their disposal.
|
|
222
|
-
*/
|
|
223
|
-
export interface Scope {
|
|
224
|
-
/**
|
|
225
|
-
* Registers `fn` to run when this scope is disposed.
|
|
226
|
-
* Throws `RippleDisposedScopeError` if called on an already-disposed scope.
|
|
227
|
-
* Use this from within an effect body to explicitly direct a cleanup into the scope
|
|
228
|
-
* rather than the effect's own cleanup queue.
|
|
229
|
-
*/
|
|
230
|
-
add(fn: CleanupFn): void;
|
|
231
|
-
/** `AbortSignal` that is aborted when `dispose()` is called. Use to tie external lifetimes to this scope. */
|
|
232
|
-
readonly disposalSignal: AbortSignal;
|
|
25
|
+
export interface Disposable {
|
|
233
26
|
dispose(): void;
|
|
234
|
-
/** `true` after `dispose()` has been called. */
|
|
235
27
|
readonly disposed: boolean;
|
|
236
|
-
|
|
237
|
-
* Runs `fn` inside this scope's cleanup context.
|
|
238
|
-
* `onCleanup()` calls and resource auto-disposals inside `fn` are registered
|
|
239
|
-
* to this scope when there is no enclosing effect or computed context.
|
|
240
|
-
* Reactive reads inside `fn` are tracked normally against any enclosing effect.
|
|
241
|
-
* Throws `RippleDisposedScopeError` if the scope has already been disposed.
|
|
242
|
-
*/
|
|
243
|
-
run<T>(fn: () => T): T;
|
|
28
|
+
readonly disposalSignal: AbortSignal;
|
|
244
29
|
[Symbol.dispose](): void;
|
|
245
30
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
* Extends `Store<T>` directly — all store mutations (`patch`, `replace`, `reset`, `lens`)
|
|
250
|
-
* work on the history adapter without `.store` indirection.
|
|
251
|
-
*
|
|
252
|
-
* History is **explicit** — call `push()` or `pushNamed()` after any mutation you want undoable.
|
|
253
|
-
*
|
|
254
|
-
* @example
|
|
255
|
-
* ```ts
|
|
256
|
-
* import { storeWithHistory } from '@vielzeug/ripple/history';
|
|
257
|
-
*
|
|
258
|
-
* const h = storeWithHistory({ count: 0 });
|
|
259
|
-
*
|
|
260
|
-
* h.patch({ count: 1 });
|
|
261
|
-
* h.push(); // save a checkpoint
|
|
262
|
-
* h.undo(); // restore to { count: 0 }
|
|
263
|
-
* h.redo(); // restore to { count: 1 }
|
|
264
|
-
* ```
|
|
265
|
-
*/
|
|
266
|
-
export interface StoreWithHistory<T extends object> extends Store<T> {
|
|
267
|
-
/** `true` when there is at least one snapshot ahead to redo. Reactive — reads inside effects re-run on change. */
|
|
268
|
-
readonly canRedo: boolean;
|
|
269
|
-
/** `true` when there is at least one snapshot to undo to. Reactive — reads inside effects re-run on change. */
|
|
270
|
-
readonly canUndo: boolean;
|
|
271
|
-
/** Returns the history entry at the given index (0 = oldest). */
|
|
272
|
-
historyAt(index: number): HistoryEntry<T> | undefined;
|
|
273
|
-
/** Number of snapshots currently in history. */
|
|
274
|
-
readonly historyLength: number;
|
|
275
|
-
/** Saves the current store state as an explicit undo checkpoint. */
|
|
276
|
-
push(): void;
|
|
277
|
-
/**
|
|
278
|
-
* Saves the current store state as an annotated checkpoint.
|
|
279
|
-
* Use to mark significant transitions (e.g. `'import'`, `'reset'`) so time-travel
|
|
280
|
-
* debuggers can distinguish user-initiated from programmatic mutations.
|
|
281
|
-
*/
|
|
282
|
-
pushNamed(label: string): void;
|
|
283
|
-
/** Move forward one snapshot. No-op when at the most recent checkpoint. */
|
|
284
|
-
redo(): void;
|
|
285
|
-
/** The underlying store — kept as an escape hatch for adapters that need direct store access. */
|
|
286
|
-
readonly store: Store<T>;
|
|
287
|
-
/** Move back one snapshot. No-op when at the oldest checkpoint. */
|
|
288
|
-
undo(): void;
|
|
31
|
+
export type EffectHandle = Disposable;
|
|
32
|
+
export interface Scope extends Disposable {
|
|
33
|
+
run<T>(fn: () => T): T;
|
|
289
34
|
}
|
|
290
|
-
export type
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
35
|
+
export type ReactiveEvent = {
|
|
36
|
+
readonly kind: 'compute';
|
|
37
|
+
readonly name?: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'effect';
|
|
40
|
+
readonly name?: string;
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'write';
|
|
43
|
+
readonly name?: string;
|
|
44
|
+
readonly next: unknown;
|
|
45
|
+
readonly previous: unknown;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: 'dispose';
|
|
48
|
+
readonly name?: string;
|
|
49
|
+
readonly node: 'effect' | 'scope';
|
|
305
50
|
};
|
|
306
|
-
|
|
307
|
-
export type
|
|
308
|
-
kind: '
|
|
309
|
-
name
|
|
310
|
-
path?: string;
|
|
51
|
+
export type ReactiveObserver = (event: ReactiveEvent) => void;
|
|
52
|
+
export type ReactiveErrorContext = {
|
|
53
|
+
readonly kind: 'cleanup' | 'effect' | 'listener' | 'observer';
|
|
54
|
+
readonly name?: string;
|
|
311
55
|
};
|
|
312
|
-
export type
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
/** Called when a signal, computed, or effect is disposed. */
|
|
316
|
-
dispose?(event: DisposeEvent): void;
|
|
317
|
-
/** Called when a store-level mutation (patch/replace/reset/lens) occurs. */
|
|
318
|
-
mutate?(event: MutateEvent): void;
|
|
319
|
-
/** Called when an effect starts running. */
|
|
320
|
-
run?(event: NamedEvent): void;
|
|
321
|
-
/** Called when a signal's value changes. */
|
|
322
|
-
write?(event: WriteEvent): void;
|
|
56
|
+
export type RippleOptions = {
|
|
57
|
+
observer?: ReactiveObserver;
|
|
58
|
+
onError?: (error: unknown, context: ReactiveErrorContext) => void;
|
|
323
59
|
};
|
|
324
60
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;AACjC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;AAC5D,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC/B,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;CAClC,CAAC;AAEF,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,IAAI,CAAC,CAAC;IACV,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW,CAAC;IAC7C,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAC5C,KAAK,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC;IACrC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;CAC1B;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC;AAEtC,MAAM,WAAW,KAAM,SAAQ,UAAU;IACvC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;CACxB;AAED,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACtG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAA;CAAE,CAAC;AAE5F,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAE9D,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;IAC9D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACnE,CAAC"}
|
package/dist/watch.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./index.cjs");exports.watch=e.watch;
|
package/dist/watch.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/watch.js
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/ripple",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
8
|
-
"description": "Fine-grained reactive
|
|
8
|
+
"description": "Fine-grained reactive runtime — signals, derived values, effects, scopes, and optional state tools",
|
|
9
9
|
"main": "./dist/index.cjs",
|
|
10
10
|
"module": "./dist/index.js",
|
|
11
11
|
"types": "dist/index.d.ts",
|
|
@@ -16,23 +16,23 @@
|
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"require": "./dist/index.cjs"
|
|
18
18
|
},
|
|
19
|
-
"./
|
|
20
|
-
"source": "./src/
|
|
21
|
-
"types": "./dist/
|
|
22
|
-
"import": "./dist/
|
|
23
|
-
"require": "./dist/
|
|
19
|
+
"./async": {
|
|
20
|
+
"source": "./src/async.ts",
|
|
21
|
+
"types": "./dist/async.d.ts",
|
|
22
|
+
"import": "./dist/async.js",
|
|
23
|
+
"require": "./dist/async.cjs"
|
|
24
24
|
},
|
|
25
|
-
"./
|
|
26
|
-
"source": "./src/
|
|
27
|
-
"types": "./dist/
|
|
28
|
-
"import": "./dist/
|
|
29
|
-
"require": "./dist/
|
|
25
|
+
"./store": {
|
|
26
|
+
"source": "./src/store.ts",
|
|
27
|
+
"types": "./dist/store.d.ts",
|
|
28
|
+
"import": "./dist/store.js",
|
|
29
|
+
"require": "./dist/store.cjs"
|
|
30
30
|
},
|
|
31
|
-
"./
|
|
32
|
-
"source": "./src/
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/
|
|
35
|
-
"require": "./dist/
|
|
31
|
+
"./watch": {
|
|
32
|
+
"source": "./src/watch.ts",
|
|
33
|
+
"types": "./dist/watch.d.ts",
|
|
34
|
+
"import": "./dist/watch.js",
|
|
35
|
+
"require": "./dist/watch.cjs"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
@@ -40,10 +40,11 @@
|
|
|
40
40
|
"build:types": "tsc -p tsconfig.declarations.json",
|
|
41
41
|
"fix": "eslint --fix src",
|
|
42
42
|
"lint": "eslint src",
|
|
43
|
-
"prepublishOnly": "pnpm run build",
|
|
43
|
+
"prepublishOnly": "pnpm run build && pnpm run verify:exports",
|
|
44
44
|
"preview": "vite preview",
|
|
45
45
|
"test": "vitest",
|
|
46
|
-
"build:bundle": "vite build --config vite.bundle.config.ts"
|
|
46
|
+
"build:bundle": "vite build --config vite.bundle.config.ts",
|
|
47
|
+
"verify:exports": "node ./scripts/verify-exports.mjs"
|
|
47
48
|
},
|
|
48
49
|
"publishConfig": {
|
|
49
50
|
"access": "public",
|
|
@@ -53,9 +54,9 @@
|
|
|
53
54
|
"node": ">=22"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^26.1.
|
|
57
|
+
"@types/node": "^26.1.2",
|
|
57
58
|
"typescript": "^6.0.3",
|
|
58
|
-
"vite": "^8.
|
|
59
|
+
"vite": "^8.2.0",
|
|
59
60
|
"vitest": "^4.1.10"
|
|
60
61
|
}
|
|
61
62
|
}
|
package/dist/_dev.cjs
DELETED
package/dist/_dev.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __RIPPLE_PROD__?: boolean }).__RIPPLE_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ripple] ${msg}`);\n}\n"],"mappings":"AAAA,IAAM,EAAQ,CAAE,WAA6C,gBAG7D,SAAgB,EAAK,EAAmB,CAClC,GAAO,QAAQ,KAAK,sBAAsB,GAAK,CACrD"}
|
package/dist/_dev.d.ts
DELETED
package/dist/_dev.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.d.ts","sourceRoot":"","sources":["../src/_dev.ts"],"names":[],"mappings":""}
|
package/dist/_dev.js
DELETED
package/dist/_dev.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __RIPPLE_PROD__?: boolean }).__RIPPLE_PROD__;\n\n/** @internal @security Messages may include user-supplied data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/ripple] ${msg}`);\n}\n"],"mappings":";AAAA,IAAM,IAAQ,CAAE,WAA6C;AAG7D,SAAgB,EAAK,GAAmB;CACtC,AAAI,KAAO,QAAQ,KAAK,sBAAsB,GAAK;AACrD"}
|
package/dist/_error-utils.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var e=e=>e instanceof Error?e:Error(`Non-Error thrown: ${String(e)}`),t=t=>{let n=[];for(let r of t)try{r()}catch(t){n.push(e(t))}return n},n=(e,n)=>{let r=t(e);if(r.length===1)throw r[0];if(r.length>0)throw AggregateError(r,n)},r=(t,n,r)=>{throw n.length===0?t:AggregateError([e(t),...n],r,{cause:e(t)})};exports.collectErrors=t,exports.ensureError=e,exports.rethrowWith=r,exports.runAll=n;
|
|
2
|
-
//# sourceMappingURL=_error-utils.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_error-utils.cjs","names":[],"sources":["../src/_error-utils.ts"],"sourcesContent":["import type { CleanupFn } from './types';\n\n/**\n * Coerces any thrown value to an `Error`.\n * Non-Error throws (strings, numbers, etc.) are wrapped in a plain `Error`\n * with a descriptive message — they are NOT mis-branded as `RippleError`.\n */\nexport const ensureError = (error: unknown): Error =>\n error instanceof Error ? error : new Error(`Non-Error thrown: ${String(error)}`);\n\n/**\n * Runs each fn in `fns`, collecting any thrown errors. Does NOT re-throw.\n */\nexport const collectErrors = (fns: Iterable<CleanupFn>): Error[] => {\n const errors: Error[] = [];\n\n for (const fn of fns) {\n try {\n fn();\n } catch (e) {\n errors.push(ensureError(e));\n }\n }\n\n return errors;\n};\n\n/**\n * Runs all `fns`, collecting errors.\n * - Single error: re-throws the original error directly (preserves type + stack).\n * - Multiple errors: wraps in AggregateError with the given context label.\n */\nexport const runAll = (fns: Iterable<CleanupFn>, context: string): void => {\n const errors = collectErrors(fns);\n\n if (errors.length === 1) throw errors[0]!;\n\n if (errors.length > 0) {\n throw new AggregateError(errors, context);\n }\n};\n\n/**\n * Re-throws `primary`, augmented with any extra errors as an AggregateError.\n * If `extras` is empty, throws `primary` directly (preserves original type + stack).\n * Otherwise, `primary` is set as the `.cause` so callers can identify the root failure.\n */\nexport const rethrowWith = (primary: unknown, extras: Error[], context: string): never => {\n if (extras.length === 0) throw primary;\n\n throw new AggregateError([ensureError(primary), ...extras], context, {\n cause: ensureError(primary),\n });\n};\n"],"mappings":"AAOA,IAAa,EAAe,GAC1B,aAAiB,MAAQ,EAAY,MAAM,qBAAqB,OAAO,CAAK,GAAG,EAKpE,EAAiB,GAAsC,CAClE,IAAM,EAAkB,CAAC,EAEzB,IAAK,IAAM,KAAM,EACf,GAAI,CACF,EAAG,CACL,OAAS,EAAG,CACV,EAAO,KAAK,EAAY,CAAC,CAAC,CAC5B,CAGF,OAAO,CACT,EAOa,GAAU,EAA0B,IAA0B,CACzE,IAAM,EAAS,EAAc,CAAG,EAEhC,GAAI,EAAO,SAAW,EAAG,MAAM,EAAO,GAEtC,GAAI,EAAO,OAAS,EAClB,MAAU,eAAe,EAAQ,CAAO,CAE5C,EAOa,GAAe,EAAkB,EAAiB,IAA2B,CAGxF,MAFI,EAAO,SAAW,EAAS,EAErB,eAAe,CAAC,EAAY,CAAO,EAAG,GAAG,CAAM,EAAG,EAAS,CACnE,MAAO,EAAY,CAAO,CAC5B,CAAC,CACH"}
|
package/dist/_error-utils.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { CleanupFn } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Coerces any thrown value to an `Error`.
|
|
4
|
-
* Non-Error throws (strings, numbers, etc.) are wrapped in a plain `Error`
|
|
5
|
-
* with a descriptive message — they are NOT mis-branded as `RippleError`.
|
|
6
|
-
*/
|
|
7
|
-
export declare const ensureError: (error: unknown) => Error;
|
|
8
|
-
/**
|
|
9
|
-
* Runs each fn in `fns`, collecting any thrown errors. Does NOT re-throw.
|
|
10
|
-
*/
|
|
11
|
-
export declare const collectErrors: (fns: Iterable<CleanupFn>) => Error[];
|
|
12
|
-
/**
|
|
13
|
-
* Runs all `fns`, collecting errors.
|
|
14
|
-
* - Single error: re-throws the original error directly (preserves type + stack).
|
|
15
|
-
* - Multiple errors: wraps in AggregateError with the given context label.
|
|
16
|
-
*/
|
|
17
|
-
export declare const runAll: (fns: Iterable<CleanupFn>, context: string) => void;
|
|
18
|
-
/**
|
|
19
|
-
* Re-throws `primary`, augmented with any extra errors as an AggregateError.
|
|
20
|
-
* If `extras` is empty, throws `primary` directly (preserves original type + stack).
|
|
21
|
-
* Otherwise, `primary` is set as the `.cause` so callers can identify the root failure.
|
|
22
|
-
*/
|
|
23
|
-
export declare const rethrowWith: (primary: unknown, extras: Error[], context: string) => never;
|
|
24
|
-
//# sourceMappingURL=_error-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_error-utils.d.ts","sourceRoot":"","sources":["../src/_error-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KACqC,CAAC;AAEnF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,QAAQ,CAAC,SAAS,CAAC,KAAG,KAAK,EAY7D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,KAAG,IAQlE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,SAAS,OAAO,EAAE,QAAQ,KAAK,EAAE,EAAE,SAAS,MAAM,KAAG,KAMhF,CAAC"}
|
package/dist/_error-utils.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/_error-utils.ts
|
|
2
|
-
var e = (e) => e instanceof Error ? e : /* @__PURE__ */ Error(`Non-Error thrown: ${String(e)}`), t = (t) => {
|
|
3
|
-
let n = [];
|
|
4
|
-
for (let r of t) try {
|
|
5
|
-
r();
|
|
6
|
-
} catch (t) {
|
|
7
|
-
n.push(e(t));
|
|
8
|
-
}
|
|
9
|
-
return n;
|
|
10
|
-
}, n = (e, n) => {
|
|
11
|
-
let r = t(e);
|
|
12
|
-
if (r.length === 1) throw r[0];
|
|
13
|
-
if (r.length > 0) throw AggregateError(r, n);
|
|
14
|
-
}, r = (t, n, r) => {
|
|
15
|
-
throw n.length === 0 ? t : AggregateError([e(t), ...n], r, { cause: e(t) });
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
18
|
-
export { t as collectErrors, e as ensureError, r as rethrowWith, n as runAll };
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=_error-utils.js.map
|
package/dist/_error-utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_error-utils.js","names":[],"sources":["../src/_error-utils.ts"],"sourcesContent":["import type { CleanupFn } from './types';\n\n/**\n * Coerces any thrown value to an `Error`.\n * Non-Error throws (strings, numbers, etc.) are wrapped in a plain `Error`\n * with a descriptive message — they are NOT mis-branded as `RippleError`.\n */\nexport const ensureError = (error: unknown): Error =>\n error instanceof Error ? error : new Error(`Non-Error thrown: ${String(error)}`);\n\n/**\n * Runs each fn in `fns`, collecting any thrown errors. Does NOT re-throw.\n */\nexport const collectErrors = (fns: Iterable<CleanupFn>): Error[] => {\n const errors: Error[] = [];\n\n for (const fn of fns) {\n try {\n fn();\n } catch (e) {\n errors.push(ensureError(e));\n }\n }\n\n return errors;\n};\n\n/**\n * Runs all `fns`, collecting errors.\n * - Single error: re-throws the original error directly (preserves type + stack).\n * - Multiple errors: wraps in AggregateError with the given context label.\n */\nexport const runAll = (fns: Iterable<CleanupFn>, context: string): void => {\n const errors = collectErrors(fns);\n\n if (errors.length === 1) throw errors[0]!;\n\n if (errors.length > 0) {\n throw new AggregateError(errors, context);\n }\n};\n\n/**\n * Re-throws `primary`, augmented with any extra errors as an AggregateError.\n * If `extras` is empty, throws `primary` directly (preserves original type + stack).\n * Otherwise, `primary` is set as the `.cause` so callers can identify the root failure.\n */\nexport const rethrowWith = (primary: unknown, extras: Error[], context: string): never => {\n if (extras.length === 0) throw primary;\n\n throw new AggregateError([ensureError(primary), ...extras], context, {\n cause: ensureError(primary),\n });\n};\n"],"mappings":";AAOA,IAAa,KAAe,MAC1B,aAAiB,QAAQ,IAAQ,gBAAI,MAAM,qBAAqB,OAAO,CAAK,GAAG,GAKpE,KAAiB,MAAsC;CAClE,IAAM,IAAkB,CAAC;CAEzB,KAAK,IAAM,KAAM,GACf,IAAI;EACF,EAAG;CACL,SAAS,GAAG;EACV,EAAO,KAAK,EAAY,CAAC,CAAC;CAC5B;CAGF,OAAO;AACT,GAOa,KAAU,GAA0B,MAA0B;CACzE,IAAM,IAAS,EAAc,CAAG;CAEhC,IAAI,EAAO,WAAW,GAAG,MAAM,EAAO;CAEtC,IAAI,EAAO,SAAS,GAClB,MAAU,eAAe,GAAQ,CAAO;AAE5C,GAOa,KAAe,GAAkB,GAAiB,MAA2B;CAGxF,MAFI,EAAO,WAAW,IAAS,IAErB,eAAe,CAAC,EAAY,CAAO,GAAG,GAAG,CAAM,GAAG,GAAS,EACnE,OAAO,EAAY,CAAO,EAC5B,CAAC;AACH"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var e = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
|
|
3
|
-
if (typeof require < "u") return require.apply(this, arguments);
|
|
4
|
-
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
-
});
|
|
6
|
-
//#endregion
|
|
7
|
-
export { e as __require };
|
package/dist/async-computed.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./devtools-hook.cjs"),t=require("./symbols.cjs"),n=require("./tracking.cjs"),r=require("./effect.cjs"),i=require("./signal.cjs");var a=(a,o)=>{let s=o?.name,c=i.signal({data:o?.initialValue,status:`loading`},s?{name:s}:void 0),l=i.signal(0),u=null,d=!1,f=r.effect(()=>{l.value,e.getDevToolsHook()?.compute?.({name:s}),u?.abort(),u=new AbortController;let{signal:t}=u,n=c.peek(),r=`data`in n?n.data:void 0;c.value={data:r,status:`loading`},(async()=>{try{let e=await a(t);!t.aborted&&!d&&(c.value={data:e,status:`ready`})}catch(e){!t.aborted&&!d&&(c.value={data:r,error:e,status:`error`})}})()},{name:s,[t.SUPPRESS_RUN_EVENT]:!0}),p=()=>{d||(l.value=l.peek()+1)},m=()=>{d||(d=!0,u?.abort(),f.dispose(),c.dispose(),l.dispose())};return n.autoRegisterDisposal(m),{dispose:m,get disposed(){return d},[t.IS_COMPUTED]:!0,[t.IS_SIGNAL]:!0,get name(){return c.name},peek:()=>c.peek(),refresh:p,subscribe:e=>c.subscribe(e),[Symbol.dispose]:m,get value(){return c.value}}};exports.resource=a;
|
|
2
|
-
//# sourceMappingURL=async-computed.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-computed.cjs","names":[],"sources":["../src/async-computed.ts"],"sourcesContent":["import type { Resource, ResourceOptions, ResourceState } from './types';\n\nimport { getDevToolsHook } from './devtools-hook';\nimport { effect } from './effect';\nimport { signal } from './signal';\nimport { IS_COMPUTED, IS_SIGNAL, SUPPRESS_RUN_EVENT } from './symbols';\nimport { autoRegisterDisposal } from './tracking';\n\n/**\n * Creates a reactive async resource that emits a `ResourceState<T>` discriminated union.\n *\n * Dependencies are tracked synchronously in the factory (before the first `await`).\n * The factory receives an `AbortSignal` that fires when dependencies change or\n * the resource is disposed, cancelling any in-flight work.\n *\n * If `resource()` is created inside an active `effect()` or `scope.run()` context,\n * it is automatically registered for cleanup and disposed with that context —\n * matching `computed()`'s auto-disposal behavior.\n *\n * Call `refresh()` to force the factory to re-run immediately, even if no tracked\n * dependency changed — useful for manual \"retry\"/\"refetch\" actions.\n *\n * @example\n * ```ts\n * const userId = signal('u1');\n * const user = resource(async (signal) => {\n * const id = userId.value; // tracked dep — re-runs when userId changes\n * return fetchUser(id, { signal });\n * });\n *\n * effect(() => {\n * const s = user.value;\n * if (s.status === 'loading') return showSpinner();\n * if (s.status === 'error') return showError(s.error);\n * renderUser(s.data);\n * });\n *\n * user.refresh(); // force a re-fetch without changing userId\n * user.dispose();\n * ```\n */\nexport const resource = <T>(\n factory: (abortSignal: AbortSignal) => Promise<T>,\n options?: ResourceOptions<T>,\n): Resource<T> => {\n const name = options?.name;\n const state = signal<ResourceState<T>>(\n { data: options?.initialValue, status: 'loading' },\n name ? { name } : undefined,\n );\n // Internal-only trigger — never exposed. Read (but never written to a meaningful\n // value) inside the effect purely so it becomes a tracked dep; refresh() bumps it\n // to force a re-run without requiring a real dependency to change.\n const epoch = signal(0);\n\n let controller: AbortController | null = null;\n let disposed = false;\n\n // Built unannotated and passed by reference (not as an inline literal) so TypeScript\n // checks it structurally against EffectOptions instead of excess-property-checking\n // the SUPPRESS_RUN_EVENT symbol key that isn't part of the public type.\n const internalEffectOptions = { name, [SUPPRESS_RUN_EVENT]: true };\n const stop = effect(() => {\n void epoch.value;\n\n // A resource is a derived value like computed() — emit the same 'compute' event\n // computed.ts fires before recomputing, so DevTools sees a resource re-run as a\n // derived-value recompute. SUPPRESS_RUN_EVENT below stops the internal effect from\n // also firing its own 'run' for the same re-run — one signal per re-run, not two.\n getDevToolsHook()?.compute?.({ name });\n\n controller?.abort();\n controller = new AbortController();\n\n const { signal: abortSignal } = controller;\n\n const current = state.peek();\n const prevData = 'data' in current ? current.data : undefined;\n\n state.value = { data: prevData, status: 'loading' };\n\n void (async () => {\n try {\n const result = await factory(abortSignal);\n\n if (!abortSignal.aborted && !disposed) {\n state.value = { data: result, status: 'ready' };\n }\n } catch (err) {\n if (!abortSignal.aborted && !disposed) {\n state.value = { data: prevData, error: err, status: 'error' };\n }\n }\n })();\n }, internalEffectOptions);\n\n const refresh = (): void => {\n if (disposed) return;\n\n epoch.value = epoch.peek() + 1;\n };\n\n const dispose = (): void => {\n if (disposed) return;\n\n disposed = true;\n controller?.abort();\n stop.dispose();\n state.dispose();\n epoch.dispose();\n };\n\n autoRegisterDisposal(dispose);\n\n // Built unannotated (the brand symbols aren't part of Resource<T>, and annotating the\n // literal directly would trip excess-property checking on it) then assigned to a\n // Resource<T>-typed binding — a structural check, not a cast, so a future member added\n // to Computed<T>/Resource<T> fails this assignment at compile time instead of silently\n // going missing.\n const impl = {\n dispose,\n get disposed() {\n return disposed;\n },\n [IS_COMPUTED]: true as const,\n [IS_SIGNAL]: true as const,\n get name() {\n return state.name;\n },\n peek: () => state.peek(),\n refresh,\n subscribe: (listener: () => void) => state.subscribe(listener),\n [Symbol.dispose]: dispose,\n get value() {\n return state.value;\n },\n };\n const handle: Resource<T> = impl;\n\n return handle;\n};\n"],"mappings":"kJAyCA,IAAa,GACX,EACA,IACgB,CAChB,IAAM,EAAO,GAAS,KAChB,EAAQ,EAAA,OACZ,CAAE,KAAM,GAAS,aAAc,OAAQ,SAAU,EACjD,EAAO,CAAE,MAAK,EAAI,IAAA,EACpB,EAIM,EAAQ,EAAA,OAAO,CAAC,EAElB,EAAqC,KACrC,EAAW,GAMT,EAAO,EAAA,WAAa,CACxB,EAAW,MAMX,EAAA,gBAAgB,CAAC,EAAE,UAAU,CAAE,MAAK,CAAC,EAErC,GAAY,MAAM,EAClB,EAAa,IAAI,gBAEjB,GAAM,CAAE,OAAQ,GAAgB,EAE1B,EAAU,EAAM,KAAK,EACrB,EAAW,SAAU,EAAU,EAAQ,KAAO,IAAA,GAEpD,EAAM,MAAQ,CAAE,KAAM,EAAU,OAAQ,SAAU,GAE5C,SAAY,CAChB,GAAI,CACF,IAAM,EAAS,MAAM,EAAQ,CAAW,EAEpC,CAAC,EAAY,SAAW,CAAC,IAC3B,EAAM,MAAQ,CAAE,KAAM,EAAQ,OAAQ,OAAQ,EAElD,OAAS,EAAK,CACR,CAAC,EAAY,SAAW,CAAC,IAC3B,EAAM,MAAQ,CAAE,KAAM,EAAU,MAAO,EAAK,OAAQ,OAAQ,EAEhE,CACF,EAAA,CAAG,CACL,EAAG,CAjC6B,QAAO,EAAA,oBAAqB,EAiCzD,CAAqB,EAElB,MAAsB,CACtB,IAEJ,EAAM,MAAQ,EAAM,KAAK,EAAI,EAC/B,EAEM,MAAsB,CACtB,IAEJ,EAAW,GACX,GAAY,MAAM,EAClB,EAAK,QAAQ,EACb,EAAM,QAAQ,EACd,EAAM,QAAQ,EAChB,EA6BA,OA3BA,EAAA,qBAAqB,CAAO,EA2BrB,CAnBL,UACA,IAAI,UAAW,CACb,OAAO,CACT,GACC,EAAA,aAAc,IACd,EAAA,WAAY,GACb,IAAI,MAAO,CACT,OAAO,EAAM,IACf,EACA,SAAY,EAAM,KAAK,EACvB,UACA,UAAY,GAAyB,EAAM,UAAU,CAAQ,GAC5D,OAAO,SAAU,EAClB,IAAI,OAAQ,CACV,OAAO,EAAM,KACf,CAIK,CACT"}
|