unwrapped 0.1.10 → 0.1.12
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/CHANGELOG.md +12 -0
- package/dist/core/index.d.mts +54 -20
- package/dist/core/index.d.ts +54 -20
- package/dist/core/index.js +71 -18
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +71 -18
- package/dist/core/index.mjs.map +1 -1
- package/dist/vue/index.d.mts +136 -110
- package/dist/vue/index.d.ts +136 -110
- package/dist/vue/index.js +2 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +2 -2
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/vue/index.d.ts
CHANGED
|
@@ -13,13 +13,13 @@ interface ReactiveProcessOptions {
|
|
|
13
13
|
* @param asyncResult the result to make reactive
|
|
14
14
|
* @returns the ref to the result
|
|
15
15
|
*/
|
|
16
|
-
declare function useAsyncResultRef<T, E extends ErrorBase = ErrorBase>(asyncResult?: AsyncResult<T, E>): Ref<AsyncResult<T, E>, AsyncResult<T, E>>;
|
|
16
|
+
declare function useAsyncResultRef<T, E extends ErrorBase = ErrorBase, P = unknown>(asyncResult?: AsyncResult<T, E, P>): Ref<AsyncResult<T, E, P>, AsyncResult<T, E, P>>;
|
|
17
17
|
/**
|
|
18
18
|
* Creates an AsyncResult ref from a promise returning a Result.
|
|
19
19
|
* @param promise the promise returning a Result
|
|
20
20
|
* @returns the ref to the AsyncResult
|
|
21
21
|
*/
|
|
22
|
-
declare function useAsyncResultRefFromPromise<T, E extends ErrorBase = ErrorBase>(promise: Promise<Result<T, E>>): Ref<AsyncResult<T, E>, AsyncResult<T, E>>;
|
|
22
|
+
declare function useAsyncResultRefFromPromise<T, E extends ErrorBase = ErrorBase>(promise: Promise<Result<T, E>>): Ref<AsyncResult<T, E, unknown>, AsyncResult<T, E, unknown>>;
|
|
23
23
|
/**
|
|
24
24
|
* Watches a source, gives it as inputs to the function provided, and updates the result contained in the ref accordingly.
|
|
25
25
|
*
|
|
@@ -32,8 +32,8 @@ declare function useReactiveChain<Inputs, T, E extends ErrorBase = ErrorBase>(so
|
|
|
32
32
|
/**
|
|
33
33
|
* The return type of useLazyAction.
|
|
34
34
|
*/
|
|
35
|
-
interface LazyActionRef<T, E extends ErrorBase = ErrorBase> {
|
|
36
|
-
resultRef: Ref<AsyncResult<T, E>>;
|
|
35
|
+
interface LazyActionRef<T, E extends ErrorBase = ErrorBase, P = unknown> {
|
|
36
|
+
resultRef: Ref<AsyncResult<T, E, P>>;
|
|
37
37
|
trigger: () => void;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -44,7 +44,7 @@ interface LazyActionRef<T, E extends ErrorBase = ErrorBase> {
|
|
|
44
44
|
* @param action the action to execute immediately
|
|
45
45
|
* @returns a ref to the AsyncResult representing the action's state
|
|
46
46
|
*/
|
|
47
|
-
declare function useAction<T, E extends ErrorBase = ErrorBase>(action: Action<T, E>): Ref<AsyncResult<T, E>>;
|
|
47
|
+
declare function useAction<T, E extends ErrorBase = ErrorBase, P = unknown>(action: Action<T, E, P>): Ref<AsyncResult<T, E, P>>;
|
|
48
48
|
/**
|
|
49
49
|
* Creates a lazy action that can be triggered manually.
|
|
50
50
|
*
|
|
@@ -53,21 +53,21 @@ declare function useAction<T, E extends ErrorBase = ErrorBase>(action: Action<T,
|
|
|
53
53
|
* @param action the action to execute when triggered
|
|
54
54
|
* @returns an object containing a ref to the AsyncResult and a trigger function
|
|
55
55
|
*/
|
|
56
|
-
declare function useLazyAction<T, E extends ErrorBase = ErrorBase>(action: Action<T, E>): LazyActionRef<T, E>;
|
|
56
|
+
declare function useLazyAction<T, E extends ErrorBase = ErrorBase, P = unknown>(action: Action<T, E, P>): LazyActionRef<T, E, P>;
|
|
57
57
|
/**
|
|
58
58
|
* Runs a generator function immediately and returns a ref to the AsyncResult representing the generator's state.
|
|
59
59
|
* @param generatorFunc the generator function to run immediately
|
|
60
60
|
* @returns a ref to the AsyncResult representing the generator's state
|
|
61
61
|
*/
|
|
62
|
-
declare function useGenerator<T>(generatorFunc: () => AsyncResultGenerator<T>): Ref<AsyncResult<T, any>>;
|
|
62
|
+
declare function useGenerator<T, P = unknown>(generatorFunc: (notifyProgress?: (progress: P) => void) => AsyncResultGenerator<T>): Ref<AsyncResult<T, any, P>>;
|
|
63
63
|
/**
|
|
64
64
|
* Creates a lazy generator that can be triggered manually.
|
|
65
65
|
*
|
|
66
66
|
* @param generatorFunc the generator function to run when triggered
|
|
67
67
|
* @returns an object containing a ref to the AsyncResult and a trigger function
|
|
68
68
|
*/
|
|
69
|
-
declare function useLazyGenerator<T>(generatorFunc: () => AsyncResultGenerator<T>): {
|
|
70
|
-
resultRef: Ref<AsyncResult<T, any>>;
|
|
69
|
+
declare function useLazyGenerator<T, P = unknown>(generatorFunc: () => AsyncResultGenerator<T>): {
|
|
70
|
+
resultRef: Ref<AsyncResult<T, any, P>>;
|
|
71
71
|
trigger: () => void;
|
|
72
72
|
};
|
|
73
73
|
/**
|
|
@@ -78,7 +78,7 @@ declare function useLazyGenerator<T>(generatorFunc: () => AsyncResultGenerator<T
|
|
|
78
78
|
* @param options optional settings
|
|
79
79
|
* @returns ref to the result
|
|
80
80
|
*/
|
|
81
|
-
declare function useReactiveGenerator<Inputs, T, E extends ErrorBase = ErrorBase>(source: WatchSource<Inputs>, generatorFunc: (args: Inputs) => AsyncResultGenerator<T>, options?: ReactiveProcessOptions): Ref<AsyncResult<T, E>>;
|
|
81
|
+
declare function useReactiveGenerator<Inputs, T, E extends ErrorBase = ErrorBase, P = unknown>(source: WatchSource<Inputs>, generatorFunc: (args: Inputs) => AsyncResultGenerator<T>, options?: ReactiveProcessOptions): Ref<AsyncResult<T, E, P>>;
|
|
82
82
|
/**
|
|
83
83
|
* Creates a reactive AsyncResultCollection wrapped in a Vue ref.
|
|
84
84
|
* The AsyncResultCollection notifies Vue's reactivity system whenever its state changes.
|
|
@@ -101,6 +101,7 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
101
101
|
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
102
102
|
readonly [Symbol.toStringTag]: string;
|
|
103
103
|
};
|
|
104
|
+
progress?: unknown;
|
|
104
105
|
} | {
|
|
105
106
|
status: "success";
|
|
106
107
|
value: vue.UnwrapRef<T>;
|
|
@@ -115,28 +116,31 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
115
116
|
unwrapOrNull: () => T | null;
|
|
116
117
|
unwrapOrThrow: () => T;
|
|
117
118
|
unwrapErrorOrNull: () => E | null;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
getProgressOrNull: () => unknown;
|
|
120
|
+
updateFromValue: (value: T) => AsyncResult<T, E, unknown>;
|
|
121
|
+
updateFromError: (error: E) => AsyncResult<T, E, unknown>;
|
|
122
|
+
updateProgress: (progress: unknown) => AsyncResult<T, E, unknown>;
|
|
123
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E, unknown>;
|
|
124
|
+
waitForSettled: () => Promise<AsyncResult<T, E, unknown>>;
|
|
122
125
|
toResultPromise: () => Promise<Result<T, E>>;
|
|
123
126
|
toValueOrThrowPromise: () => Promise<T>;
|
|
124
127
|
toValueOrNullPromise: () => Promise<T | null>;
|
|
125
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
126
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
127
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
128
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E, unknown>;
|
|
129
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
130
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
128
131
|
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
129
132
|
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
130
133
|
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
131
134
|
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
132
|
-
mirror: (other: AsyncResult<T, E
|
|
133
|
-
mirrorUntilSettled: (other: AsyncResult<T, E
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
mirror: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
136
|
+
mirrorUntilSettled: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
137
|
+
updateFromAction: (action: Action<T, E, unknown>) => AsyncResult<T, E, unknown>;
|
|
138
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2, unknown>;
|
|
139
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2, unknown>) => AsyncResult<O, E | E2, unknown>;
|
|
140
|
+
runInPlace: (generatorFunc: (notifyProgress?: ((progress: unknown) => void) | undefined) => AsyncResultGenerator<T>) => AsyncResult<T, E, unknown>;
|
|
137
141
|
log: (name?: string) => void;
|
|
138
142
|
debug: (name?: string) => () => void;
|
|
139
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
143
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E, unknown>, T, any>;
|
|
140
144
|
};
|
|
141
145
|
unsub: () => void;
|
|
142
146
|
}> & Omit<Map<string, unwrapped_core.AsyncResultCollectionItem<T, E>>, keyof Map<any, any>>;
|
|
@@ -152,6 +156,7 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
152
156
|
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
153
157
|
readonly [Symbol.toStringTag]: string;
|
|
154
158
|
};
|
|
159
|
+
progress?: unknown;
|
|
155
160
|
} | {
|
|
156
161
|
status: "success";
|
|
157
162
|
value: vue.UnwrapRef<T>;
|
|
@@ -166,28 +171,31 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
166
171
|
unwrapOrNull: () => T | null;
|
|
167
172
|
unwrapOrThrow: () => T;
|
|
168
173
|
unwrapErrorOrNull: () => E | null;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
getProgressOrNull: () => unknown;
|
|
175
|
+
updateFromValue: (value: T) => AsyncResult<T, E, unknown>;
|
|
176
|
+
updateFromError: (error: E) => AsyncResult<T, E, unknown>;
|
|
177
|
+
updateProgress: (progress: unknown) => AsyncResult<T, E, unknown>;
|
|
178
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E, unknown>;
|
|
179
|
+
waitForSettled: () => Promise<AsyncResult<T, E, unknown>>;
|
|
173
180
|
toResultPromise: () => Promise<Result<T, E>>;
|
|
174
181
|
toValueOrThrowPromise: () => Promise<T>;
|
|
175
182
|
toValueOrNullPromise: () => Promise<T | null>;
|
|
176
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
177
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
178
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
183
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E, unknown>;
|
|
184
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
185
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
179
186
|
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
180
187
|
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
181
188
|
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
182
189
|
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
183
|
-
mirror: (other: AsyncResult<T, E
|
|
184
|
-
mirrorUntilSettled: (other: AsyncResult<T, E
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
mirror: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
191
|
+
mirrorUntilSettled: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
192
|
+
updateFromAction: (action: Action<T, E, unknown>) => AsyncResult<T, E, unknown>;
|
|
193
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2, unknown>;
|
|
194
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2, unknown>) => AsyncResult<O, E | E2, unknown>;
|
|
195
|
+
runInPlace: (generatorFunc: (notifyProgress?: ((progress: unknown) => void) | undefined) => AsyncResultGenerator<T>) => AsyncResult<T, E, unknown>;
|
|
188
196
|
log: (name?: string) => void;
|
|
189
197
|
debug: (name?: string) => () => void;
|
|
190
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
198
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E, unknown>, T, any>;
|
|
191
199
|
}[];
|
|
192
200
|
readonly entries: [string, {
|
|
193
201
|
state: {
|
|
@@ -200,6 +208,7 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
200
208
|
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
201
209
|
readonly [Symbol.toStringTag]: string;
|
|
202
210
|
};
|
|
211
|
+
progress?: unknown;
|
|
203
212
|
} | {
|
|
204
213
|
status: "success";
|
|
205
214
|
value: vue.UnwrapRef<T>;
|
|
@@ -214,44 +223,47 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
214
223
|
unwrapOrNull: () => T | null;
|
|
215
224
|
unwrapOrThrow: () => T;
|
|
216
225
|
unwrapErrorOrNull: () => E | null;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
226
|
+
getProgressOrNull: () => unknown;
|
|
227
|
+
updateFromValue: (value: T) => AsyncResult<T, E, unknown>;
|
|
228
|
+
updateFromError: (error: E) => AsyncResult<T, E, unknown>;
|
|
229
|
+
updateProgress: (progress: unknown) => AsyncResult<T, E, unknown>;
|
|
230
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E, unknown>;
|
|
231
|
+
waitForSettled: () => Promise<AsyncResult<T, E, unknown>>;
|
|
221
232
|
toResultPromise: () => Promise<Result<T, E>>;
|
|
222
233
|
toValueOrThrowPromise: () => Promise<T>;
|
|
223
234
|
toValueOrNullPromise: () => Promise<T | null>;
|
|
224
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
225
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
226
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
235
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E, unknown>;
|
|
236
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
237
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
227
238
|
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
228
239
|
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
229
240
|
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
230
241
|
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
231
|
-
mirror: (other: AsyncResult<T, E
|
|
232
|
-
mirrorUntilSettled: (other: AsyncResult<T, E
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
242
|
+
mirror: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
243
|
+
mirrorUntilSettled: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
244
|
+
updateFromAction: (action: Action<T, E, unknown>) => AsyncResult<T, E, unknown>;
|
|
245
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2, unknown>;
|
|
246
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2, unknown>) => AsyncResult<O, E | E2, unknown>;
|
|
247
|
+
runInPlace: (generatorFunc: (notifyProgress?: ((progress: unknown) => void) | undefined) => AsyncResultGenerator<T>) => AsyncResult<T, E, unknown>;
|
|
236
248
|
log: (name?: string) => void;
|
|
237
249
|
debug: (name?: string) => () => void;
|
|
238
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
250
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E, unknown>, T, any>;
|
|
239
251
|
}][];
|
|
240
252
|
state: unwrapped_core.AsyncResultCollectionState;
|
|
241
253
|
listen: (listener: (taskQueue: AsyncResultCollection<T, E>) => void) => () => void;
|
|
242
|
-
onItemSuccess: (listener: (task: AsyncResult<T, E>, key: string) => void) => () => void;
|
|
243
|
-
onItemError: (listener: (task: AsyncResult<T, E>, key: string) => void) => () => void;
|
|
244
|
-
add: (key: string, task: AsyncResult<T, E>, removeOnSettle?: boolean) => AsyncResult<T, E>;
|
|
254
|
+
onItemSuccess: (listener: (task: AsyncResult<T, E, unknown>, key: string) => void) => () => void;
|
|
255
|
+
onItemError: (listener: (task: AsyncResult<T, E, unknown>, key: string) => void) => () => void;
|
|
256
|
+
add: (key: string, task: AsyncResult<T, E, unknown>, removeOnSettle?: boolean) => AsyncResult<T, E, unknown>;
|
|
245
257
|
remove: (key: string) => boolean;
|
|
246
258
|
clear: () => void;
|
|
247
259
|
anyLoading: () => boolean;
|
|
248
|
-
getAllFiltered: (predicate: (task: AsyncResult<T, E>) => boolean) => AsyncResult<T, E>[];
|
|
249
|
-
getAllFilteredAndMap: <U>(filterPredicate: (task: AsyncResult<T, E>) => boolean, mapFunc: (task: AsyncResult<T, E>) => U) => U[];
|
|
250
|
-
getAllSuccess: () => AsyncResult<T, E>[];
|
|
260
|
+
getAllFiltered: (predicate: (task: AsyncResult<T, E, unknown>) => boolean) => AsyncResult<T, E, unknown>[];
|
|
261
|
+
getAllFilteredAndMap: <U>(filterPredicate: (task: AsyncResult<T, E, unknown>) => boolean, mapFunc: (task: AsyncResult<T, E, unknown>) => U) => U[];
|
|
262
|
+
getAllSuccess: () => AsyncResult<T, E, unknown>[];
|
|
251
263
|
getAllSuccessValues: () => T[];
|
|
252
|
-
getAllErrors: () => AsyncResult<T, E>[];
|
|
264
|
+
getAllErrors: () => AsyncResult<T, E, unknown>[];
|
|
253
265
|
getAllErrorValues: () => E[];
|
|
254
|
-
getAllLoading: () => AsyncResult<T, E>[];
|
|
266
|
+
getAllLoading: () => AsyncResult<T, E, unknown>[];
|
|
255
267
|
getAllLoadingPromises: () => Promise<Result<T, E>>[];
|
|
256
268
|
log: (name?: string) => void;
|
|
257
269
|
debug: (name?: string) => () => void;
|
|
@@ -269,6 +281,7 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
269
281
|
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
270
282
|
readonly [Symbol.toStringTag]: string;
|
|
271
283
|
};
|
|
284
|
+
progress?: unknown;
|
|
272
285
|
} | {
|
|
273
286
|
status: "success";
|
|
274
287
|
value: vue.UnwrapRef<T>;
|
|
@@ -283,28 +296,31 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
283
296
|
unwrapOrNull: () => T | null;
|
|
284
297
|
unwrapOrThrow: () => T;
|
|
285
298
|
unwrapErrorOrNull: () => E | null;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
299
|
+
getProgressOrNull: () => unknown;
|
|
300
|
+
updateFromValue: (value: T) => AsyncResult<T, E, unknown>;
|
|
301
|
+
updateFromError: (error: E) => AsyncResult<T, E, unknown>;
|
|
302
|
+
updateProgress: (progress: unknown) => AsyncResult<T, E, unknown>;
|
|
303
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E, unknown>;
|
|
304
|
+
waitForSettled: () => Promise<AsyncResult<T, E, unknown>>;
|
|
290
305
|
toResultPromise: () => Promise<Result<T, E>>;
|
|
291
306
|
toValueOrThrowPromise: () => Promise<T>;
|
|
292
307
|
toValueOrNullPromise: () => Promise<T | null>;
|
|
293
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
294
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
295
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
308
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E, unknown>;
|
|
309
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
310
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
296
311
|
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
297
312
|
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
298
313
|
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
299
314
|
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
300
|
-
mirror: (other: AsyncResult<T, E
|
|
301
|
-
mirrorUntilSettled: (other: AsyncResult<T, E
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
315
|
+
mirror: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
316
|
+
mirrorUntilSettled: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
317
|
+
updateFromAction: (action: Action<T, E, unknown>) => AsyncResult<T, E, unknown>;
|
|
318
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2, unknown>;
|
|
319
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2, unknown>) => AsyncResult<O, E | E2, unknown>;
|
|
320
|
+
runInPlace: (generatorFunc: (notifyProgress?: ((progress: unknown) => void) | undefined) => AsyncResultGenerator<T>) => AsyncResult<T, E, unknown>;
|
|
305
321
|
log: (name?: string) => void;
|
|
306
322
|
debug: (name?: string) => () => void;
|
|
307
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
323
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E, unknown>, T, any>;
|
|
308
324
|
};
|
|
309
325
|
unsub: () => void;
|
|
310
326
|
}> & Omit<Map<string, unwrapped_core.AsyncResultCollectionItem<T, E>>, keyof Map<any, any>>;
|
|
@@ -320,6 +336,7 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
320
336
|
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
321
337
|
readonly [Symbol.toStringTag]: string;
|
|
322
338
|
};
|
|
339
|
+
progress?: unknown;
|
|
323
340
|
} | {
|
|
324
341
|
status: "success";
|
|
325
342
|
value: vue.UnwrapRef<T>;
|
|
@@ -334,28 +351,31 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
334
351
|
unwrapOrNull: () => T | null;
|
|
335
352
|
unwrapOrThrow: () => T;
|
|
336
353
|
unwrapErrorOrNull: () => E | null;
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
354
|
+
getProgressOrNull: () => unknown;
|
|
355
|
+
updateFromValue: (value: T) => AsyncResult<T, E, unknown>;
|
|
356
|
+
updateFromError: (error: E) => AsyncResult<T, E, unknown>;
|
|
357
|
+
updateProgress: (progress: unknown) => AsyncResult<T, E, unknown>;
|
|
358
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E, unknown>;
|
|
359
|
+
waitForSettled: () => Promise<AsyncResult<T, E, unknown>>;
|
|
341
360
|
toResultPromise: () => Promise<Result<T, E>>;
|
|
342
361
|
toValueOrThrowPromise: () => Promise<T>;
|
|
343
362
|
toValueOrNullPromise: () => Promise<T | null>;
|
|
344
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
345
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
346
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
363
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E, unknown>;
|
|
364
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
365
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
347
366
|
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
348
367
|
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
349
368
|
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
350
369
|
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
351
|
-
mirror: (other: AsyncResult<T, E
|
|
352
|
-
mirrorUntilSettled: (other: AsyncResult<T, E
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
370
|
+
mirror: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
371
|
+
mirrorUntilSettled: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
372
|
+
updateFromAction: (action: Action<T, E, unknown>) => AsyncResult<T, E, unknown>;
|
|
373
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2, unknown>;
|
|
374
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2, unknown>) => AsyncResult<O, E | E2, unknown>;
|
|
375
|
+
runInPlace: (generatorFunc: (notifyProgress?: ((progress: unknown) => void) | undefined) => AsyncResultGenerator<T>) => AsyncResult<T, E, unknown>;
|
|
356
376
|
log: (name?: string) => void;
|
|
357
377
|
debug: (name?: string) => () => void;
|
|
358
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
378
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E, unknown>, T, any>;
|
|
359
379
|
}[];
|
|
360
380
|
readonly entries: [string, {
|
|
361
381
|
state: {
|
|
@@ -368,6 +388,7 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
368
388
|
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
369
389
|
readonly [Symbol.toStringTag]: string;
|
|
370
390
|
};
|
|
391
|
+
progress?: unknown;
|
|
371
392
|
} | {
|
|
372
393
|
status: "success";
|
|
373
394
|
value: vue.UnwrapRef<T>;
|
|
@@ -382,51 +403,56 @@ declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBa
|
|
|
382
403
|
unwrapOrNull: () => T | null;
|
|
383
404
|
unwrapOrThrow: () => T;
|
|
384
405
|
unwrapErrorOrNull: () => E | null;
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
406
|
+
getProgressOrNull: () => unknown;
|
|
407
|
+
updateFromValue: (value: T) => AsyncResult<T, E, unknown>;
|
|
408
|
+
updateFromError: (error: E) => AsyncResult<T, E, unknown>;
|
|
409
|
+
updateProgress: (progress: unknown) => AsyncResult<T, E, unknown>;
|
|
410
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E, unknown>;
|
|
411
|
+
waitForSettled: () => Promise<AsyncResult<T, E, unknown>>;
|
|
389
412
|
toResultPromise: () => Promise<Result<T, E>>;
|
|
390
413
|
toValueOrThrowPromise: () => Promise<T>;
|
|
391
414
|
toValueOrNullPromise: () => Promise<T | null>;
|
|
392
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
393
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
394
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>,
|
|
415
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E, unknown>;
|
|
416
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
417
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
395
418
|
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
396
419
|
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
397
420
|
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
398
421
|
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
399
|
-
mirror: (other: AsyncResult<T, E
|
|
400
|
-
mirrorUntilSettled: (other: AsyncResult<T, E
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
422
|
+
mirror: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
423
|
+
mirrorUntilSettled: (other: AsyncResult<T, E, unknown>, options?: unwrapped_core.AsyncResultListenerOptions) => () => void;
|
|
424
|
+
updateFromAction: (action: Action<T, E, unknown>) => AsyncResult<T, E, unknown>;
|
|
425
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2, unknown>;
|
|
426
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2, unknown>) => AsyncResult<O, E | E2, unknown>;
|
|
427
|
+
runInPlace: (generatorFunc: (notifyProgress?: ((progress: unknown) => void) | undefined) => AsyncResultGenerator<T>) => AsyncResult<T, E, unknown>;
|
|
404
428
|
log: (name?: string) => void;
|
|
405
429
|
debug: (name?: string) => () => void;
|
|
406
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
430
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E, unknown>, T, any>;
|
|
407
431
|
}][];
|
|
408
432
|
state: unwrapped_core.AsyncResultCollectionState;
|
|
409
433
|
listen: (listener: (taskQueue: AsyncResultCollection<T, E>) => void) => () => void;
|
|
410
|
-
onItemSuccess: (listener: (task: AsyncResult<T, E>, key: string) => void) => () => void;
|
|
411
|
-
onItemError: (listener: (task: AsyncResult<T, E>, key: string) => void) => () => void;
|
|
412
|
-
add: (key: string, task: AsyncResult<T, E>, removeOnSettle?: boolean) => AsyncResult<T, E>;
|
|
434
|
+
onItemSuccess: (listener: (task: AsyncResult<T, E, unknown>, key: string) => void) => () => void;
|
|
435
|
+
onItemError: (listener: (task: AsyncResult<T, E, unknown>, key: string) => void) => () => void;
|
|
436
|
+
add: (key: string, task: AsyncResult<T, E, unknown>, removeOnSettle?: boolean) => AsyncResult<T, E, unknown>;
|
|
413
437
|
remove: (key: string) => boolean;
|
|
414
438
|
clear: () => void;
|
|
415
439
|
anyLoading: () => boolean;
|
|
416
|
-
getAllFiltered: (predicate: (task: AsyncResult<T, E>) => boolean) => AsyncResult<T, E>[];
|
|
417
|
-
getAllFilteredAndMap: <U>(filterPredicate: (task: AsyncResult<T, E>) => boolean, mapFunc: (task: AsyncResult<T, E>) => U) => U[];
|
|
418
|
-
getAllSuccess: () => AsyncResult<T, E>[];
|
|
440
|
+
getAllFiltered: (predicate: (task: AsyncResult<T, E, unknown>) => boolean) => AsyncResult<T, E, unknown>[];
|
|
441
|
+
getAllFilteredAndMap: <U>(filterPredicate: (task: AsyncResult<T, E, unknown>) => boolean, mapFunc: (task: AsyncResult<T, E, unknown>) => U) => U[];
|
|
442
|
+
getAllSuccess: () => AsyncResult<T, E, unknown>[];
|
|
419
443
|
getAllSuccessValues: () => T[];
|
|
420
|
-
getAllErrors: () => AsyncResult<T, E>[];
|
|
444
|
+
getAllErrors: () => AsyncResult<T, E, unknown>[];
|
|
421
445
|
getAllErrorValues: () => E[];
|
|
422
|
-
getAllLoading: () => AsyncResult<T, E>[];
|
|
446
|
+
getAllLoading: () => AsyncResult<T, E, unknown>[];
|
|
423
447
|
getAllLoadingPromises: () => Promise<Result<T, E>>[];
|
|
424
448
|
log: (name?: string) => void;
|
|
425
449
|
debug: (name?: string) => () => void;
|
|
426
450
|
}>;
|
|
427
451
|
|
|
428
|
-
interface CustomSlots<E extends ErrorBase = ErrorBase> {
|
|
429
|
-
loading?: (
|
|
452
|
+
interface CustomSlots<E extends ErrorBase = ErrorBase, P = unknown> {
|
|
453
|
+
loading?: (props: {
|
|
454
|
+
progress?: P;
|
|
455
|
+
}) => VNode;
|
|
430
456
|
error?: (props: {
|
|
431
457
|
error: E;
|
|
432
458
|
}) => VNode;
|
|
@@ -453,9 +479,9 @@ interface CustomSlots<E extends ErrorBase = ErrorBase> {
|
|
|
453
479
|
* </template>
|
|
454
480
|
* </MyLoader>
|
|
455
481
|
*/
|
|
456
|
-
declare function makeAsyncResultLoader<T, E extends ErrorBase = ErrorBase>(slots: CustomSlots<E>, name?: string): vue.DefineComponent<vue.ExtractPropTypes<{
|
|
482
|
+
declare function makeAsyncResultLoader<T, E extends ErrorBase = ErrorBase, P = unknown>(slots: CustomSlots<E, P>, name?: string): vue.DefineComponent<vue.ExtractPropTypes<{
|
|
457
483
|
result: {
|
|
458
|
-
type: () => AsyncResult<T, E>;
|
|
484
|
+
type: () => AsyncResult<T, E, P>;
|
|
459
485
|
required: true;
|
|
460
486
|
};
|
|
461
487
|
}>, () => VNode<vue.RendererNode, vue.RendererElement, {
|
|
@@ -464,10 +490,10 @@ declare function makeAsyncResultLoader<T, E extends ErrorBase = ErrorBase>(slots
|
|
|
464
490
|
[key: string]: any;
|
|
465
491
|
}>[], {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
466
492
|
result: {
|
|
467
|
-
type: () => AsyncResult<T, E>;
|
|
493
|
+
type: () => AsyncResult<T, E, P>;
|
|
468
494
|
required: true;
|
|
469
495
|
};
|
|
470
|
-
}>> & Readonly<{}>, {}, SlotsType<CustomSlots<E> & {
|
|
496
|
+
}>> & Readonly<{}>, {}, SlotsType<CustomSlots<E, P> & {
|
|
471
497
|
default: {
|
|
472
498
|
value: T;
|
|
473
499
|
};
|
package/dist/vue/index.js
CHANGED
|
@@ -66,7 +66,7 @@ function useReactiveChain(source, pipe, options = { immediate: true }) {
|
|
|
66
66
|
return resultRef;
|
|
67
67
|
}
|
|
68
68
|
function useAction(action) {
|
|
69
|
-
return
|
|
69
|
+
return useAsyncResultRef(import_core.AsyncResult.fromAction(action));
|
|
70
70
|
}
|
|
71
71
|
function useLazyAction(action) {
|
|
72
72
|
const lazyAction = import_core.AsyncResult.makeLazyAction(action);
|
|
@@ -132,7 +132,7 @@ function makeAsyncResultLoader(slots, name = "AsyncResultLoader") {
|
|
|
132
132
|
const renderIdle = context.slots.idle ?? slots.idle ?? (() => (0, import_vue2.h)("div", { class: "idle" }, "Idle"));
|
|
133
133
|
switch (s.status) {
|
|
134
134
|
case "loading":
|
|
135
|
-
return renderLoading();
|
|
135
|
+
return renderLoading({ progress: s.progress });
|
|
136
136
|
case "error":
|
|
137
137
|
return renderError({ error: s.error });
|
|
138
138
|
case "success":
|
package/dist/vue/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vue/index.ts","../../src/vue/composables.ts","../../src/vue/components/asyncResultLoader.ts"],"sourcesContent":["export * from \"./composables\"\nexport * from \"./components/asyncResultLoader\"","import { onUnmounted, ref, triggerRef, watch, type Ref, type WatchSource } from \"vue\";\nimport { AsyncResult, AsyncResultCollection, ErrorBase, type Action, type AsyncResultGenerator, type FlatChainStep, type Result } from \"unwrapped/core\";\n\n\n// === Vue specific types ===\n\ninterface ReactiveProcessOptions {\n immediate: boolean;\n}\n\n\n\n// === Vue Composables for AsyncResult ===\n\n/**\n * Makes a ref to the given AsyncResult. Whenever the state of the AsyncResult changes,\n * the ref gets retriggered, making those changes visible to Vue's reactivity system.\n * \n * @param asyncResult the result to make reactive\n * @returns the ref to the result\n */\nexport function useAsyncResultRef<T, E extends ErrorBase = ErrorBase>(asyncResult?: AsyncResult<T, E>) {\n if (!asyncResult) {\n asyncResult = new AsyncResult<T, E>();\n }\n const state = ref<AsyncResult<T, E>>(asyncResult) as Ref<AsyncResult<T, E>>;\n\n const unsub = asyncResult.listen(() => {\n triggerRef(state);\n });\n\n onUnmounted(() => {\n unsub();\n });\n\n return state;\n}\n\n/**\n * Creates an AsyncResult ref from a promise returning a Result.\n * @param promise the promise returning a Result\n * @returns the ref to the AsyncResult\n */\nexport function useAsyncResultRefFromPromise<T, E extends ErrorBase = ErrorBase>(promise: Promise<Result<T, E>>) {\n return useAsyncResultRef(AsyncResult.fromResultPromise(promise));\n}\n\n\n\n// === Vue Composables for Chains ===\n\n/**\n * Watches a source, gives it as inputs to the function provided, and updates the result contained in the ref accordingly.\n * \n * @param source the inputs to react to\n * @param pipe the function to run when the inputs change\n * @param options optional settings\n * @returns ref to the result\n */\nexport function useReactiveChain<Inputs, T, E extends ErrorBase = ErrorBase>(source: WatchSource<Inputs>, pipe: FlatChainStep<Inputs, T, E>, options: ReactiveProcessOptions = { immediate: true }): Ref<AsyncResult<T, E>> {\n const result = new AsyncResult<T, E>();\n const resultRef = useAsyncResultRef(result);\n\n let unsub: (() => void) | null = null;\n\n watch(source, (newInputs) => {\n unsub?.();\n unsub = result.mirror(pipe(newInputs));\n }, { immediate: options.immediate });\n\n onUnmounted(() => {\n unsub?.();\n });\n\n return resultRef;\n}\n\n\n// === Vue Composables for Actions ===\n\n/**\n * The return type of useLazyAction.\n */\nexport interface LazyActionRef<T, E extends ErrorBase = ErrorBase> {\n resultRef: Ref<AsyncResult<T, E>>;\n trigger: () => void;\n}\n\n/**\n * Executes an action immediately and returns a ref to the AsyncResult representing the action's state.\n * \n * Same as useAsyncResultRefFromPromise(action()).\n * \n * @param action the action to execute immediately\n * @returns a ref to the AsyncResult representing the action's state\n */\nexport function useAction<T, E extends ErrorBase = ErrorBase>(action: Action<T, E>): Ref<AsyncResult<T, E>> {\n return useAsyncResultRefFromPromise(action());\n}\n\n/**\n * Creates a lazy action that can be triggered manually.\n * \n * Same as AsyncResult.makeLazyAction(action), but the AsyncResult is wrapped in a ref for Vue reactivity.\n * \n * @param action the action to execute when triggered\n * @returns an object containing a ref to the AsyncResult and a trigger function\n */\nexport function useLazyAction<T, E extends ErrorBase = ErrorBase>(action: Action<T, E>): LazyActionRef<T, E> {\n const lazyAction = AsyncResult.makeLazyAction<T, E>(action);\n const resultRef = useAsyncResultRef(lazyAction.result);\n\n return { resultRef, trigger: lazyAction.trigger };\n}\n\n\n// === Vue Composables for Generators ===\n\n/**\n * Runs a generator function immediately and returns a ref to the AsyncResult representing the generator's state.\n * @param generatorFunc the generator function to run immediately\n * @returns a ref to the AsyncResult representing the generator's state\n */\nexport function useGenerator<T>(generatorFunc: () => AsyncResultGenerator<T>): Ref<AsyncResult<T, any>> {\n const resultRef = useAsyncResultRef(AsyncResult.run(generatorFunc));\n return resultRef;\n}\n\n/**\n * Creates a lazy generator that can be triggered manually.\n * \n * @param generatorFunc the generator function to run when triggered\n * @returns an object containing a ref to the AsyncResult and a trigger function\n */\nexport function useLazyGenerator<T>(generatorFunc: () => AsyncResultGenerator<T>): { resultRef: Ref<AsyncResult<T, any>>, trigger: () => void } {\n const result = new AsyncResult<T, any>();\n const resultRef = useAsyncResultRef(result);\n\n const trigger = () => {\n result.runInPlace(generatorFunc);\n }\n\n return { resultRef, trigger };\n}\n\n/**\n * Watches a source, gives it as inputs to the generator function provided, and updates the result contained in the ref accordingly.\n * \n * @param source the inputs to react to\n * @param generatorFunc the generator function to run when the inputs change\n * @param options optional settings\n * @returns ref to the result\n */\nexport function useReactiveGenerator<Inputs, T, E extends ErrorBase = ErrorBase>(source: WatchSource<Inputs>, generatorFunc: (args: Inputs) => AsyncResultGenerator<T>, options: ReactiveProcessOptions = { immediate: true }): Ref<AsyncResult<T, E>> {\n const resultRef = useAsyncResultRef(new AsyncResult<T, E>());\n\n watch(source, (newInputs) => {\n resultRef.value.runInPlace(() => generatorFunc(newInputs));\n }, { immediate: options.immediate });\n\n return resultRef;\n}\n\n\n// === Vue Composables for AsyncResultCollection ===\n\n/**\n * Creates a reactive AsyncResultCollection wrapped in a Vue ref.\n * The AsyncResultCollection notifies Vue's reactivity system whenever its state changes.\n * \n * @template T - The type of the values in the AsyncResultCollection.\n * @template E - The type of the error, extending ErrorBase (default is ErrorBase).\n * @returns a ref to the AsyncResultCollection\n */\nexport function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBase>() {\n const list = new AsyncResultCollection<T, E>();\n const listRef = ref(list);\n\n list.listen(() => {\n triggerRef(listRef);\n });\n\n return listRef;\n}","import { defineComponent, watch, h, type VNode, type SlotsType } from \"vue\"\nimport { ErrorBase, type AsyncResult } from \"unwrapped/core\"\nimport { useAsyncResultRef } from \"../composables\"\n\ninterface CustomSlots<E extends ErrorBase = ErrorBase> {\n loading?: () => VNode;\n error?: (props: { error: E }) => VNode;\n idle?: () => VNode;\n}\n\n/**\n * Factory function to create a component that displays different content based on an AsyncResult's state. Provides slots for loading, error, idle, and success states and passes the relevant data to each slot, and are typed appropriately.\n * @param slots predefined slots for loading, error, and idle states. Useful for not having to repeat the same template for displaying a framework-specific spinner while in loading state, or a custom error message.\n * @param name Optional internal name for the component\n * @returns An instantiable component that accepts an AsyncResult prop and a default slot for the success state.\n * \n * @example\n * // loaders.ts - Create reusable loader with default loading/error UI\n * const MyLoader = makeAsyncResultLoader({\n * loading: () => h(Spinner),\n * error: ({ error }) => h(ErrorDisplay, { error }),\n * idle: () => h('div', 'Ready')\n * });\n * \n * // MyPage.vue - Use the loader with custom success content\n * <MyLoader :result=\"myAsyncResult\">\n * <template #default=\"{ value }\">\n * <UserProfile :user=\"value\" />\n * </template>\n * </MyLoader>\n */\nexport function makeAsyncResultLoader<T, E extends ErrorBase = ErrorBase>(slots: CustomSlots<E>, name = \"AsyncResultLoader\") {\n return defineComponent({\n name,\n props: {\n result: {\n type: Object as () => AsyncResult<T, E>,\n required: true\n }\n },\n slots: Object as SlotsType<CustomSlots<E> & { default: { value: T } }>,\n setup(props, context) {\n let resultRef = useAsyncResultRef(props.result);\n\n // Watch for prop changes & update listener\n watch(\n () => props.result,\n (newResult, oldResult) => {\n if (newResult === oldResult) return;\n resultRef = useAsyncResultRef(newResult);\n },\n { immediate: true }\n )\n\n return () => {\n const s = resultRef.value.state;\n\n const renderDefault = context.slots.default ?? (() => h(\"div\", { class: \"success\" }, \"Success\"));\n const renderError = context.slots.error ?? slots.error ?? (() => h(\"div\", { class: \"error\" }, \"Error\"));\n const renderLoading = context.slots.loading ?? slots.loading ?? (() => h(\"div\", { class: \"loading\" }, \"Loading…\"));\n const renderIdle = context.slots.idle ?? slots.idle ?? (() => h(\"div\", { class: \"idle\" }, \"Idle\"));\n\n // Choose what to render based on status\n switch (s.status) {\n case \"loading\":\n return renderLoading();\n\n case \"error\":\n return renderError({ error: s.error });\n\n case \"success\":\n return renderDefault({ value: s.value });\n\n default:\n return renderIdle();\n }\n }\n }\n })\n}"],"mapp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Q,GAAG,OAAO;AACrG,cAAM,gBAAgB,QAAQ,MAAM,WAAW,MAAM,YAAY,UAAM,eAAE,OAAO,EAAE,OAAO,UAAU,GAAG,eAAU;AAChH,cAAM,aAAa,QAAQ,MAAM,QAAQ,MAAM,SAAS,UAAM,eAAE,OAAO,EAAE,OAAO,OAAO,GAAG,MAAM;AAGhG,gBAAQ,EAAE,QAAQ;AAAA,UACd,KAAK;AACD,mBAAO,cAAc;AAAA,UAEzB,KAAK;AACD,mBAAO,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC;AAAA,UAEzC,KAAK;AACD,mBAAO,cAAc,EAAE,OAAO,EAAE,MAAM,CAAC;AAAA,UAE3C;AACI,mBAAO,WAAW;AAAA,QAC1B;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ,CAAC;AACL;","names":["import_vue","import_core"]}
|
|
1
|
+
{"version":3,"sources":["../../src/vue/index.ts","../../src/vue/composables.ts","../../src/vue/components/asyncResultLoader.ts"],"sourcesContent":["export * from \"./composables\"\nexport * from \"./components/asyncResultLoader\"","import { onUnmounted, ref, triggerRef, watch, type Ref, type WatchSource } from \"vue\";\nimport { AsyncResult, AsyncResultCollection, ErrorBase, type Action, type AsyncResultGenerator, type FlatChainStep, type Result } from \"unwrapped/core\";\n\n\n// === Vue specific types ===\n\ninterface ReactiveProcessOptions {\n immediate: boolean;\n}\n\n\n\n// === Vue Composables for AsyncResult ===\n\n/**\n * Makes a ref to the given AsyncResult. Whenever the state of the AsyncResult changes,\n * the ref gets retriggered, making those changes visible to Vue's reactivity system.\n * \n * @param asyncResult the result to make reactive\n * @returns the ref to the result\n */\nexport function useAsyncResultRef<T, E extends ErrorBase = ErrorBase, P = unknown>(asyncResult?: AsyncResult<T, E, P>) {\n if (!asyncResult) {\n asyncResult = new AsyncResult<T, E, P>();\n }\n const state = ref<AsyncResult<T, E, P>>(asyncResult) as Ref<AsyncResult<T, E, P>>;\n\n const unsub = asyncResult.listen(() => {\n triggerRef(state);\n });\n\n onUnmounted(() => {\n unsub();\n });\n\n return state;\n}\n\n/**\n * Creates an AsyncResult ref from a promise returning a Result.\n * @param promise the promise returning a Result\n * @returns the ref to the AsyncResult\n */\nexport function useAsyncResultRefFromPromise<T, E extends ErrorBase = ErrorBase>(promise: Promise<Result<T, E>>) {\n return useAsyncResultRef(AsyncResult.fromResultPromise(promise));\n}\n\n\n\n// === Vue Composables for Chains ===\n\n/**\n * Watches a source, gives it as inputs to the function provided, and updates the result contained in the ref accordingly.\n * \n * @param source the inputs to react to\n * @param pipe the function to run when the inputs change\n * @param options optional settings\n * @returns ref to the result\n */\nexport function useReactiveChain<Inputs, T, E extends ErrorBase = ErrorBase>(source: WatchSource<Inputs>, pipe: FlatChainStep<Inputs, T, E>, options: ReactiveProcessOptions = { immediate: true }): Ref<AsyncResult<T, E>> {\n const result = new AsyncResult<T, E>();\n const resultRef = useAsyncResultRef(result);\n\n let unsub: (() => void) | null = null;\n\n watch(source, (newInputs) => {\n unsub?.();\n unsub = result.mirror(pipe(newInputs));\n }, { immediate: options.immediate });\n\n onUnmounted(() => {\n unsub?.();\n });\n\n return resultRef;\n}\n\n\n// === Vue Composables for Actions ===\n\n/**\n * The return type of useLazyAction.\n */\nexport interface LazyActionRef<T, E extends ErrorBase = ErrorBase, P = unknown> {\n resultRef: Ref<AsyncResult<T, E, P>>;\n trigger: () => void;\n}\n\n/**\n * Executes an action immediately and returns a ref to the AsyncResult representing the action's state.\n * \n * Same as useAsyncResultRefFromPromise(action()).\n * \n * @param action the action to execute immediately\n * @returns a ref to the AsyncResult representing the action's state\n */\nexport function useAction<T, E extends ErrorBase = ErrorBase, P = unknown>(action: Action<T, E, P>): Ref<AsyncResult<T, E, P>> {\n return useAsyncResultRef(AsyncResult.fromAction(action));\n}\n\n/**\n * Creates a lazy action that can be triggered manually.\n * \n * Same as AsyncResult.makeLazyAction(action), but the AsyncResult is wrapped in a ref for Vue reactivity.\n * \n * @param action the action to execute when triggered\n * @returns an object containing a ref to the AsyncResult and a trigger function\n */\nexport function useLazyAction<T, E extends ErrorBase = ErrorBase, P = unknown>(action: Action<T, E, P>): LazyActionRef<T, E, P> {\n const lazyAction = AsyncResult.makeLazyAction<T, E, P>(action);\n const resultRef = useAsyncResultRef(lazyAction.result);\n\n return { resultRef, trigger: lazyAction.trigger };\n}\n\n\n// === Vue Composables for Generators ===\n\n/**\n * Runs a generator function immediately and returns a ref to the AsyncResult representing the generator's state.\n * @param generatorFunc the generator function to run immediately\n * @returns a ref to the AsyncResult representing the generator's state\n */\nexport function useGenerator<T, P = unknown>(generatorFunc: (notifyProgress?: (progress: P) => void) => AsyncResultGenerator<T>): Ref<AsyncResult<T, any, P>> {\n const resultRef = useAsyncResultRef(AsyncResult.run(generatorFunc));\n return resultRef;\n}\n\n/**\n * Creates a lazy generator that can be triggered manually.\n * \n * @param generatorFunc the generator function to run when triggered\n * @returns an object containing a ref to the AsyncResult and a trigger function\n */\nexport function useLazyGenerator<T, P = unknown>(generatorFunc: () => AsyncResultGenerator<T>): { resultRef: Ref<AsyncResult<T, any, P>>, trigger: () => void } {\n const result = new AsyncResult<T, any, P>();\n const resultRef = useAsyncResultRef(result);\n\n const trigger = () => {\n result.runInPlace(generatorFunc);\n }\n\n return { resultRef, trigger };\n}\n\n/**\n * Watches a source, gives it as inputs to the generator function provided, and updates the result contained in the ref accordingly.\n * \n * @param source the inputs to react to\n * @param generatorFunc the generator function to run when the inputs change\n * @param options optional settings\n * @returns ref to the result\n */\nexport function useReactiveGenerator<Inputs, T, E extends ErrorBase = ErrorBase, P = unknown>(source: WatchSource<Inputs>, generatorFunc: (args: Inputs) => AsyncResultGenerator<T>, options: ReactiveProcessOptions = { immediate: true }): Ref<AsyncResult<T, E, P>> {\n const resultRef = useAsyncResultRef(new AsyncResult<T, E, P>());\n\n watch(source, (newInputs) => {\n resultRef.value.runInPlace(() => generatorFunc(newInputs));\n }, { immediate: options.immediate });\n\n return resultRef;\n}\n\n\n// === Vue Composables for AsyncResultCollection ===\n\n/**\n * Creates a reactive AsyncResultCollection wrapped in a Vue ref.\n * The AsyncResultCollection notifies Vue's reactivity system whenever its state changes.\n * \n * @template T - The type of the values in the AsyncResultCollection.\n * @template E - The type of the error, extending ErrorBase (default is ErrorBase).\n * @returns a ref to the AsyncResultCollection\n */\nexport function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBase>() {\n const list = new AsyncResultCollection<T, E>();\n const listRef = ref(list);\n\n list.listen(() => {\n triggerRef(listRef);\n });\n\n return listRef;\n}","import { defineComponent, watch, h, type VNode, type SlotsType } from \"vue\"\nimport { ErrorBase, type AsyncResult } from \"unwrapped/core\"\nimport { useAsyncResultRef } from \"../composables\"\n\ninterface CustomSlots<E extends ErrorBase = ErrorBase, P = unknown> {\n loading?: (props: { progress?: P }) => VNode;\n error?: (props: { error: E }) => VNode;\n idle?: () => VNode;\n}\n\n/**\n * Factory function to create a component that displays different content based on an AsyncResult's state. Provides slots for loading, error, idle, and success states and passes the relevant data to each slot, and are typed appropriately.\n * @param slots predefined slots for loading, error, and idle states. Useful for not having to repeat the same template for displaying a framework-specific spinner while in loading state, or a custom error message.\n * @param name Optional internal name for the component\n * @returns An instantiable component that accepts an AsyncResult prop and a default slot for the success state.\n * \n * @example\n * // loaders.ts - Create reusable loader with default loading/error UI\n * const MyLoader = makeAsyncResultLoader({\n * loading: () => h(Spinner),\n * error: ({ error }) => h(ErrorDisplay, { error }),\n * idle: () => h('div', 'Ready')\n * });\n * \n * // MyPage.vue - Use the loader with custom success content\n * <MyLoader :result=\"myAsyncResult\">\n * <template #default=\"{ value }\">\n * <UserProfile :user=\"value\" />\n * </template>\n * </MyLoader>\n */\nexport function makeAsyncResultLoader<T, E extends ErrorBase = ErrorBase, P = unknown>(slots: CustomSlots<E, P>, name = \"AsyncResultLoader\") {\n return defineComponent({\n name,\n props: {\n result: {\n type: Object as () => AsyncResult<T, E, P>,\n required: true\n }\n },\n slots: Object as SlotsType<CustomSlots<E, P> & { default: { value: T } }>,\n setup(props, context) {\n let resultRef = useAsyncResultRef(props.result);\n\n // Watch for prop changes & update listener\n watch(\n () => props.result,\n (newResult, oldResult) => {\n if (newResult === oldResult) return;\n resultRef = useAsyncResultRef(newResult);\n },\n { immediate: true }\n )\n\n return () => {\n const s = resultRef.value.state;\n\n const renderDefault = context.slots.default ?? (() => h(\"div\", { class: \"success\" }, \"Success\"));\n const renderError = context.slots.error ?? slots.error ?? (() => h(\"div\", { class: \"error\" }, \"Error\"));\n const renderLoading = context.slots.loading ?? slots.loading ?? (() => h(\"div\", { class: \"loading\" }, \"Loading…\"));\n const renderIdle = context.slots.idle ?? slots.idle ?? (() => h(\"div\", { class: \"idle\" }, \"Idle\"));\n\n // Choose what to render based on status\n switch (s.status) {\n case \"loading\":\n return renderLoading({ progress: s.progress });\n\n case \"error\":\n return renderError({ error: s.error });\n\n case \"success\":\n return renderDefault({ value: s.value });\n\n default:\n return renderIdle();\n }\n }\n }\n })\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAgF;AAChF,kBAAuI;AAoBhI,SAAS,kBAAmE,aAAoC;AACnH,MAAI,CAAC,aAAa;AACd,kBAAc,IAAI,wBAAqB;AAAA,EAC3C;AACA,QAAM,YAAQ,gBAA0B,WAAW;AAEnD,QAAM,QAAQ,YAAY,OAAO,MAAM;AACnC,+BAAW,KAAK;AAAA,EACpB,CAAC;AAED,8BAAY,MAAM;AACd,UAAM;AAAA,EACV,CAAC;AAED,SAAO;AACX;AAOO,SAAS,6BAAiE,SAAgC;AAC7G,SAAO,kBAAkB,wBAAY,kBAAkB,OAAO,CAAC;AACnE;AAcO,SAAS,iBAA6D,QAA6B,MAAmC,UAAkC,EAAE,WAAW,KAAK,GAA2B;AACxN,QAAM,SAAS,IAAI,wBAAkB;AACrC,QAAM,YAAY,kBAAkB,MAAM;AAE1C,MAAI,QAA6B;AAEjC,wBAAM,Q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
|
|
31
31
|
return resultRef;
|
|
32
32
|
}
|
|
33
33
|
function useAction(action) {
|
|
34
|
-
return
|
|
34
|
+
return useAsyncResultRef(AsyncResult.fromAction(action));
|
|
35
35
|
}
|
|
36
36
|
function useLazyAction(action) {
|
|
37
37
|
const lazyAction = AsyncResult.makeLazyAction(action);
|
|
@@ -97,7 +97,7 @@ function makeAsyncResultLoader(slots, name = "AsyncResultLoader") {
|
|
|
97
97
|
const renderIdle = context.slots.idle ?? slots.idle ?? (() => h("div", { class: "idle" }, "Idle"));
|
|
98
98
|
switch (s.status) {
|
|
99
99
|
case "loading":
|
|
100
|
-
return renderLoading();
|
|
100
|
+
return renderLoading({ progress: s.progress });
|
|
101
101
|
case "error":
|
|
102
102
|
return renderError({ error: s.error });
|
|
103
103
|
case "success":
|