@anweb/nuxt-ancore 1.7.0 → 1.7.1
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/module.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
|
|
2
2
|
import { type Ref, type ComputedRef } from 'vue';
|
|
3
3
|
import { useAsyncData } from '#app';
|
|
4
|
-
|
|
4
|
+
import type { UseEventBusReturn } from '@vueuse/core';
|
|
5
|
+
import type { KeysOf, PickFrom } from '#app/composables/asyncData';
|
|
6
|
+
interface TConfig<TData> {
|
|
5
7
|
request: NitroFetchRequest;
|
|
6
8
|
apiConfig?: NitroFetchOptions<string>;
|
|
9
|
+
events?: {
|
|
10
|
+
bus: UseEventBusReturn<any, any>;
|
|
11
|
+
callback: (info: TData) => PickFrom<TData, KeysOf<TData>> | undefined;
|
|
12
|
+
}[];
|
|
7
13
|
}
|
|
8
14
|
interface TUseAnData<TData, TError> {
|
|
9
15
|
init: () => Promise<void>;
|
|
@@ -13,5 +19,5 @@ interface TUseAnData<TData, TError> {
|
|
|
13
19
|
error: ComputedRef<TError>;
|
|
14
20
|
status: ReturnType<typeof useAsyncData>['status'];
|
|
15
21
|
}
|
|
16
|
-
export declare const useAnData: <TData = unknown, TError = unknown>(config: TConfig) => TUseAnData<TData, TError>;
|
|
22
|
+
export declare const useAnData: <TData = unknown, TError = unknown>(config: TConfig<TData>) => TUseAnData<TData, TError>;
|
|
17
23
|
export {};
|
|
@@ -19,6 +19,13 @@ export const useAnData = (config) => {
|
|
|
19
19
|
() => userApi(request.value, { method: "GET", ...config.apiConfig || {} }),
|
|
20
20
|
{ immediate: false }
|
|
21
21
|
);
|
|
22
|
+
if (config.events) {
|
|
23
|
+
for (const event of config.events) {
|
|
24
|
+
event.bus.on((info) => {
|
|
25
|
+
data.value = event.callback(info);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
22
29
|
return {
|
|
23
30
|
init: execute,
|
|
24
31
|
loading,
|