revojs 0.0.66 → 0.0.67

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/dist/index.js CHANGED
@@ -421,11 +421,11 @@ const $fetch = async (scope, input, options) => {
421
421
  default: return response;
422
422
  }
423
423
  };
424
- const useAsync = (scope, invoke) => {
424
+ const useAsync = (scope, invoke, options) => {
425
425
  const { tasks } = useRuntime(scope);
426
426
  const state = createState();
427
427
  const isLoading = createState(true);
428
- const task = invoke().then((value) => state.value = value).finally(() => isLoading.value = false);
428
+ const task = invoke().then((value) => state.value = value).catch(options?.catch).finally(() => isLoading.value = false);
429
429
  if (isServer()) tasks.push(task);
430
430
  return {
431
431
  state,
@@ -21,6 +21,9 @@ export type RuntimeContext<T = Record<string, unknown>> = {
21
21
  export type RouteContext = {
22
22
  inputs: State<Record<string, string>>;
23
23
  };
24
+ export type AsyncOptions = {
25
+ catch?: (error: Error) => void | Promise<void>;
26
+ };
24
27
  export declare const isRoute: <T>(value?: T) => value is Route & T;
25
28
  export declare const useRuntime: <T = Record<string, unknown>>(scope: Scope) => RuntimeContext<T>;
26
29
  export declare const useRoute: (scope: Scope) => RouteContext;
@@ -29,7 +32,7 @@ export declare const defineMiddleware: (middleware: Middleware) => Middleware;
29
32
  export declare const fileName: (path: string) => string | undefined;
30
33
  export declare const toPath: (value: string) => (string | undefined)[];
31
34
  export declare const $fetch: <T>(scope: Scope, input: string | URL, options?: RequestInit) => Promise<T>;
32
- export declare const useAsync: <T>(scope: Scope, invoke: () => Promise<T>) => {
35
+ export declare const useAsync: <T>(scope: Scope, invoke: () => Promise<T>, options?: AsyncOptions) => {
33
36
  state: State<T | undefined>;
34
37
  isLoading: State<boolean>;
35
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.0.66",
3
+ "version": "0.0.67",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",