@vielzeug/ripple 1.2.3 → 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 -71
- 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 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -12
- 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 -44
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +2 -205
- package/dist/types.d.ts +37 -292
- 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 +23 -16
- 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 -58
- 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 -173
- package/dist/effect.js.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/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-history.cjs +0 -2
- package/dist/store-history.cjs.map +0 -1
- package/dist/store-history.d.ts +0 -42
- package/dist/store-history.d.ts.map +0 -1
- package/dist/store-history.js +0 -60
- package/dist/store-history.js.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 -82
- package/dist/tracking.d.ts.map +0 -1
- package/dist/tracking.js +0 -76
- 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,315 +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
|
-
export interface AsyncSubscription extends Subscription {
|
|
68
|
-
/** Awaits the current async run without disposing the effect. Resolves immediately if idle. */
|
|
69
|
-
run(): Promise<void>;
|
|
70
|
-
/** ES2024 `await using` compatible async disposal. Stops the effect and awaits full teardown. */
|
|
71
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
72
|
-
}
|
|
73
|
-
export type WatchOptions<T> = {
|
|
74
|
-
equals?: EqualityFn<T>;
|
|
75
|
-
immediate?: boolean;
|
|
8
|
+
export type ComputedOptions<T> = {
|
|
9
|
+
equals?: Equality<T>;
|
|
76
10
|
name?: string;
|
|
77
|
-
/** Auto-dispose the watch after the first callback invocation. */
|
|
78
|
-
once?: boolean;
|
|
79
11
|
};
|
|
80
|
-
export type
|
|
81
|
-
/** Value exposed via `data` while the first run is loading. */
|
|
82
|
-
initialValue?: T;
|
|
83
|
-
/** Debug name for the internal effect and state signal. */
|
|
12
|
+
export type EffectOptions = {
|
|
84
13
|
name?: string;
|
|
14
|
+
scheduler?: 'microtask' | 'sync';
|
|
85
15
|
};
|
|
86
|
-
/**
|
|
87
|
-
* Discriminated-union state emitted by a `resource()` signal.
|
|
88
|
-
*
|
|
89
|
-
* - `'loading'` — async factory is in-flight. `data` carries the last fulfilled value (if any).
|
|
90
|
-
* - `'ready'` — factory resolved. `data` is the fulfilled value.
|
|
91
|
-
* - `'error'` — factory rejected. `error` holds the thrown value. `data` carries the last fulfilled value (if any).
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```ts
|
|
95
|
-
* const user = resource(async () => fetchUser(id.value));
|
|
96
|
-
*
|
|
97
|
-
* effect(() => {
|
|
98
|
-
* const s = user.value;
|
|
99
|
-
* if (s.status === 'loading') return showSpinner();
|
|
100
|
-
* if (s.status === 'error') return showError(s.error);
|
|
101
|
-
* renderUser(s.data);
|
|
102
|
-
* });
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export type ResourceState<T> = {
|
|
106
|
-
readonly data?: T;
|
|
107
|
-
readonly status: 'loading';
|
|
108
|
-
} | {
|
|
109
|
-
readonly data: T;
|
|
110
|
-
readonly status: 'ready';
|
|
111
|
-
} | {
|
|
112
|
-
readonly data?: T;
|
|
113
|
-
readonly error: unknown;
|
|
114
|
-
readonly status: 'error';
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Disposable handle returned by `resource()`. Extends `Computed<ResourceState<T>>`
|
|
118
|
-
* with `refresh()` for manually forcing a re-fetch.
|
|
119
|
-
*/
|
|
120
|
-
export interface Resource<T> extends Computed<ResourceState<T>> {
|
|
121
|
-
/**
|
|
122
|
-
* Forces the factory to re-run immediately, aborting any in-flight run —
|
|
123
|
-
* even if no tracked dependency changed. No-op after `dispose()`.
|
|
124
|
-
*/
|
|
125
|
-
refresh(): void;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* A single snapshot entry in `StoreWithHistory`.
|
|
129
|
-
* Carries the frozen state and an optional label for annotated checkpoints.
|
|
130
|
-
*/
|
|
131
|
-
export type HistoryEntry<T> = {
|
|
132
|
-
readonly label?: string;
|
|
133
|
-
readonly state: Readonly<T>;
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* The minimal read-only contract for consuming any reactive value.
|
|
137
|
-
* Effects and computed functions read `.value` (tracked) or `peek()` (untracked).
|
|
138
|
-
* Use `subscribe()` for external imperative listeners.
|
|
139
|
-
*/
|
|
140
16
|
export interface Readable<T> {
|
|
141
|
-
/** `true` after the underlying node has been disposed. */
|
|
142
|
-
readonly disposed: boolean;
|
|
143
|
-
/** The debug name assigned at creation time, or `undefined` if unnamed. */
|
|
144
17
|
readonly name?: string;
|
|
145
18
|
peek(): T;
|
|
146
|
-
|
|
147
|
-
* Subscribes a listener to value change notifications.
|
|
148
|
-
* Implementations MUST NOT invoke `listener` synchronously during registration.
|
|
149
|
-
*/
|
|
150
|
-
subscribe(listener: () => void): Subscription;
|
|
19
|
+
subscribe(listener: () => void): Unsubscribe;
|
|
151
20
|
readonly value: T;
|
|
152
21
|
}
|
|
153
|
-
|
|
154
|
-
* A disposable derived value. The holder is responsible for calling `dispose()`.
|
|
155
|
-
* Returned by `computed()`, `readonly()`, and `resource()`.
|
|
156
|
-
*/
|
|
157
|
-
export interface Computed<T> extends Readable<T> {
|
|
158
|
-
dispose(): void;
|
|
159
|
-
[Symbol.dispose](): void;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* A writable owned signal. The holder can both read and write `.value`,
|
|
163
|
-
* and is responsible for calling `dispose()` when done.
|
|
164
|
-
*/
|
|
165
|
-
export interface Signal<T> extends Computed<T> {
|
|
22
|
+
export interface Signal<T> extends Readable<T> {
|
|
166
23
|
value: T;
|
|
167
24
|
}
|
|
168
|
-
|
|
169
|
-
* Extracts the value type at a dot-separated path `P` within object type `T`.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* type City = PathValue<{ user: { address: { city: string } } }, 'user.address.city'>
|
|
173
|
-
* // → string
|
|
174
|
-
*/
|
|
175
|
-
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;
|
|
176
|
-
/**
|
|
177
|
-
* A fine-grained reactive store for objects.
|
|
178
|
-
* Extends `Computed<Readonly<T>>` — `store.value` provides a tracked whole-store read.
|
|
179
|
-
*
|
|
180
|
-
* `lens()` is the primary reactive read/write API — it returns a `Signal` for
|
|
181
|
-
* a specific property or nested path and registers fine-grained dependencies.
|
|
182
|
-
* `peek()` returns a non-reactive snapshot (useful for serialization).
|
|
183
|
-
* `subscribe()` fires on any mutation (useful for adapters like `storeWithHistory`).
|
|
184
|
-
*/
|
|
185
|
-
export interface Store<T extends object> extends Computed<Readonly<T>> {
|
|
186
|
-
/**
|
|
187
|
-
* Returns a writable `Signal` scoped to a single property or nested path.
|
|
188
|
-
* Reads register a fine-grained dependency on that property's signal —
|
|
189
|
-
* unrelated patches do NOT re-run effects watching this lens.
|
|
190
|
-
* Lenses are cached — `store.lens('x') === store.lens('x')`.
|
|
191
|
-
*/
|
|
192
|
-
lens<P extends string>(path: P): Signal<PathValue<T, P>>;
|
|
193
|
-
/** Atomic partial update — only changed keys notify their subscribers. */
|
|
194
|
-
patch(partial: Partial<T>): void;
|
|
195
|
-
/**
|
|
196
|
-
* Returns a non-reactive snapshot of the current state.
|
|
197
|
-
* Use for serialization or one-off reads outside reactive contexts.
|
|
198
|
-
*/
|
|
199
|
-
peek(): Readonly<T>;
|
|
200
|
-
/**
|
|
201
|
-
* Replaces the entire store state by passing the current state to `fn` and
|
|
202
|
-
* applying the returned value. Only changed properties trigger downstream effects.
|
|
203
|
-
*/
|
|
204
|
-
replace(fn: (state: Readonly<T>) => T): void;
|
|
205
|
-
/** Resets the store to its initial state. */
|
|
206
|
-
reset(): void;
|
|
207
|
-
/**
|
|
208
|
-
* Subscribes to any store mutation (patch / replace / reset / lens write).
|
|
209
|
-
* Used by external adapters — prefer `store.lens()` for reactive reads.
|
|
210
|
-
*/
|
|
211
|
-
subscribe(listener: () => void): Subscription;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* A lifecycle scope that collects cleanup functions and runs them on dispose.
|
|
215
|
-
* Effects and computeds created inside `scope.run()` auto-register their disposal.
|
|
216
|
-
*/
|
|
217
|
-
export interface Scope {
|
|
218
|
-
/**
|
|
219
|
-
* Registers `fn` to run when this scope is disposed.
|
|
220
|
-
* Throws `RippleDisposedScopeError` if called on an already-disposed scope.
|
|
221
|
-
* Use this from within an effect body to explicitly direct a cleanup into the scope
|
|
222
|
-
* rather than the effect's own cleanup queue.
|
|
223
|
-
*/
|
|
224
|
-
add(fn: CleanupFn): void;
|
|
225
|
-
/** `AbortSignal` that is aborted when `dispose()` is called. Use to tie external lifetimes to this scope. */
|
|
226
|
-
readonly disposalSignal: AbortSignal;
|
|
25
|
+
export interface Disposable {
|
|
227
26
|
dispose(): void;
|
|
228
|
-
/** `true` after `dispose()` has been called. */
|
|
229
27
|
readonly disposed: boolean;
|
|
230
|
-
|
|
231
|
-
* Runs `fn` inside this scope's cleanup context.
|
|
232
|
-
* `onCleanup()` calls and resource auto-disposals inside `fn` are registered
|
|
233
|
-
* to this scope when there is no enclosing effect or computed context.
|
|
234
|
-
* Reactive reads inside `fn` are tracked normally against any enclosing effect.
|
|
235
|
-
* Throws `RippleDisposedScopeError` if the scope has already been disposed.
|
|
236
|
-
*/
|
|
237
|
-
run<T>(fn: () => T): T;
|
|
28
|
+
readonly disposalSignal: AbortSignal;
|
|
238
29
|
[Symbol.dispose](): void;
|
|
239
30
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
* work on the history adapter without `.store` indirection.
|
|
244
|
-
*
|
|
245
|
-
* History is **explicit** — call `push()` or `pushNamed()` after any mutation you want undoable.
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```ts
|
|
249
|
-
* const h = storeWithHistory({ count: 0 });
|
|
250
|
-
*
|
|
251
|
-
* h.patch({ count: 1 });
|
|
252
|
-
* h.push(); // save a checkpoint
|
|
253
|
-
* h.undo(); // restore to { count: 0 }
|
|
254
|
-
* h.redo(); // restore to { count: 1 }
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
export interface StoreWithHistory<T extends object> extends Store<T> {
|
|
258
|
-
/** `true` when there is at least one snapshot ahead to redo. Reactive — reads inside effects re-run on change. */
|
|
259
|
-
readonly canRedo: boolean;
|
|
260
|
-
/** `true` when there is at least one snapshot to undo to. Reactive — reads inside effects re-run on change. */
|
|
261
|
-
readonly canUndo: boolean;
|
|
262
|
-
/** Returns the history entry at the given index (0 = oldest). */
|
|
263
|
-
historyAt(index: number): HistoryEntry<T> | undefined;
|
|
264
|
-
/** Number of snapshots currently in history. */
|
|
265
|
-
readonly historyLength: number;
|
|
266
|
-
/** Saves the current store state as an explicit undo checkpoint. */
|
|
267
|
-
push(): void;
|
|
268
|
-
/**
|
|
269
|
-
* Saves the current store state as an annotated checkpoint.
|
|
270
|
-
* Use to mark significant transitions (e.g. `'import'`, `'reset'`) so time-travel
|
|
271
|
-
* debuggers can distinguish user-initiated from programmatic mutations.
|
|
272
|
-
*/
|
|
273
|
-
pushNamed(label: string): void;
|
|
274
|
-
/** Move forward one snapshot. No-op when at the most recent checkpoint. */
|
|
275
|
-
redo(): void;
|
|
276
|
-
/** The underlying store — kept as an escape hatch for adapters that need direct store access. */
|
|
277
|
-
readonly store: Store<T>;
|
|
278
|
-
/** Move back one snapshot. No-op when at the oldest checkpoint. */
|
|
279
|
-
undo(): void;
|
|
31
|
+
export type EffectHandle = Disposable;
|
|
32
|
+
export interface Scope extends Disposable {
|
|
33
|
+
run<T>(fn: () => T): T;
|
|
280
34
|
}
|
|
281
|
-
export type
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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';
|
|
296
50
|
};
|
|
297
|
-
|
|
298
|
-
export type
|
|
299
|
-
kind: '
|
|
300
|
-
name
|
|
301
|
-
path?: string;
|
|
51
|
+
export type ReactiveObserver = (event: ReactiveEvent) => void;
|
|
52
|
+
export type ReactiveErrorContext = {
|
|
53
|
+
readonly kind: 'cleanup' | 'effect' | 'listener' | 'observer';
|
|
54
|
+
readonly name?: string;
|
|
302
55
|
};
|
|
303
|
-
export type
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
/** Called when a signal, computed, or effect is disposed. */
|
|
307
|
-
dispose?(event: DisposeEvent): void;
|
|
308
|
-
/** Called when a store-level mutation (patch/replace/reset/lens) occurs. */
|
|
309
|
-
mutate?(event: MutateEvent): void;
|
|
310
|
-
/** Called when an effect starts running. */
|
|
311
|
-
run?(event: NamedEvent): void;
|
|
312
|
-
/** Called when a signal's value changes. */
|
|
313
|
-
write?(event: WriteEvent): void;
|
|
56
|
+
export type RippleOptions = {
|
|
57
|
+
observer?: ReactiveObserver;
|
|
58
|
+
onError?: (error: unknown, context: ReactiveErrorContext) => void;
|
|
314
59
|
};
|
|
315
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,17 +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
|
+
},
|
|
31
|
+
"./watch": {
|
|
32
|
+
"source": "./src/watch.ts",
|
|
33
|
+
"types": "./dist/watch.d.ts",
|
|
34
|
+
"import": "./dist/watch.js",
|
|
35
|
+
"require": "./dist/watch.cjs"
|
|
30
36
|
}
|
|
31
37
|
},
|
|
32
38
|
"scripts": {
|
|
@@ -34,10 +40,11 @@
|
|
|
34
40
|
"build:types": "tsc -p tsconfig.declarations.json",
|
|
35
41
|
"fix": "eslint --fix src",
|
|
36
42
|
"lint": "eslint src",
|
|
37
|
-
"prepublishOnly": "pnpm run build",
|
|
43
|
+
"prepublishOnly": "pnpm run build && pnpm run verify:exports",
|
|
38
44
|
"preview": "vite preview",
|
|
39
45
|
"test": "vitest",
|
|
40
|
-
"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"
|
|
41
48
|
},
|
|
42
49
|
"publishConfig": {
|
|
43
50
|
"access": "public",
|
|
@@ -47,9 +54,9 @@
|
|
|
47
54
|
"node": ">=22"
|
|
48
55
|
},
|
|
49
56
|
"devDependencies": {
|
|
50
|
-
"@types/node": "^26.1.
|
|
57
|
+
"@types/node": "^26.1.2",
|
|
51
58
|
"typescript": "^6.0.3",
|
|
52
|
-
"vite": "^8.
|
|
59
|
+
"vite": "^8.2.0",
|
|
53
60
|
"vitest": "^4.1.10"
|
|
54
61
|
}
|
|
55
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("./tracking.cjs"),t=require("./symbols.cjs"),n=require("./effect.cjs"),r=require("./signal.cjs");var i=(i,a)=>{let o=a?.name,s=r.signal({data:a?.initialValue,status:`loading`},o?{name:o}:void 0),c=r.signal(0),l=null,u=!1,d=n.effect(()=>{c.value,l?.abort(),l=new AbortController;let{signal:e}=l,t=s.peek(),n=`data`in t?t.data:void 0;s.value={data:n,status:`loading`},(async()=>{try{let t=await i(e);!e.aborted&&!u&&(s.value={data:t,status:`ready`})}catch(t){!e.aborted&&!u&&(s.value={data:n,error:t,status:`error`})}})()},o?{name:o}:void 0),f=()=>{u||(c.value=c.peek()+1)},p=()=>{u||(u=!0,l?.abort(),d.dispose(),s.dispose(),c.dispose())};return e.autoRegisterDisposal(p),{dispose:p,get disposed(){return u},[t.IS_COMPUTED]:!0,[t.IS_SIGNAL]:!0,get name(){return s.name},peek:()=>s.peek(),refresh:f,subscribe:e=>s.subscribe(e),[Symbol.dispose]:p,get value(){return s.value}}};exports.resource=i;
|
|
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 { effect } from './effect';\nimport { signal } from './signal';\nimport { IS_COMPUTED, IS_SIGNAL } 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 const stop = effect(\n () => {\n void epoch.value;\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 },\n name ? { name } : undefined,\n );\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 return {\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 } as Resource<T>;\n};\n"],"mappings":"iHAwCA,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,GAET,EAAO,EAAA,WACL,CACJ,EAAW,MAEX,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,EACA,EAAO,CAAE,MAAK,EAAI,IAAA,EACpB,EAEM,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,EAIA,OAFA,EAAA,qBAAqB,CAAO,EAErB,CACL,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,CACF,CACF"}
|
package/dist/async-computed.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Resource, ResourceOptions } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a reactive async resource that emits a `ResourceState<T>` discriminated union.
|
|
4
|
-
*
|
|
5
|
-
* Dependencies are tracked synchronously in the factory (before the first `await`).
|
|
6
|
-
* The factory receives an `AbortSignal` that fires when dependencies change or
|
|
7
|
-
* the resource is disposed, cancelling any in-flight work.
|
|
8
|
-
*
|
|
9
|
-
* If `resource()` is created inside an active `effect()` or `scope.run()` context,
|
|
10
|
-
* it is automatically registered for cleanup and disposed with that context —
|
|
11
|
-
* matching `computed()`'s auto-disposal behavior.
|
|
12
|
-
*
|
|
13
|
-
* Call `refresh()` to force the factory to re-run immediately, even if no tracked
|
|
14
|
-
* dependency changed — useful for manual "retry"/"refetch" actions.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* const userId = signal('u1');
|
|
19
|
-
* const user = resource(async (signal) => {
|
|
20
|
-
* const id = userId.value; // tracked dep — re-runs when userId changes
|
|
21
|
-
* return fetchUser(id, { signal });
|
|
22
|
-
* });
|
|
23
|
-
*
|
|
24
|
-
* effect(() => {
|
|
25
|
-
* const s = user.value;
|
|
26
|
-
* if (s.status === 'loading') return showSpinner();
|
|
27
|
-
* if (s.status === 'error') return showError(s.error);
|
|
28
|
-
* renderUser(s.data);
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* user.refresh(); // force a re-fetch without changing userId
|
|
32
|
-
* user.dispose();
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare const resource: <T>(factory: (abortSignal: AbortSignal) => Promise<T>, options?: ResourceOptions<T>) => Resource<T>;
|
|
36
|
-
//# sourceMappingURL=async-computed.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-computed.d.ts","sourceRoot":"","sources":["../src/async-computed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAiB,MAAM,SAAS,CAAC;AAOxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EACxB,SAAS,CAAC,WAAW,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACjD,UAAU,eAAe,CAAC,CAAC,CAAC,KAC3B,QAAQ,CAAC,CAAC,CAiFZ,CAAC"}
|