unwrapped 0.1.8 → 0.1.9
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 +6 -0
- package/dist/core/index.d.mts +68 -8
- package/dist/core/index.d.ts +68 -8
- package/dist/core/index.js +80 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +79 -3
- package/dist/core/index.mjs.map +1 -1
- package/dist/vue/index.d.mts +42 -14
- package/dist/vue/index.d.ts +42 -14
- package/dist/vue/index.js +3 -3
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +4 -4
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/vue/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as unwrapped_core from 'unwrapped/core';
|
|
2
|
-
import { ErrorBase, AsyncResult, Result, FlatChainStep, Action, AsyncResultGenerator,
|
|
2
|
+
import { ErrorBase, AsyncResult, Result, FlatChainStep, Action, AsyncResultGenerator, AsyncResultCollection } from 'unwrapped/core';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
4
|
import { Ref, WatchSource, VNode, SlotsType } from 'vue';
|
|
5
5
|
|
|
@@ -80,14 +80,14 @@ declare function useLazyGenerator<T>(generatorFunc: () => AsyncResultGenerator<T
|
|
|
80
80
|
*/
|
|
81
81
|
declare function useReactiveGenerator<Inputs, T, E extends ErrorBase = ErrorBase>(source: WatchSource<Inputs>, generatorFunc: (args: Inputs) => AsyncResultGenerator<T>, options?: ReactiveProcessOptions): Ref<AsyncResult<T, E>>;
|
|
82
82
|
/**
|
|
83
|
-
* Creates a reactive
|
|
84
|
-
* The
|
|
83
|
+
* Creates a reactive AsyncResultCollection wrapped in a Vue ref.
|
|
84
|
+
* The AsyncResultCollection notifies Vue's reactivity system whenever its state changes.
|
|
85
85
|
*
|
|
86
|
-
* @template T - The type of the values in the
|
|
86
|
+
* @template T - The type of the values in the AsyncResultCollection.
|
|
87
87
|
* @template E - The type of the error, extending ErrorBase (default is ErrorBase).
|
|
88
|
-
* @returns a ref to the
|
|
88
|
+
* @returns a ref to the AsyncResultCollection
|
|
89
89
|
*/
|
|
90
|
-
declare function
|
|
90
|
+
declare function useAsyncResultCollection<T = any, E extends ErrorBase = ErrorBase>(): Ref<{
|
|
91
91
|
readonly tasks: Map<string, {
|
|
92
92
|
key: string;
|
|
93
93
|
result: {
|
|
@@ -125,6 +125,10 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
125
125
|
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
126
126
|
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
127
127
|
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
128
|
+
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
129
|
+
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
130
|
+
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
131
|
+
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
128
132
|
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
129
133
|
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
130
134
|
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
@@ -135,7 +139,7 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
135
139
|
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
136
140
|
};
|
|
137
141
|
unsub: () => void;
|
|
138
|
-
}> & Omit<Map<string, unwrapped_core.
|
|
142
|
+
}> & Omit<Map<string, unwrapped_core.AsyncResultCollectionItem<T, E>>, keyof Map<any, any>>;
|
|
139
143
|
readonly length: number;
|
|
140
144
|
readonly items: {
|
|
141
145
|
state: {
|
|
@@ -172,6 +176,10 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
172
176
|
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
173
177
|
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
174
178
|
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
179
|
+
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
180
|
+
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
181
|
+
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
182
|
+
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
175
183
|
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
176
184
|
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
177
185
|
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
@@ -216,6 +224,10 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
216
224
|
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
217
225
|
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
218
226
|
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
227
|
+
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
228
|
+
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
229
|
+
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
230
|
+
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
219
231
|
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
220
232
|
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
221
233
|
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
@@ -225,8 +237,10 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
225
237
|
debug: (name?: string) => () => void;
|
|
226
238
|
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
227
239
|
}][];
|
|
228
|
-
state: unwrapped_core.
|
|
229
|
-
listen: (listener: (taskQueue:
|
|
240
|
+
state: unwrapped_core.AsyncResultCollectionState;
|
|
241
|
+
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;
|
|
230
244
|
add: (key: string, task: AsyncResult<T, E>, removeOnSettle?: boolean) => AsyncResult<T, E>;
|
|
231
245
|
remove: (key: string) => boolean;
|
|
232
246
|
clear: () => void;
|
|
@@ -241,7 +255,7 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
241
255
|
getAllLoadingPromises: () => Promise<Result<T, E>>[];
|
|
242
256
|
log: (name?: string) => void;
|
|
243
257
|
debug: (name?: string) => () => void;
|
|
244
|
-
},
|
|
258
|
+
}, AsyncResultCollection<T, E> | {
|
|
245
259
|
readonly tasks: Map<string, {
|
|
246
260
|
key: string;
|
|
247
261
|
result: {
|
|
@@ -279,6 +293,10 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
279
293
|
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
280
294
|
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
281
295
|
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
296
|
+
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
297
|
+
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
298
|
+
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
299
|
+
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
282
300
|
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
283
301
|
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
284
302
|
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
@@ -289,7 +307,7 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
289
307
|
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
290
308
|
};
|
|
291
309
|
unsub: () => void;
|
|
292
|
-
}> & Omit<Map<string, unwrapped_core.
|
|
310
|
+
}> & Omit<Map<string, unwrapped_core.AsyncResultCollectionItem<T, E>>, keyof Map<any, any>>;
|
|
293
311
|
readonly length: number;
|
|
294
312
|
readonly items: {
|
|
295
313
|
state: {
|
|
@@ -326,6 +344,10 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
326
344
|
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
327
345
|
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
328
346
|
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
347
|
+
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
348
|
+
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
349
|
+
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
350
|
+
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
329
351
|
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
330
352
|
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
331
353
|
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
@@ -370,6 +392,10 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
370
392
|
updateFromResultPromise: (promise: Promise<Result<T, E>>) => AsyncResult<T, E>;
|
|
371
393
|
listen: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
372
394
|
listenUntilSettled: (listener: unwrapped_core.AsyncResultListener<T, E>, immediate?: boolean) => () => void;
|
|
395
|
+
onSuccessOnce: (callback: (value: T) => void) => () => void;
|
|
396
|
+
onSuccessPerpetual: (callback: (value: T) => void) => () => void;
|
|
397
|
+
onErrorOnce: (callback: (error: E) => void) => () => void;
|
|
398
|
+
onErrorPerpetual: (callback: (error: E) => void) => () => void;
|
|
373
399
|
mirror: (other: AsyncResult<T, E>) => () => void;
|
|
374
400
|
mirrorUntilSettled: (other: AsyncResult<T, E>) => () => void;
|
|
375
401
|
chain: <O, E2 extends ErrorBase = ErrorBase>(fn: unwrapped_core.ChainStep<T, O, E | E2>) => AsyncResult<O, E | E2>;
|
|
@@ -379,8 +405,10 @@ declare function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>():
|
|
|
379
405
|
debug: (name?: string) => () => void;
|
|
380
406
|
[Symbol.iterator]: () => Generator<AsyncResult<T, E>, T, any>;
|
|
381
407
|
}][];
|
|
382
|
-
state: unwrapped_core.
|
|
383
|
-
listen: (listener: (taskQueue:
|
|
408
|
+
state: unwrapped_core.AsyncResultCollectionState;
|
|
409
|
+
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;
|
|
384
412
|
add: (key: string, task: AsyncResult<T, E>, removeOnSettle?: boolean) => AsyncResult<T, E>;
|
|
385
413
|
remove: (key: string) => boolean;
|
|
386
414
|
clear: () => void;
|
|
@@ -445,4 +473,4 @@ declare function makeAsyncResultLoader<T, E extends ErrorBase = ErrorBase>(slots
|
|
|
445
473
|
};
|
|
446
474
|
}>, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
447
475
|
|
|
448
|
-
export { type LazyActionRef, makeAsyncResultLoader, useAction,
|
|
476
|
+
export { type LazyActionRef, makeAsyncResultLoader, useAction, useAsyncResultCollection, useAsyncResultRef, useAsyncResultRefFromPromise, useGenerator, useLazyAction, useLazyGenerator, useReactiveChain, useReactiveGenerator };
|
package/dist/vue/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
makeAsyncResultLoader: () => makeAsyncResultLoader,
|
|
24
24
|
useAction: () => useAction,
|
|
25
|
-
|
|
25
|
+
useAsyncResultCollection: () => useAsyncResultCollection,
|
|
26
26
|
useAsyncResultRef: () => useAsyncResultRef,
|
|
27
27
|
useAsyncResultRefFromPromise: () => useAsyncResultRefFromPromise,
|
|
28
28
|
useGenerator: () => useGenerator,
|
|
@@ -92,8 +92,8 @@ function useReactiveGenerator(source, generatorFunc, options = { immediate: true
|
|
|
92
92
|
}, { immediate: options.immediate });
|
|
93
93
|
return resultRef;
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
const list = new import_core.
|
|
95
|
+
function useAsyncResultCollection() {
|
|
96
|
+
const list = new import_core.AsyncResultCollection();
|
|
97
97
|
const listRef = (0, import_vue.ref)(list);
|
|
98
98
|
list.listen(() => {
|
|
99
99
|
(0, import_vue.triggerRef)(listRef);
|
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, AsyncResultList, 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 AsyncResultList ===\n\n/**\n * Creates a reactive AsyncResultList wrapped in a Vue ref.\n * The AsyncResultList notifies Vue's reactivity system whenever its state changes.\n * \n * @template T - The type of the values in the AsyncResultList.\n * @template E - The type of the error, extending ErrorBase (default is ErrorBase).\n * @returns a ref to the AsyncResultList\n */\nexport function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>() {\n const list = new AsyncResultList<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}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAgF;AAChF,kBAAiI;AAoB1H,SAAS,kBAAsD,aAAiC;AACnG,MAAI,CAAC,aAAa;AACd,kBAAc,IAAI,wBAAkB;AAAA,EACxC;AACA,QAAM,YAAQ,gBAAuB,WAAW;AAEhD,QAAM,QAAQ,YAAY,OAAO,MAAM;AACnC,+BAAW,KAAK;AAAA,EACpB,CAAC;AAED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AAA,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>(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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Ac,QAAQ,MAAM,SAAS,MAAM,UAAU,UAAM,eAAE,OAAO,EAAE,OAAO,QAAQ,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"]}
|
package/dist/vue/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/vue/composables.ts
|
|
2
2
|
import { onUnmounted, ref, triggerRef, watch } from "vue";
|
|
3
|
-
import { AsyncResult,
|
|
3
|
+
import { AsyncResult, AsyncResultCollection } from "unwrapped/core";
|
|
4
4
|
function useAsyncResultRef(asyncResult) {
|
|
5
5
|
if (!asyncResult) {
|
|
6
6
|
asyncResult = new AsyncResult();
|
|
@@ -57,8 +57,8 @@ function useReactiveGenerator(source, generatorFunc, options = { immediate: true
|
|
|
57
57
|
}, { immediate: options.immediate });
|
|
58
58
|
return resultRef;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
const list = new
|
|
60
|
+
function useAsyncResultCollection() {
|
|
61
|
+
const list = new AsyncResultCollection();
|
|
62
62
|
const listRef = ref(list);
|
|
63
63
|
list.listen(() => {
|
|
64
64
|
triggerRef(listRef);
|
|
@@ -112,7 +112,7 @@ function makeAsyncResultLoader(slots, name = "AsyncResultLoader") {
|
|
|
112
112
|
export {
|
|
113
113
|
makeAsyncResultLoader,
|
|
114
114
|
useAction,
|
|
115
|
-
|
|
115
|
+
useAsyncResultCollection,
|
|
116
116
|
useAsyncResultRef,
|
|
117
117
|
useAsyncResultRefFromPromise,
|
|
118
118
|
useGenerator,
|
package/dist/vue/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vue/composables.ts","../../src/vue/components/asyncResultLoader.ts"],"sourcesContent":["import { onUnmounted, ref, triggerRef, watch, type Ref, type WatchSource } from \"vue\";\nimport { AsyncResult, AsyncResultList, 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 AsyncResultList ===\n\n/**\n * Creates a reactive AsyncResultList wrapped in a Vue ref.\n * The AsyncResultList notifies Vue's reactivity system whenever its state changes.\n * \n * @template T - The type of the values in the AsyncResultList.\n * @template E - The type of the error, extending ErrorBase (default is ErrorBase).\n * @returns a ref to the AsyncResultList\n */\nexport function useAsyncResultList<T = any, E extends ErrorBase = ErrorBase>() {\n const list = new AsyncResultList<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 });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AAgB,QAAQ,MAAM,WAAW,MAAM,YAAY,MAAM,EAAE,OAAO,EAAE,OAAO,UAAU,GAAG,eAAU;AAChH,cAAM,aAAa,QAAQ,MAAM,QAAQ,MAAM,SAAS,MAAM,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":["watch","watch"]}
|
|
1
|
+
{"version":3,"sources":["../../src/vue/composables.ts","../../src/vue/components/asyncResultLoader.ts"],"sourcesContent":["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}"],"mappings":";AAAA,SAAS,aAAa,KAAK,YAAY,aAAyC;AAChF,SAAS,aAAa,6BAAiH;AAoBhI,SAAS,kBAAsD,aAAiC;AACnG,MAAI,CAAC,aAAa;AACd,kBAAc,IAAI,YAAkB;AAAA,EACxC;AACA,QAAM,QAAQ,IAAuB,WAAW;AAEhD,QAAM,QAAQ,YAAY,OAAO,MAAM;AACnC,eAAW,KAAK;AAAA,EACpB,CAAC;AAED,cAAY,MAAM;AACd,UAAM;AAAA,EACV,CAAC;AAED,SAAO;AACX;AAOO,SAAS,6BAAiE,SAAgC;AAC7G,SAAO,kBAAkB,YAAY,kBAAkB,OAAO,CAAC;AACnE;AAcO,SAAS,iBAA6D,QAA6B,MAAmC,UAAkC,EAAE,WAAW,KAAK,GAA2B;AACxN,QAAM,SAAS,IAAI,YAAkB;AACrC,QAAM,YAAY,kBAAkB,MAAM;AAE1C,MAAI,QAA6B;AAEjC,QAAM,QAAQ,CAAC,cAAc;AACzB,YAAQ;AACR,YAAQ,OAAO,OAAO,KAAK,SAAS,CAAC;AAAA,EACzC,GAAG,EAAE,WAAW,QAAQ,UAAU,CAAC;AAEnC,cAAY,MAAM;AACd,YAAQ;AAAA,EACZ,CAAC;AAED,SAAO;AACX;AAqBO,SAAS,UAA8C,QAA8C;AACxG,SAAO,6BAA6B,OAAO,CAAC;AAChD;AAUO,SAAS,cAAkD,QAA2C;AACzG,QAAM,aAAa,YAAY,eAAqB,MAAM;AAC1D,QAAM,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