@anweb/nuxt-ancore 1.7.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "AnCore",
3
3
  "configKey": "ancore",
4
- "version": "1.7.0",
4
+ "version": "1.7.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
@@ -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
- interface TConfig {
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: (target: PickFrom<TData, KeysOf<TData>> | undefined, updated: 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,14 @@ 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((updated) => {
25
+ const result = event.callback(data.value, updated);
26
+ if (result !== void 0) data.value = result;
27
+ });
28
+ }
29
+ }
22
30
  return {
23
31
  init: execute,
24
32
  loading,
@@ -1,21 +1,16 @@
1
1
  import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
2
2
  import { type UseEventBusReturn } from '@vueuse/core';
3
- import type { TWS as TWSDefault } from '#ancore/types';
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 | void;
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, TWS extends TWSDefault = TWSDefault>(config: TConfig<TData, TFilter, TWS>) => {
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 || newCount === 0) {
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 = () => {
@@ -1,4 +1,3 @@
1
1
  export * from './api.js';
2
2
  export * from './global.js';
3
- export * from './ws.js';
4
3
  export * from './responseList.js';
@@ -1,4 +1,3 @@
1
1
  export * from "./api";
2
2
  export * from "./global";
3
- export * from "./ws";
4
3
  export * from "./responseList";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anweb/nuxt-ancore",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "AnCore Nuxt module",
5
5
  "repository": "https://github.com/ANLTD/ancore",
6
6
  "license": "MIT",
@@ -1,4 +0,0 @@
1
- export interface TWS {
2
- type: string
3
- data: unknown
4
- }