|
1 | 1 | import { LoadableMixinInstance } from './LoadableMixin'; |
2 | 2 | /** |
3 | | - * Decorate a function to causes loading states changes during its execution. It |
4 | | - * set state as loading when function is init and unset on throws an error or |
| 3 | + * An union of any function and functions that have access to `this` |
| 4 | + * (Vue instance). |
| 5 | + */ |
| 6 | +export declare type Method = ((...args: any[]) => any) | ((this: LoadableMixinInstance, ...args: any[]) => any); |
| 7 | +/** |
| 8 | + * A Higher-order type to trasnform a method into loadable method that have |
| 9 | + * access to `this` (Vue instance) and returns a Promise. |
| 10 | + */ |
| 11 | +export declare type LoadableMethod<T extends Method> = (this: LoadableMixinInstance, ...args: Parameters<T>) => ReturnType<T> extends Promise<any> ? ReturnType<T> : Promise<ReturnType<T>>; |
| 12 | +/** |
| 13 | + * Decorate a method to causes loading states changes during its execution. It |
| 14 | + * sets state as loading when function is init and unsets on throws an error or |
5 | 15 | * resolve/return. |
6 | | - * @example ```js |
| 16 | + * @example |
7 | 17 | * Vue.component('SignInForm', { |
8 | 18 | * methods: { |
9 | 19 | * signIn: loadable(async function ({ email, password }) { |
10 | 20 | * // ... |
11 | 21 | * }, 'signIn') |
12 | 22 | * } |
13 | | - * })``` |
14 | | - * @param λ - A function, commonly async, which causes loading state changes. |
15 | | - * @param [state] - Loading state name. |
| 23 | + * }); |
| 24 | + * @param method - A method, commonly async, which causes loading state changes. |
| 25 | + * @param [state] - Loading state name. It's "unknown" if not defined. |
16 | 26 | */ |
17 | | -export default function loadable<Return, Params extends any[]>(λ: (this: LoadableMixinInstance, ...params: Params) => Return | Promise<Return>, state?: string): (this: LoadableMixinInstance, ...params: Params) => Promise<Return>; |
| 27 | +declare const loadable: <T extends Method>(method: T, state?: string) => LoadableMethod<T>; |
| 28 | +export default loadable; |
0 commit comments