unwrapped 0.1.6 → 0.1.7
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 +7 -0
- package/dist/core/index.d.mts +8 -2
- package/dist/core/index.d.ts +8 -2
- package/dist/core/index.js +19 -13
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +19 -13
- package/dist/core/index.mjs.map +1 -1
- package/dist/vue/index.d.mts +121 -126
- package/dist/vue/index.d.ts +121 -126
- package/dist/vue/index.js +30 -50
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +30 -50
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/vue/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as unwrapped_core from 'unwrapped/core';
|
|
2
2
|
import { ErrorBase, AsyncResult, Result, FlatChainStep, Action, AsyncResultGenerator, AsyncResultList } from 'unwrapped/core';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
|
-
import { Ref, WatchSource, VNode } from 'vue';
|
|
4
|
+
import { Ref, WatchSource, VNode, SlotsType } from 'vue';
|
|
5
5
|
|
|
6
6
|
interface ReactiveProcessOptions {
|
|
7
7
|
immediate: boolean;
|
|
@@ -89,49 +89,53 @@ declare function useReactiveGenerator<Inputs, T, E extends ErrorBase = ErrorBase
|
|
|
89
89
|
*/
|
|
90
90
|
declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>(): Ref<{
|
|
91
91
|
readonly tasks: Map<string, {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
key: string;
|
|
93
|
+
result: {
|
|
94
|
+
state: {
|
|
95
|
+
status: "idle";
|
|
96
|
+
} | {
|
|
97
|
+
status: "loading";
|
|
98
|
+
promise: {
|
|
99
|
+
then: <TResult1 = Result<T, E>, TResult2 = never>(onfulfilled?: ((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
|
|
100
|
+
catch: <TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined) => Promise<Result<T, E> | TResult>;
|
|
101
|
+
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
102
|
+
readonly [Symbol.toStringTag]: string;
|
|
103
|
+
};
|
|
104
|
+
} | {
|
|
105
|
+
status: "success";
|
|
106
|
+
value: vue.UnwrapRef<T>;
|
|
107
|
+
} | {
|
|
108
|
+
status: "error";
|
|
109
|
+
error: vue.UnwrapRef<E>;
|
|
101
110
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
isSuccess: () => boolean;
|
|
112
|
+
isError: () => boolean;
|
|
113
|
+
isIdle: () => boolean;
|
|
114
|
+
isLoading: () => boolean;
|
|
115
|
+
unwrapOrNull: () => T | null;
|
|
116
|
+
unwrapOrThrow: () => T;
|
|
117
|
+
unwrapErrorOrNull: () => E | null;
|
|
118
|
+
updateFromValue: (value: T) => AsyncResult<T, E>;
|
|
119
|
+
updateFromError: (error: E) => AsyncResult<T, E>;
|
|
120
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E>;
|
|
121
|
+
waitForSettled: () => Promise<AsyncResult<T, E>>;
|
|
122
|
+
toResultPromise: () => Promise<Result<T, E>>;
|
|
123
|
+
toValueOrThrowPromise: () => Promise<T>;
|
|
124
|
+
toValueOrNullPromise: () => Promise<T | null>;
|
|
125
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
126
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
127
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
128
|
+
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
129
|
+
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
130
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
131
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
132
|
+
runInPlace: (generatorFunc: () => AsyncResultGenerator<T>) => AsyncResult<T, E>;
|
|
133
|
+
log: (name?: string) => void;
|
|
134
|
+
debug: (name?: string) => () => void;
|
|
135
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
108
136
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
isIdle: () => boolean;
|
|
112
|
-
isLoading: () => boolean;
|
|
113
|
-
unwrapOrNull: () => T | null;
|
|
114
|
-
unwrapOrThrow: () => T;
|
|
115
|
-
unwrapErrorOrNull: () => E | null;
|
|
116
|
-
updateFromValue: (value: T) => AsyncResult<T, E>;
|
|
117
|
-
updateFromError: (error: E) => AsyncResult<T, E>;
|
|
118
|
-
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E>;
|
|
119
|
-
waitForSettled: () => Promise<AsyncResult<T, E>>;
|
|
120
|
-
toResultPromise: () => Promise<Result<T, E>>;
|
|
121
|
-
toValueOrThrowPromise: () => Promise<T>;
|
|
122
|
-
toValueOrNullPromise: () => Promise<T | null>;
|
|
123
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
124
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
125
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
126
|
-
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
127
|
-
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
128
|
-
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
129
|
-
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
130
|
-
runInPlace: (generatorFunc: () => AsyncResultGenerator<T>) => AsyncResult<T, E>;
|
|
131
|
-
log: (name?: string) => void;
|
|
132
|
-
debug: (name?: string) => () => void;
|
|
133
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
134
|
-
}> & Omit<Map<string, AsyncResult<T, E>>, keyof Map<any, any>>;
|
|
137
|
+
unsub: () => void;
|
|
138
|
+
}> & Omit<Map<string, unwrapped_core.AsyncResultListItem<T, E>>, keyof Map<any, any>>;
|
|
135
139
|
readonly length: number;
|
|
136
140
|
readonly items: {
|
|
137
141
|
state: {
|
|
@@ -180,6 +184,7 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
180
184
|
state: unwrapped_core.AsyncResultListState;
|
|
181
185
|
listen: (listener: (taskQueue: AsyncResultList<T, E>) => void) => () => void;
|
|
182
186
|
add: (key: string, task: AsyncResult<T, E>, removeOnSettle?: boolean) => AsyncResult<T, E>;
|
|
187
|
+
clear: () => void;
|
|
183
188
|
anyLoading: () => boolean;
|
|
184
189
|
getAllFiltered: (predicate: (task: AsyncResult<T, E>) => boolean) => AsyncResult<T, E>[];
|
|
185
190
|
getAllFilteredAndMap: <U>(filterPredicate: (task: AsyncResult<T, E>) => boolean, mapFunc: (task: AsyncResult<T, E>) => U) => U[];
|
|
@@ -193,49 +198,53 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
193
198
|
debug: (name?: string) => () => void;
|
|
194
199
|
}, AsyncResultList<T, E> | {
|
|
195
200
|
readonly tasks: Map<string, {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
key: string;
|
|
202
|
+
result: {
|
|
203
|
+
state: {
|
|
204
|
+
status: "idle";
|
|
205
|
+
} | {
|
|
206
|
+
status: "loading";
|
|
207
|
+
promise: {
|
|
208
|
+
then: <TResult1 = Result<T, E>, TResult2 = never>(onfulfilled?: ((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
|
|
209
|
+
catch: <TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined) => Promise<Result<T, E> | TResult>;
|
|
210
|
+
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
211
|
+
readonly [Symbol.toStringTag]: string;
|
|
212
|
+
};
|
|
213
|
+
} | {
|
|
214
|
+
status: "success";
|
|
215
|
+
value: vue.UnwrapRef<T>;
|
|
216
|
+
} | {
|
|
217
|
+
status: "error";
|
|
218
|
+
error: vue.UnwrapRef<E>;
|
|
205
219
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
220
|
+
isSuccess: () => boolean;
|
|
221
|
+
isError: () => boolean;
|
|
222
|
+
isIdle: () => boolean;
|
|
223
|
+
isLoading: () => boolean;
|
|
224
|
+
unwrapOrNull: () => T | null;
|
|
225
|
+
unwrapOrThrow: () => T;
|
|
226
|
+
unwrapErrorOrNull: () => E | null;
|
|
227
|
+
updateFromValue: (value: T) => AsyncResult<T, E>;
|
|
228
|
+
updateFromError: (error: E) => AsyncResult<T, E>;
|
|
229
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E>;
|
|
230
|
+
waitForSettled: () => Promise<AsyncResult<T, E>>;
|
|
231
|
+
toResultPromise: () => Promise<Result<T, E>>;
|
|
232
|
+
toValueOrThrowPromise: () => Promise<T>;
|
|
233
|
+
toValueOrNullPromise: () => Promise<T | null>;
|
|
234
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
235
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
236
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
237
|
+
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
238
|
+
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
239
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
240
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
241
|
+
runInPlace: (generatorFunc: () => AsyncResultGenerator<T>) => AsyncResult<T, E>;
|
|
242
|
+
log: (name?: string) => void;
|
|
243
|
+
debug: (name?: string) => () => void;
|
|
244
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
212
245
|
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
isIdle: () => boolean;
|
|
216
|
-
isLoading: () => boolean;
|
|
217
|
-
unwrapOrNull: () => T | null;
|
|
218
|
-
unwrapOrThrow: () => T;
|
|
219
|
-
unwrapErrorOrNull: () => E | null;
|
|
220
|
-
updateFromValue: (value: T) => AsyncResult<T, E>;
|
|
221
|
-
updateFromError: (error: E) => AsyncResult<T, E>;
|
|
222
|
-
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E>;
|
|
223
|
-
waitForSettled: () => Promise<AsyncResult<T, E>>;
|
|
224
|
-
toResultPromise: () => Promise<Result<T, E>>;
|
|
225
|
-
toValueOrThrowPromise: () => Promise<T>;
|
|
226
|
-
toValueOrNullPromise: () => Promise<T | null>;
|
|
227
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
228
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
229
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
230
|
-
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
231
|
-
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
232
|
-
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
233
|
-
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
234
|
-
runInPlace: (generatorFunc: () => AsyncResultGenerator<T>) => AsyncResult<T, E>;
|
|
235
|
-
log: (name?: string) => void;
|
|
236
|
-
debug: (name?: string) => () => void;
|
|
237
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
238
|
-
}> & Omit<Map<string, AsyncResult<T, E>>, keyof Map<any, any>>;
|
|
246
|
+
unsub: () => void;
|
|
247
|
+
}> & Omit<Map<string, unwrapped_core.AsyncResultListItem<T, E>>, keyof Map<any, any>>;
|
|
239
248
|
readonly length: number;
|
|
240
249
|
readonly items: {
|
|
241
250
|
state: {
|
|
@@ -284,6 +293,7 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
284
293
|
state: unwrapped_core.AsyncResultListState;
|
|
285
294
|
listen: (listener: (taskQueue: AsyncResultList<T, E>) => void) => () => void;
|
|
286
295
|
add: (key: string, task: AsyncResult<T, E>, removeOnSettle?: boolean) => AsyncResult<T, E>;
|
|
296
|
+
clear: () => void;
|
|
287
297
|
anyLoading: () => boolean;
|
|
288
298
|
getAllFiltered: (predicate: (task: AsyncResult<T, E>) => boolean) => AsyncResult<T, E>[];
|
|
289
299
|
getAllFilteredAndMap: <U>(filterPredicate: (task: AsyncResult<T, E>) => boolean, mapFunc: (task: AsyncResult<T, E>) => U) => U[];
|
|
@@ -297,67 +307,52 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
297
307
|
debug: (name?: string) => () => void;
|
|
298
308
|
}>;
|
|
299
309
|
|
|
300
|
-
/**
|
|
301
|
-
* A Vue component that displays different content based on the state of an AsyncResult.
|
|
302
|
-
* It supports slots for 'loading', 'error', 'success' (default), and 'idle' states.
|
|
303
|
-
*
|
|
304
|
-
* @example
|
|
305
|
-
* <AsyncResultLoader :result="myAsyncResult">
|
|
306
|
-
* <template #loading>
|
|
307
|
-
* <div>Loading data...</div>
|
|
308
|
-
* </template>
|
|
309
|
-
* <template #error="{ error }">
|
|
310
|
-
* <div>Error occurred: {{ error.message }}</div>
|
|
311
|
-
* </template>
|
|
312
|
-
* <template #default="{ value }">
|
|
313
|
-
* <div>Data loaded: {{ value }}</div>
|
|
314
|
-
* </template>
|
|
315
|
-
* <template #idle>
|
|
316
|
-
* <div>Waiting to start...</div>
|
|
317
|
-
* </template>
|
|
318
|
-
* </AsyncResultLoader>
|
|
319
|
-
*/
|
|
320
|
-
declare const AsyncResultLoader: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
321
|
-
result: {
|
|
322
|
-
type: () => AsyncResult<unknown>;
|
|
323
|
-
required: true;
|
|
324
|
-
};
|
|
325
|
-
}>, () => VNode<vue.RendererNode, vue.RendererElement, {
|
|
326
|
-
[key: string]: any;
|
|
327
|
-
}> | VNode<vue.RendererNode, vue.RendererElement, {
|
|
328
|
-
[key: string]: any;
|
|
329
|
-
}>[] | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
330
|
-
result: {
|
|
331
|
-
type: () => AsyncResult<unknown>;
|
|
332
|
-
required: true;
|
|
333
|
-
};
|
|
334
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
335
310
|
interface CustomSlots<E extends ErrorBase = ErrorBase> {
|
|
336
311
|
loading?: () => VNode;
|
|
337
312
|
error?: (props: {
|
|
338
313
|
error: E;
|
|
339
314
|
}) => VNode;
|
|
315
|
+
idle?: () => VNode;
|
|
340
316
|
}
|
|
341
317
|
/**
|
|
342
|
-
*
|
|
318
|
+
* 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.
|
|
319
|
+
* @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.
|
|
320
|
+
* @param name Optional internal name for the component
|
|
321
|
+
* @returns An instantiable component that accepts an AsyncResult prop and a default slot for the success state.
|
|
343
322
|
*
|
|
344
|
-
*
|
|
323
|
+
* @example
|
|
324
|
+
* // loaders.ts - Create reusable loader with default loading/error UI
|
|
325
|
+
* const MyLoader = makeAsyncResultLoader({
|
|
326
|
+
* loading: () => h(Spinner),
|
|
327
|
+
* error: ({ error }) => h(ErrorDisplay, { error }),
|
|
328
|
+
* idle: () => h('div', 'Ready')
|
|
329
|
+
* });
|
|
345
330
|
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
331
|
+
* // MyPage.vue - Use the loader with custom success content
|
|
332
|
+
* <MyLoader :result="myAsyncResult">
|
|
333
|
+
* <template #default="{ value }">
|
|
334
|
+
* <UserProfile :user="value" />
|
|
335
|
+
* </template>
|
|
336
|
+
* </MyLoader>
|
|
348
337
|
*/
|
|
349
|
-
declare function
|
|
338
|
+
declare function makeAsyncResultLoader<T, E extends ErrorBase = ErrorBase>(slots: CustomSlots<E>, name?: string): vue.DefineComponent<vue.ExtractPropTypes<{
|
|
350
339
|
result: {
|
|
351
340
|
type: () => AsyncResult<T, E>;
|
|
352
341
|
required: true;
|
|
353
342
|
};
|
|
354
343
|
}>, () => VNode<vue.RendererNode, vue.RendererElement, {
|
|
355
344
|
[key: string]: any;
|
|
356
|
-
}
|
|
345
|
+
}> | VNode<vue.RendererNode, vue.RendererElement, {
|
|
346
|
+
[key: string]: any;
|
|
347
|
+
}>[], {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
357
348
|
result: {
|
|
358
349
|
type: () => AsyncResult<T, E>;
|
|
359
350
|
required: true;
|
|
360
351
|
};
|
|
361
|
-
}>> & Readonly<{}>, {},
|
|
352
|
+
}>> & Readonly<{}>, {}, SlotsType<CustomSlots<E> & {
|
|
353
|
+
default: {
|
|
354
|
+
value: T;
|
|
355
|
+
};
|
|
356
|
+
}>, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
362
357
|
|
|
363
|
-
export {
|
|
358
|
+
export { type LazyActionRef, makeAsyncResultLoader, useAction, useAsyncResultList, useAsyncResultRef, useAsyncResultRefFromPromise, useGenerator, useLazyAction, useLazyGenerator, useReactiveChain, useReactiveGenerator };
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as unwrapped_core from 'unwrapped/core';
|
|
2
2
|
import { ErrorBase, AsyncResult, Result, FlatChainStep, Action, AsyncResultGenerator, AsyncResultList } from 'unwrapped/core';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
|
-
import { Ref, WatchSource, VNode } from 'vue';
|
|
4
|
+
import { Ref, WatchSource, VNode, SlotsType } from 'vue';
|
|
5
5
|
|
|
6
6
|
interface ReactiveProcessOptions {
|
|
7
7
|
immediate: boolean;
|
|
@@ -89,49 +89,53 @@ declare function useReactiveGenerator<Inputs, T, E extends ErrorBase = ErrorBase
|
|
|
89
89
|
*/
|
|
90
90
|
declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>(): Ref<{
|
|
91
91
|
readonly tasks: Map<string, {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
key: string;
|
|
93
|
+
result: {
|
|
94
|
+
state: {
|
|
95
|
+
status: "idle";
|
|
96
|
+
} | {
|
|
97
|
+
status: "loading";
|
|
98
|
+
promise: {
|
|
99
|
+
then: <TResult1 = Result<T, E>, TResult2 = never>(onfulfilled?: ((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
|
|
100
|
+
catch: <TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined) => Promise<Result<T, E> | TResult>;
|
|
101
|
+
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
102
|
+
readonly [Symbol.toStringTag]: string;
|
|
103
|
+
};
|
|
104
|
+
} | {
|
|
105
|
+
status: "success";
|
|
106
|
+
value: vue.UnwrapRef<T>;
|
|
107
|
+
} | {
|
|
108
|
+
status: "error";
|
|
109
|
+
error: vue.UnwrapRef<E>;
|
|
101
110
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
isSuccess: () => boolean;
|
|
112
|
+
isError: () => boolean;
|
|
113
|
+
isIdle: () => boolean;
|
|
114
|
+
isLoading: () => boolean;
|
|
115
|
+
unwrapOrNull: () => T | null;
|
|
116
|
+
unwrapOrThrow: () => T;
|
|
117
|
+
unwrapErrorOrNull: () => E | null;
|
|
118
|
+
updateFromValue: (value: T) => AsyncResult<T, E>;
|
|
119
|
+
updateFromError: (error: E) => AsyncResult<T, E>;
|
|
120
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E>;
|
|
121
|
+
waitForSettled: () => Promise<AsyncResult<T, E>>;
|
|
122
|
+
toResultPromise: () => Promise<Result<T, E>>;
|
|
123
|
+
toValueOrThrowPromise: () => Promise<T>;
|
|
124
|
+
toValueOrNullPromise: () => Promise<T | null>;
|
|
125
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
126
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
127
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
128
|
+
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
129
|
+
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
130
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
131
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
132
|
+
runInPlace: (generatorFunc: () => AsyncResultGenerator<T>) => AsyncResult<T, E>;
|
|
133
|
+
log: (name?: string) => void;
|
|
134
|
+
debug: (name?: string) => () => void;
|
|
135
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
108
136
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
isIdle: () => boolean;
|
|
112
|
-
isLoading: () => boolean;
|
|
113
|
-
unwrapOrNull: () => T | null;
|
|
114
|
-
unwrapOrThrow: () => T;
|
|
115
|
-
unwrapErrorOrNull: () => E | null;
|
|
116
|
-
updateFromValue: (value: T) => AsyncResult<T, E>;
|
|
117
|
-
updateFromError: (error: E) => AsyncResult<T, E>;
|
|
118
|
-
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E>;
|
|
119
|
-
waitForSettled: () => Promise<AsyncResult<T, E>>;
|
|
120
|
-
toResultPromise: () => Promise<Result<T, E>>;
|
|
121
|
-
toValueOrThrowPromise: () => Promise<T>;
|
|
122
|
-
toValueOrNullPromise: () => Promise<T | null>;
|
|
123
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
124
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
125
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
126
|
-
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
127
|
-
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
128
|
-
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
129
|
-
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
130
|
-
runInPlace: (generatorFunc: () => AsyncResultGenerator<T>) => AsyncResult<T, E>;
|
|
131
|
-
log: (name?: string) => void;
|
|
132
|
-
debug: (name?: string) => () => void;
|
|
133
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
134
|
-
}> & Omit<Map<string, AsyncResult<T, E>>, keyof Map<any, any>>;
|
|
137
|
+
unsub: () => void;
|
|
138
|
+
}> & Omit<Map<string, unwrapped_core.AsyncResultListItem<T, E>>, keyof Map<any, any>>;
|
|
135
139
|
readonly length: number;
|
|
136
140
|
readonly items: {
|
|
137
141
|
state: {
|
|
@@ -180,6 +184,7 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
180
184
|
state: unwrapped_core.AsyncResultListState;
|
|
181
185
|
listen: (listener: (taskQueue: AsyncResultList<T, E>) => void) => () => void;
|
|
182
186
|
add: (key: string, task: AsyncResult<T, E>, removeOnSettle?: boolean) => AsyncResult<T, E>;
|
|
187
|
+
clear: () => void;
|
|
183
188
|
anyLoading: () => boolean;
|
|
184
189
|
getAllFiltered: (predicate: (task: AsyncResult<T, E>) => boolean) => AsyncResult<T, E>[];
|
|
185
190
|
getAllFilteredAndMap: <U>(filterPredicate: (task: AsyncResult<T, E>) => boolean, mapFunc: (task: AsyncResult<T, E>) => U) => U[];
|
|
@@ -193,49 +198,53 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
193
198
|
debug: (name?: string) => () => void;
|
|
194
199
|
}, AsyncResultList<T, E> | {
|
|
195
200
|
readonly tasks: Map<string, {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
key: string;
|
|
202
|
+
result: {
|
|
203
|
+
state: {
|
|
204
|
+
status: "idle";
|
|
205
|
+
} | {
|
|
206
|
+
status: "loading";
|
|
207
|
+
promise: {
|
|
208
|
+
then: <TResult1 = Result<T, E>, TResult2 = never>(onfulfilled?: ((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<TResult1 | TResult2>;
|
|
209
|
+
catch: <TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined) => Promise<Result<T, E> | TResult>;
|
|
210
|
+
finally: (onfinally?: (() => void) | null | undefined) => Promise<Result<T, E>>;
|
|
211
|
+
readonly [Symbol.toStringTag]: string;
|
|
212
|
+
};
|
|
213
|
+
} | {
|
|
214
|
+
status: "success";
|
|
215
|
+
value: vue.UnwrapRef<T>;
|
|
216
|
+
} | {
|
|
217
|
+
status: "error";
|
|
218
|
+
error: vue.UnwrapRef<E>;
|
|
205
219
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
220
|
+
isSuccess: () => boolean;
|
|
221
|
+
isError: () => boolean;
|
|
222
|
+
isIdle: () => boolean;
|
|
223
|
+
isLoading: () => boolean;
|
|
224
|
+
unwrapOrNull: () => T | null;
|
|
225
|
+
unwrapOrThrow: () => T;
|
|
226
|
+
unwrapErrorOrNull: () => E | null;
|
|
227
|
+
updateFromValue: (value: T) => AsyncResult<T, E>;
|
|
228
|
+
updateFromError: (error: E) => AsyncResult<T, E>;
|
|
229
|
+
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E>;
|
|
230
|
+
waitForSettled: () => Promise<AsyncResult<T, E>>;
|
|
231
|
+
toResultPromise: () => Promise<Result<T, E>>;
|
|
232
|
+
toValueOrThrowPromise: () => Promise<T>;
|
|
233
|
+
toValueOrNullPromise: () => Promise<T | null>;
|
|
234
|
+
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
235
|
+
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
236
|
+
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
237
|
+
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
238
|
+
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
239
|
+
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
240
|
+
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
241
|
+
runInPlace: (generatorFunc: () => AsyncResultGenerator<T>) => AsyncResult<T, E>;
|
|
242
|
+
log: (name?: string) => void;
|
|
243
|
+
debug: (name?: string) => () => void;
|
|
244
|
+
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
212
245
|
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
isIdle: () => boolean;
|
|
216
|
-
isLoading: () => boolean;
|
|
217
|
-
unwrapOrNull: () => T | null;
|
|
218
|
-
unwrapOrThrow: () => T;
|
|
219
|
-
unwrapErrorOrNull: () => E | null;
|
|
220
|
-
updateFromValue: (value: T) => AsyncResult<T, E>;
|
|
221
|
-
updateFromError: (error: E) => AsyncResult<T, E>;
|
|
222
|
-
updateFromValuePromise: (promise: Promise<T>) => AsyncResult<T, E>;
|
|
223
|
-
waitForSettled: () => Promise<AsyncResult<T, E>>;
|
|
224
|
-
toResultPromise: () => Promise<Result<T, E>>;
|
|
225
|
-
toValueOrThrowPromise: () => Promise<T>;
|
|
226
|
-
toValueOrNullPromise: () => Promise<T | null>;
|
|
227
|
-
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
228
|
-
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
229
|
-
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
230
|
-
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
231
|
-
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
232
|
-
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
233
|
-
flatChain: <O, E2 extends ErrorBase = ErrorBase>(fn: FlatChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
234
|
-
runInPlace: (generatorFunc: () => AsyncResultGenerator<T>) => AsyncResult<T, E>;
|
|
235
|
-
log: (name?: string) => void;
|
|
236
|
-
debug: (name?: string) => () => void;
|
|
237
|
-
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
238
|
-
}> & Omit<Map<string, AsyncResult<T, E>>, keyof Map<any, any>>;
|
|
246
|
+
unsub: () => void;
|
|
247
|
+
}> & Omit<Map<string, unwrapped_core.AsyncResultListItem<T, E>>, keyof Map<any, any>>;
|
|
239
248
|
readonly length: number;
|
|
240
249
|
readonly items: {
|
|
241
250
|
state: {
|
|
@@ -284,6 +293,7 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
284
293
|
state: unwrapped_core.AsyncResultListState;
|
|
285
294
|
listen: (listener: (taskQueue: AsyncResultList<T, E>) => void) => () => void;
|
|
286
295
|
add: (key: string, task: AsyncResult<T, E>, removeOnSettle?: boolean) => AsyncResult<T, E>;
|
|
296
|
+
clear: () => void;
|
|
287
297
|
anyLoading: () => boolean;
|
|
288
298
|
getAllFiltered: (predicate: (task: AsyncResult<T, E>) => boolean) => AsyncResult<T, E>[];
|
|
289
299
|
getAllFilteredAndMap: <U>(filterPredicate: (task: AsyncResult<T, E>) => boolean, mapFunc: (task: AsyncResult<T, E>) => U) => U[];
|
|
@@ -297,67 +307,52 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
297
307
|
debug: (name?: string) => () => void;
|
|
298
308
|
}>;
|
|
299
309
|
|
|
300
|
-
/**
|
|
301
|
-
* A Vue component that displays different content based on the state of an AsyncResult.
|
|
302
|
-
* It supports slots for 'loading', 'error', 'success' (default), and 'idle' states.
|
|
303
|
-
*
|
|
304
|
-
* @example
|
|
305
|
-
* <AsyncResultLoader :result="myAsyncResult">
|
|
306
|
-
* <template #loading>
|
|
307
|
-
* <div>Loading data...</div>
|
|
308
|
-
* </template>
|
|
309
|
-
* <template #error="{ error }">
|
|
310
|
-
* <div>Error occurred: {{ error.message }}</div>
|
|
311
|
-
* </template>
|
|
312
|
-
* <template #default="{ value }">
|
|
313
|
-
* <div>Data loaded: {{ value }}</div>
|
|
314
|
-
* </template>
|
|
315
|
-
* <template #idle>
|
|
316
|
-
* <div>Waiting to start...</div>
|
|
317
|
-
* </template>
|
|
318
|
-
* </AsyncResultLoader>
|
|
319
|
-
*/
|
|
320
|
-
declare const AsyncResultLoader: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
321
|
-
result: {
|
|
322
|
-
type: () => AsyncResult<unknown>;
|
|
323
|
-
required: true;
|
|
324
|
-
};
|
|
325
|
-
}>, () => VNode<vue.RendererNode, vue.RendererElement, {
|
|
326
|
-
[key: string]: any;
|
|
327
|
-
}> | VNode<vue.RendererNode, vue.RendererElement, {
|
|
328
|
-
[key: string]: any;
|
|
329
|
-
}>[] | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
330
|
-
result: {
|
|
331
|
-
type: () => AsyncResult<unknown>;
|
|
332
|
-
required: true;
|
|
333
|
-
};
|
|
334
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
335
310
|
interface CustomSlots<E extends ErrorBase = ErrorBase> {
|
|
336
311
|
loading?: () => VNode;
|
|
337
312
|
error?: (props: {
|
|
338
313
|
error: E;
|
|
339
314
|
}) => VNode;
|
|
315
|
+
idle?: () => VNode;
|
|
340
316
|
}
|
|
341
317
|
/**
|
|
342
|
-
*
|
|
318
|
+
* 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.
|
|
319
|
+
* @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.
|
|
320
|
+
* @param name Optional internal name for the component
|
|
321
|
+
* @returns An instantiable component that accepts an AsyncResult prop and a default slot for the success state.
|
|
343
322
|
*
|
|
344
|
-
*
|
|
323
|
+
* @example
|
|
324
|
+
* // loaders.ts - Create reusable loader with default loading/error UI
|
|
325
|
+
* const MyLoader = makeAsyncResultLoader({
|
|
326
|
+
* loading: () => h(Spinner),
|
|
327
|
+
* error: ({ error }) => h(ErrorDisplay, { error }),
|
|
328
|
+
* idle: () => h('div', 'Ready')
|
|
329
|
+
* });
|
|
345
330
|
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
331
|
+
* // MyPage.vue - Use the loader with custom success content
|
|
332
|
+
* <MyLoader :result="myAsyncResult">
|
|
333
|
+
* <template #default="{ value }">
|
|
334
|
+
* <UserProfile :user="value" />
|
|
335
|
+
* </template>
|
|
336
|
+
* </MyLoader>
|
|
348
337
|
*/
|
|
349
|
-
declare function
|
|
338
|
+
declare function makeAsyncResultLoader<T, E extends ErrorBase = ErrorBase>(slots: CustomSlots<E>, name?: string): vue.DefineComponent<vue.ExtractPropTypes<{
|
|
350
339
|
result: {
|
|
351
340
|
type: () => AsyncResult<T, E>;
|
|
352
341
|
required: true;
|
|
353
342
|
};
|
|
354
343
|
}>, () => VNode<vue.RendererNode, vue.RendererElement, {
|
|
355
344
|
[key: string]: any;
|
|
356
|
-
}
|
|
345
|
+
}> | VNode<vue.RendererNode, vue.RendererElement, {
|
|
346
|
+
[key: string]: any;
|
|
347
|
+
}>[], {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
357
348
|
result: {
|
|
358
349
|
type: () => AsyncResult<T, E>;
|
|
359
350
|
required: true;
|
|
360
351
|
};
|
|
361
|
-
}>> & Readonly<{}>, {},
|
|
352
|
+
}>> & Readonly<{}>, {}, SlotsType<CustomSlots<E> & {
|
|
353
|
+
default: {
|
|
354
|
+
value: T;
|
|
355
|
+
};
|
|
356
|
+
}>, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
362
357
|
|
|
363
|
-
export {
|
|
358
|
+
export { type LazyActionRef, makeAsyncResultLoader, useAction, useAsyncResultList, useAsyncResultRef, useAsyncResultRefFromPromise, useGenerator, useLazyAction, useLazyGenerator, useReactiveChain, useReactiveGenerator };
|