@anweb/nuxt-ancore 1.7.1 → 1.7.2
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 +1 -1
- package/dist/runtime/composables/useAnData.d.ts +1 -1
- package/dist/runtime/composables/useAnData.js +3 -2
- package/dist/runtime/composables/useAnList.d.ts +3 -8
- package/dist/runtime/composables/useAnList.js +1 -14
- package/dist/runtime/types/index.d.ts +0 -1
- package/dist/runtime/types/index.js +0 -1
- package/package.json +1 -1
- package/dist/runtime/types/ws.d.ts +0 -4
package/dist/module.json
CHANGED
|
@@ -8,7 +8,7 @@ interface TConfig<TData> {
|
|
|
8
8
|
apiConfig?: NitroFetchOptions<string>;
|
|
9
9
|
events?: {
|
|
10
10
|
bus: UseEventBusReturn<any, any>;
|
|
11
|
-
callback: (
|
|
11
|
+
callback: (target: PickFrom<TData, KeysOf<TData>> | undefined, updated: TData) => PickFrom<TData, KeysOf<TData>> | undefined;
|
|
12
12
|
}[];
|
|
13
13
|
}
|
|
14
14
|
interface TUseAnData<TData, TError> {
|
|
@@ -21,8 +21,9 @@ export const useAnData = (config) => {
|
|
|
21
21
|
);
|
|
22
22
|
if (config.events) {
|
|
23
23
|
for (const event of config.events) {
|
|
24
|
-
event.bus.on((
|
|
25
|
-
|
|
24
|
+
event.bus.on((updated) => {
|
|
25
|
+
const result = event.callback(data.value, updated);
|
|
26
|
+
if (result !== void 0) data.value = result;
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
|
|
2
2
|
import { type UseEventBusReturn } from '@vueuse/core';
|
|
3
|
-
|
|
4
|
-
interface TConfig<TData, TFilter, TWS extends TWSDefault> {
|
|
3
|
+
interface TConfig<TData, TFilter> {
|
|
5
4
|
request: NitroFetchRequest;
|
|
6
5
|
filter?: TFilter;
|
|
7
6
|
reverse?: boolean;
|
|
8
7
|
events?: {
|
|
9
8
|
bus: UseEventBusReturn<any, any>;
|
|
10
|
-
callback: (list: TData[], count: number, data: any) => number |
|
|
11
|
-
}[];
|
|
12
|
-
ws?: {
|
|
13
|
-
type: TWS['type'];
|
|
14
|
-
callback: (list: TData[], count: number, data: any) => number | void;
|
|
9
|
+
callback: (list: TData[], count: number, data: any) => number | undefined;
|
|
15
10
|
}[];
|
|
16
11
|
apiConfig?: NitroFetchOptions<string>;
|
|
17
12
|
}
|
|
18
|
-
declare const _default: <TData, TFilter = unknown
|
|
13
|
+
declare const _default: <TData, TFilter = unknown>(config: TConfig<TData, TFilter>) => {
|
|
19
14
|
init: (newFilter?: TFilter) => Promise<void>;
|
|
20
15
|
inited: import("vue").Ref<boolean, boolean>;
|
|
21
16
|
filter: [Partial<TFilter>] extends [import("vue").Ref<any, any>] ? import("@vue/shared").IfAny<import("vue").Ref<any, any> & Partial<TFilter>, import("vue").Ref<import("vue").Ref<any, any> & Partial<TFilter>, import("vue").Ref<any, any> & Partial<TFilter>>, import("vue").Ref<any, any> & Partial<TFilter>> : import("vue").Ref<import("vue").UnwrapRef<Partial<TFilter>>, Partial<TFilter> | import("vue").UnwrapRef<Partial<TFilter>>>;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { useEventBus } from "@vueuse/core";
|
|
2
1
|
import { computed, ref, reactive, watch } from "vue";
|
|
3
2
|
import { useAsyncData } from "#app";
|
|
4
3
|
import { userApi, toQuery } from "../utils/index.js";
|
|
5
4
|
export default (config) => {
|
|
6
|
-
const busWS = useEventBus("ws");
|
|
7
5
|
const inited = ref(false);
|
|
8
6
|
const filter = ref(config.filter || {});
|
|
9
7
|
const items = reactive([]);
|
|
@@ -20,23 +18,12 @@ export default (config) => {
|
|
|
20
18
|
for (const event of config.events) {
|
|
21
19
|
event.bus.on((data2) => {
|
|
22
20
|
const newCount = event.callback(items, count.value || 0, data2);
|
|
23
|
-
if (newCount
|
|
21
|
+
if (newCount !== void 0) {
|
|
24
22
|
count.value = newCount;
|
|
25
23
|
}
|
|
26
24
|
});
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
|
-
if (config.ws) {
|
|
30
|
-
busWS.on((data2) => {
|
|
31
|
-
const event = config.ws?.find((item) => item.type === data2.type);
|
|
32
|
-
if (event) {
|
|
33
|
-
const newCount = event.callback(items, count.value || 0, data2.data);
|
|
34
|
-
if (newCount || newCount === 0) {
|
|
35
|
-
count.value = newCount;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
27
|
inited.value = true;
|
|
41
28
|
};
|
|
42
29
|
const refresh = () => {
|
package/package.json
CHANGED