vue-asyncx 1.7.0 → 1.8.0

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/README.md CHANGED
@@ -1,10 +1,13 @@
1
+ 优雅好用的异步函数/数据管理工具
2
+
3
+ ![](./docs/compare.png)
4
+
1
5
  ## 特性
2
6
 
3
- - 效率+:异步相关样板代码减少50%
4
- - 效率+:自动处理异步操作的乱序响应
7
+ - 效率+:异步相关样板代码减少40%+
5
8
  - 可读+:异步操作命名指向明确、风格统一
6
- - 可读+:易于写出符合“干净架构”理念的函数
7
9
  - 质量+:全 TS 支持 + 100% 单元测试
10
+ - 维护+:易于写出符合“干净架构”理念的函数
8
11
 
9
12
  ## 安装
10
13
 
@@ -12,126 +15,102 @@
12
15
  pnpm i vue-asyncx
13
16
  ```
14
17
 
15
- ## 使用
16
-
17
- ### useAsync 异步函数
18
-
19
- 当需要执行一个异步函数,可以将要执行的异步函数传入 `useAsync` 中,得到
20
-
21
- - 一个异步函数的包裹函数
22
- - 一个记录异步函数执行 `loading` 响应式数据
23
- - 等等
18
+ ## 快速开始
24
19
 
25
20
  ```ts
26
- import { useAsync } from 'vue-asyncx'
21
+ import { getUserApi } from './api'
22
+ import { useAsyncData } from '../dist/vue-asyncx'
27
23
 
28
24
  const {
29
- method,
30
- methodLoading,
31
- } = useAsync(async (a: number, b: number) => a + b)
25
+ user,
26
+ queryUserLoading,
27
+ queryUser,
28
+ } = useAsyncData('user', getUserApi)
32
29
 
33
- method(1, 1).then(total => console.log(total))
30
+ queryUser('Mike')
34
31
  ```
35
32
 
36
- 如果不喜欢默认解构出来的 `method` `methodLoading`,除了解构赋值的重命名,你还可以直接:
33
+ 当需要异步数据 `user` 时,只需要传入数据的变量名和获取数据的异步函数即可。`useAsyncData` 会自动处理与异步函数相关的 `loading`, `data`, `function`、`error` 等状态。
37
34
 
38
- ```ts
39
- import { useAsync } from 'vue-asyncx'
35
+ ## 约定带来效率
40
36
 
41
- const {
42
- sum,
43
- sumLoading
44
- } = useAsync('sum', async (a: number, b: number) => a + b)
37
+ [`useRequest`](https://ahooks.js.org/hooks/use-request/index) 返回固定的 `data`、`loading`、`error` 不同,`useAsyncData` 将关联的函数、变量统一命名:
45
38
 
46
- sum(1, 1).then(total => console.log(total))
47
- ```
39
+ - `user`:由异步函数更新的数据 `data`
40
+ - `queryUser`:更新 `user` 的异步函数
41
+ - `queryUserLoading`:调用 `queryUser` 时的 `loading` 状态
48
42
 
49
- 当你将 `sum` 字符串传入 `useAsync`,结果属性自动替换为 `sum` 和 `sumLoading`,并且,**解构附带 ts 提示**,在结果对象内输入 `s`,相关内容会自动提示。
43
+ 刚接触可能有些不习惯,但这种方式带来可读性和效率的双重提升,在大型项目、多人团队中尤为明显。
50
44
 
51
- 同时,解构出的 `sum` TS 类型由传入的函数推导出,二者 TS 类型一致。
45
+ 代码中看到 `queryUserLoading` 变量,就知道它和 `user` 变量以及 `queryUser` 函数有关。
52
46
 
53
- 想象一下在多人合作的大型项目中,通过这种方式约束命名:不同开发人员可以自然地将相同模式的变量名关联在一起,互相理解代码、review 内容变得更简单。
47
+ ![](./docs/vscode-hint.png)
54
48
 
55
- ### useAsyncData 异步数据
49
+ 并且这一切,都可以自动提示。
56
50
 
57
- 除了异步函数,另一个常见场景是异步数据。
51
+ ## 用法
58
52
 
59
- 假设你在开发一个用户详情页,页面通过 `user` 数据渲染,`user` 数据通过 `getUserById` 的 api 获取。
53
+ ### 立即执行
60
54
 
61
- 显然,`user` 是一个异步数据,通过 `useAsyncData`,你可以很容易处理这些内容:
55
+ 默认情况下,异步函数需要手动调用,可以设置 `options.immediate = true` 自动触发异步函数。
62
56
 
63
57
  ```ts
64
- import { getUserById } from '@/api'
65
- import { useAsyncData } from 'vue-asyncx'
66
-
67
- /**
68
- * 调用 useAsyncData('user', ...),
69
- * user、queryUserLoading、queryUser 自动提示
70
- */
71
58
  const {
72
59
  user,
73
- queryUserLoading,
74
- queryUser
75
- } = useAsyncData('user', () => getUserById('1'), { immediate: true })
60
+ queryUserLoading
61
+ } = useAsyncData('user', getUserApi, { immediate: true })
76
62
  ```
77
63
 
78
- 代码编写流程与思路流程高度一致:
79
- - 数据命名:页面需要使用异步数据 user => `useAsyncData('user', `
80
- - 数据获取:user 数据来自 getUserById 接口 => `useAsyncData('user', () => getUserById('1')`
81
- - 触发获取:进入页面后需要立即获取 user 数据 `useAsyncData('user', () => getUserById('1'), { immediate: true })`
64
+ ### watch 执行
82
65
 
83
- ok,写完上述,页面所需的 `user` 各种相关数据、函数立即出现,想用什么解构什么:
66
+ 除了 `immediate`,`useAsyncData` 还完整支持 [vue watch](https://vuejs.org/api/reactivity-core.html#watch)
84
67
 
85
- - `user` 响应式变量自动定义并声明
86
- - 获取 `user` 的函数被自动命名为 `queryUser`
87
- - 调用 `queryUser` 时的加载状态自动关联到 `queryUserLoading`
68
+ #### `options.watch` 配置 watch source
88
69
 
89
- 只需要在 TS 的提示下,按需解构出页面所需的内容
70
+ ```ts
71
+ import { getUserApi } from './api'
72
+ import { useAsyncData } from '../dist/vue-asyncx'
90
73
 
91
- > `useAsyncData` 底层使用 `useAsync`,即 `useAsync` 的所有能力 `useAsyncData` 都具备。
92
- > 除 `useAsync` 的能力外,`useAsyncData` 额外支持了一些与数据相关的能力。
93
- > 二者区别:
94
- > `useAsync` 关注异步函数,不关注需要长久保留结果值。例如 `submit`、`confirm` 等操作
95
- > `useAsyncData` 则关注异步数据,异步函数则是数据的获取方式
74
+ const props = defineProps<{
75
+ userId: string;
76
+ }>();
96
77
 
97
- ### immediate watch
78
+ const { user } = useAsyncData('user', () => getUserApi(props.userId), {
79
+ watch: () => props.userId,
80
+ immediate: true
81
+ })
82
+ ```
98
83
 
99
- 注意到上面例子里的 `useAsyncData` 使用了 `immediate` 配置,效果是立即调用 `queryUser`
84
+ `useAsyncData` 会立即执行,并在每次 `props.userId` 变化时执行。
100
85
 
101
- 这个配置来自 vue `watch`,除了 `immediate` 外,**`useAsync` 和 `useAsyncData`** 完整支持了 vue watch 的各种配置
102
- - 通过 `options.watch` 配置 watch source
103
- - 通过 `options.watchOptions` 配置 watch 的其它 options
86
+ 上面的写法等价于:
104
87
 
105
- 比如常见的通过 props 传递参数,props 参数改变,触发异步数据改变:
88
+ ```ts
89
+ const { user, queryUser } = useAsyncData('user', () => getUserApi(props.userId))
90
+ watch(() => props.userId, () => queryUser(), { immediate: true })
91
+ ```
106
92
 
107
- ```js
108
- const {
109
- user,
110
- queryUserLoading,
111
- queryUser
112
- } = useAsyncData('user', () => getUserById(props.id), {
113
- watch: () => props.id, // 此处用 props 举例,支持所有 vue watch source 的用法
114
- immediate: true,
93
+ #### `options.watchOptions` 配置 watch options
94
+
95
+ ```ts
96
+ const { user } = useAsyncData('user', () => getUserApi(props.userId), {
97
+ watch: () => props.userId,
115
98
  watchOptions: {
116
- once: true // 此处用 once 举例,支持所有 vue watch options 内的配置
117
- // 这里也可以配置 immediate,与上一层的 immediate 效果一致,优先级更高
99
+ once: true, // 此处用 once 举例,支持所有 vue watch options 内的配置
118
100
  }
119
101
  })
120
102
  ```
121
103
 
122
- 实际上即使不配置 `options.watch`,配置 `options.immediate = true` 后内部也是通过 watch 机制触发的立即调用
104
+ > 注:`options.watchOptions.immediate` 优先级高于 `options.immediate`
123
105
 
124
- 默认情况下,由 watch 触发的调用不会传递任何参数。watch 的 handler 相当于:`() => queryUser()`。但在 vue 中,watch handler 可以接收新、旧数据以及 `onCleanup`
106
+ #### `options.watchOptions.handlerCreator` 配置 watch handler
125
107
 
126
- `useAsync` 和 `useAsyncData` 可以通过配置 `options.watchOptions.handlerCreator` 来自定义 watch handler:
127
-
128
- ```js
108
+ ```ts
129
109
  const {
130
- user,
131
- queryUserLoading,
110
+ user,
132
111
  queryUser
133
- } = useAsyncData('user', (id) => getUserById(id), {
134
- watch: () => props.id,
112
+ } = useAsyncData('user', (userId) => getUserApi(userId), {
113
+ watch: () => props.userId,
135
114
  immediate: true,
136
115
  watchOptions: {
137
116
  // fn 等价于 queryUser
@@ -147,130 +126,20 @@ const {
147
126
  })
148
127
  ```
149
128
 
150
- ### 调用报错与参数
151
-
152
- 除了 `loading`,`useAsync` 与 `useAsyncData` 还支持记录调用的 `error` 与 `arguments`,默认状态下,它们的命名是:
153
-
154
- ```js
155
- const {
156
- methodError,
157
- methodArguments,
158
- } = useAsync(() => {})
159
-
160
- const {
161
- queryDataError,
162
- queryDataArguments
163
- } = useAsyncData(() => {})
164
- ```
165
-
166
- 与之前例子一致,当自定义命名时,结果随之改变:
167
-
168
- ```js
169
- const {
170
- confirmError,
171
- confirmArguments,
172
- } = useAsync('confirm', () => {})
173
-
174
- const {
175
- queryUserError,
176
- queryUserArguments
177
- } = useAsyncData('user', () => {})
178
- ```
179
-
180
- `error`
181
- - **最后一次**调用 fn,**且**调用结果失败
182
- - 记录异步 fn 的 reject 内容
183
- - 记录同步 fn 的 throw 内容
184
- - **新一次**调用开始后,`error` 自动置空
129
+ ### 初始数据配置
185
130
 
186
- `arguments`
187
- - `loading` 一致,调用开始时记录本次调用传入的参数
188
- - 调用结果出现后,`arguments` 自动置空
189
-
190
- ### 异步函数乱序响应
191
-
192
- ```js
193
- // 使用 useAsync,没有 user 变量
194
- const {
195
- queryUser,
196
- queryUserLoading,
197
- } = useAsync('queryUser', () => {})
198
-
199
- // 或者,使用 useAsyncData
200
- const {
201
- user,
202
- queryUser,
203
- queryUserLoading
204
- } = useAsyncData('user', () => {})
205
- ```
206
-
207
- `queryUser` 是个异步函数,由于异步操作时间不定,多次调用情况下会出现乱序响应,考虑下列的时间线顺序:
208
-
209
- - **首次调用** `queryUser`,记做 `queryUser1`
210
- - `queryUser1` 未结束,**再次调用** `queryUser`,记做 `queryUser2`
211
- - `queryUser2` 先结束
212
- - `queryUser1` 后结束
213
-
214
- 即:**依次调用 `queryUser1` 和 `queryUser2`,但 `queryUser2` 先于 `queryUser1` 结束**。这种场景很常见,专门处理很麻烦。
215
-
216
- 而使用 `useAsync` 和 `useAsyncData`,你无需再考虑这类问题,方法会自动帮你处理。
217
-
218
- 以上述例子举例:
219
-
220
- - `queryUser1` 开始时,`queryUserLoading.value` 为 `true`
221
- - **`queryUser2` 结束时**,`queryUserLoading.value` 为 `false`
222
-
223
- 对于 `useAsyncData`,`queryUser` 对应的 `user` 数据:
224
-
225
- - `user.value` 将始终以 `queryUser2` 的结果为准(取**最晚的调用**产生的结果)
226
- - 即使 `queryUser1` 产生结果的时间更晚,但 `queryUser1` 的结果不会更新到 `user.value` 上
227
- - `queryUser1` 的结果会被自动舍弃,因为这是一个“过期的”数据
228
-
229
- > 另一种处理重复调用的方式是不允许在上次调用未结束时再次调用
230
- >
231
- > 由于 `useAsync` 和 `useAsyncData` 提供了响应式的 `loading`,对于常用组件库,向按钮传入 `loading` 状态或在 `disabled` 属性中添加 `loading` 判断即可轻松避免
232
- >
233
- > 此处讨论的是因数据源变动导致异步数据需要刷新的场景,比如 `userId` 短时间从 `1` 切换到 `2`,`user` 数据需要做对应刷新
234
-
235
- ### 数据过期
236
-
237
- > 过期数据标注是 `useAsyncData` 独有功能
238
-
239
- ```js
240
- const {
241
- user,
242
- queryUser,
243
- queryUserError,
244
- userExpired
245
- } = useAsyncData('user', () => {})
131
+ ```ts
132
+ const { user } = useAsyncData('user', getUserApi, {
133
+ // 未配置时,user 首次调用前为 undefined
134
+ initialData: {}
135
+ })
246
136
  ```
247
137
 
248
- 假设是以下时间线:
249
-
250
- - 首次调用 `queryUser`,记做 `queryUser1`
251
- - `queryUser1` 未结束,再次调用 `queryUser`,记做 `queryUser2`
252
- - `queryUser2` 先结束,**但发生报错**
253
- - `queryUser1` 后结束
254
-
255
- 此时:
256
- - `queryUser2` 的错误会被记录到 `queryUserError.value` 上
257
- - `queryUser1` 的结果**会被更新到** `user.value` 上
258
- - `userExpired.value` 会被设置为 `true`,表明当前的 `user.value` 是个过期数据(因为 `user.value` 来自`queryUser1`,而最新的结果是 `queryUser2` 的报错)
259
-
260
- > 大多数情况下,无需考虑 `userExpired.value` 的问题,因为它只会在 `queryUserError.value` 出现时出现,优先处理 `queryUserError.value` 往往是更好的做法
138
+ ### 异步函数执行过程中更新数据
261
139
 
262
- > `userExpired.value` 为 `true` 后,直到下次调用更新 `user.value` 前,`userExpired.value` 将一直保持 `true` 状态。
263
- > 原因:`userExpired.value` 为 `true` 后,虽然再次调用了 `queryUser`,但在 `user.value` 再次更新前,`user.value` 当前的值仍是“过期的”珊瑚橘
140
+ `{name}` 数据通常在异步函数调用执行结束时更新,但也可以在异步函数执行过程中更新。
264
141
 
265
- > 由于乱序的问题,如果在 `queryUser1` 时使用了 `.then(res => ...)`,`res` 的值是 `queryUser1` 的结果,与 `user.value` 不一致,这是符合预期的。
266
-
267
- ### 异步数据的中途获取与更新
268
-
269
- > 异步数据中途获取与更新是 `useAsyncData` 独有功能
270
-
271
- 在某些场景下,我们希望异步数据可以在异步获取过程中更新,无需等到获取过程完全结束。
272
-
273
- 可以通过 `options.enhanceFirstArgument = true` 支持这种需求。
142
+ 通过配置 `options.enhanceFirstArgument = true` 实现。
274
143
 
275
144
  ```js
276
145
  import { unFirstArgumentEnhanced, useAsyncData } from 'vue-asyncx'
@@ -283,10 +152,13 @@ const {
283
152
  } = useAsyncData('progress', async (init?: number) => {
284
153
  const { getData, updateData } = unFirstArgumentEnhanced(init)
285
154
  init = unFirstArgumentEnhanced(init).firstArgument
155
+ // 同步更新为入参 10
286
156
  updateData(init || 0)
287
157
  await wait(100)
158
+ // 间隔 100ms 后,更新为 50
288
159
  updateData(50)
289
160
  await wait(100)
161
+ // 间隔 100ms 后,返回 100,本次异步函数完全结束。
290
162
  return 100
291
163
  }, {
292
164
  enhanceFirstArgument: true
@@ -295,85 +167,58 @@ const {
295
167
  queryProgress(10)
296
168
  ```
297
169
 
298
- 在上述代码的最后一行调用 `queryProgress(10)` 后:
299
- - `progress.value` 会立即更新为 `10`
300
- - 100ms 后 `progress.value` 更新为 `50`
301
- - 再过 100ms 后,`progress.value` 更新为 `100`,本次调用结束
302
-
303
- 注意到在传入 `useAsyncData` 的 `fn` 内,有
304
-
305
- ```js
306
- const { getData, updateData } = unFirstArgumentEnhanced(init)
307
- init = unFirstArgumentEnhanced(init).firstArgument
308
- ```
309
-
310
- 原理:
311
-
312
170
  当 `options.enhanceFirstArgument = true` 后
313
- - `fn` 的首个参数 `init` 便被拓展为 `FirstArgumentEnhanced` 类型。
314
- - 实际调用 `queryProgress(10)` 时传入的 `10` `fn` 内部通过 `init` 接收时变成了 `{ getData, updateData, firstArgument }`,`10` 被赋在了 `init.firstArgument` 上
171
+ - 异步函数的首个参数 `init` 便被转换为 `FirstArgumentEnhanced` 类型,包含 `{ getData, updateData, firstArgument }` 属性。
172
+ - 调用 `queryProgress(10)` 时传入的 `10` 在异步函数内部被赋在 `init.firstArgument` 上
315
173
  - `unFirstArgumentEnhanced(init)` 先解构出 `getData` 和 `updateData`,再将 `init` 重新赋值为传入的 `10`
316
174
 
317
- > 也就是在 `fn` 内部可以直接通过
318
- > `const { getData, updateData, firstArgument } = init`
319
- > 但是这样写需要自行处理 TS 类型问题,因此提供了 `unFirstArgumentEnhanced` 辅助函数。
175
+ > 注意,异步函数的 `init` 不可以直接设置默认值。如:`(init: number = 0) => {}`,可以通过 `unFirstArgumentEnhanced(init, 0)` 设置默认值。
320
176
 
321
- 只需要记住
177
+ > 注意,`queryProgress()` 时,`'firstArgument' in unFirstArgumentEnhanced(init)` === `false`,这可以用来区分 `queryProgress()` 与 `queryProgress(undefined)`
322
178
 
323
- - 可以像以往一般正常定义 `fn`、调用 `queryProgress`
324
- - 在 `fn` 内部实现的最上方,加上上述的两行代码,余下即可正常使用
179
+ ### Debounce
325
180
 
326
- 如果 `fn` 本身不接收参数,那么可以改成普通函数,通过 `arguments[0]` 传递:
181
+ ```ts
182
+ import { debounce } from 'es-toolkit';
327
183
 
328
- ```js
329
184
  const {
330
- progress,
331
- queryProgress
332
- } = useAsyncData('progress', async function () {
333
- const { getData, updateData } = unFirstArgumentEnhanced(arguments[0])
334
- updateData(0)
335
- await wait(100)
336
- updateData(50)
337
- await wait(100)
338
- return 100
339
- }, {
340
- enhanceFirstArgument: true
185
+ user,
186
+ queryUser
187
+ } = useAsyncData('user', getUserApi, {
188
+ immediate: true,
189
+ setup(fn) {
190
+ return debounce(fn, 500)
191
+ }
341
192
  })
342
-
343
- queryProgress()
344
193
  ```
345
194
 
346
- 在某些情况下,需要区分 `queryProgress()` 与 `queryProgress(undefined)`,可以通过:
347
-
348
- ```js
349
- const firstArgumentEnhanced = unFirstArgumentEnhanced(arguments[0])
350
- const undefinedOrEmpty = 'firstArgument' in firstArgumentEnhanced
351
- ```
352
-
353
-
354
-
355
- - `firstArgumentEnhanced` 存在 `firstArgument` 属性时,是 `queryProgress(undefined)`
356
- - `firstArgumentEnhanced` 不存在 `firstArgument` 属性时,是 `queryProgress()`
357
-
358
- 本块 api 设计思考过程见
359
-
360
- - [rfc1-async-data-update](./docs/rfc1-async-data-update.md)
195
+ 上面例子中,`queryUser` 等价于 `debounce(fn, 500)`。可以使用任意你喜欢的 `debounce` 函数
361
196
 
362
- 其它
197
+ > `fn` 是 `useAsyncData` 内部对 `getUserApi` 做的封装。`setup` 返回值为函数类型时,会成为最终返回的 `queryUser`,否则,`queryUser` === `fn`
363
198
 
364
- - `getData` 总是返回最新的数据
365
- - `setData` 不保证设置成功(比如发生了乱序响应的情况)
366
- - 接上,`setData` 支持处理乱序响应,一旦有新的调用触发 `setData`,旧调用的 `setData` 操作会被忽略
199
+ ## API
367
200
 
368
- ## 理念
201
+ ### 响应
369
202
 
370
- 在“干净架构”里,函数拆分的原则是:一个函数应该做且只做一件事
203
+ | 属性 | 描述 | 类型 | 默认值 |
204
+ | ------------------------ | ------------------------------- | ---------------- | --------- |
205
+ | {name} | 异步函数的返回数据 | any \\ undefined | undefined |
206
+ | query{Name}Loading | 异步函数执行时的加载状态 | boolean | false |
207
+ | query{Name}Arguments | 异步函数执行时的传入的参数列表 | any[] \\ [] | [] |
208
+ | query{Name}ArgumentFirst | query{Name}Arguments 的首个参数 | any \\ undefined | undefined |
209
+ | query{Name}Error | 异步函数执行时的异常 | any \\ undefined | undefined |
210
+ | {name}Expired | {name} 数据是否过期 | any \\ undefined | undefined |
371
211
 
372
- - 对于传入 `useAsyncData` 的函数 `fn` 而言,唯一需要关注的就是如何设置 `data` 的值
373
- - 对于在 `data` 值初始化后需要干的其它事情,可以在 `useAsyncData` **外部** 通过 vue 的 watch data 去触发
374
- - 对于 `useAsyncData` 整体而言,我们将与 `data` 值相关的代码都聚集在了一起
375
- - loading、error、expired、arguments 等数据与 data 或 fn 紧密相关
376
- - watch 设置了 fn 的调用时机,即初始化 data 的时机
212
+ ### 配置
377
213
 
378
- 通过上面的约定,很容易写出“干净”的函数与高内聚的代码块,提高代码可读性
214
+ | 配置名 | 描述 | 类型 | 默认值 |
215
+ | --------------------------- | ----------------------------------------------------- | ------------------------------------------------------- | --------- |
216
+ | immediate | 是否立即执行 | boolean | false |
217
+ | watch | 传入 vue watch 的侦听数据源,发生变动时执行 `handler` | 与 vue WatchSource 一致 | - |
218
+ | watchOptions | 传入 vue watch 的配置项 | 支持全部 vue WatchOptions,另有 `handlerCreator` 配置项 | - |
219
+ | watchOptions.handlerCreator | 自定义传入 `watch` 的 `handler` | `(fn: Fn) => WatchCallback` | - |
220
+ | initialData | data 的初始值 | any | undefined |
221
+ | shallow | 是否使用 `shallowRef` 保存 data,默认使用 `ref` | boolean | false |
222
+ | enhanceFirstArgument | 是否强化首个入参 | boolean | false |
223
+ | setup | 转换函数或执行其它初始化操作 | `(fn: Fn) => ((...args: any) => any) \| void` | - |
379
224
 
@@ -50,6 +50,7 @@ declare type UseAsyncOptions<Fn extends (...args: any) => any> = {
50
50
  watch?: WatchSource;
51
51
  watchOptions?: UseAsyncWatchOptions<Fn>;
52
52
  immediate?: boolean;
53
+ setup?: (fn: Fn) => ((...args: any) => any) | void;
53
54
  };
54
55
 
55
56
  declare type UseAsyncResult<Fn extends (...args: any) => any, Name extends string> = {
@@ -1,150 +1,191 @@
1
- var b = Object.defineProperty, x = Object.defineProperties;
2
- var N = Object.getOwnPropertyDescriptors;
3
- var w = Object.getOwnPropertySymbols;
4
- var $ = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
5
- var g = (e, n, t) => n in e ? b(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t, C = (e, n) => {
6
- for (var t in n || (n = {}))
7
- $.call(n, t) && g(e, t, n[t]);
8
- if (w)
9
- for (var t of w(n))
10
- D.call(n, t) && g(e, t, n[t]);
1
+ var G = Object.defineProperty, L = Object.defineProperties;
2
+ var P = Object.getOwnPropertyDescriptors;
3
+ var F = Object.getOwnPropertySymbols;
4
+ var O = Object.prototype.hasOwnProperty, b = Object.prototype.propertyIsEnumerable;
5
+ var H = (e, t, r) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, T = (e, t) => {
6
+ for (var r in t || (t = {}))
7
+ O.call(t, r) && H(e, r, t[r]);
8
+ if (F)
9
+ for (var r of F(t))
10
+ b.call(t, r) && H(e, r, t[r]);
11
11
  return e;
12
- }, U = (e, n) => x(e, N(n));
13
- var T = (e, n) => {
14
- var t = {};
15
- for (var o in e)
16
- $.call(e, o) && n.indexOf(o) < 0 && (t[o] = e[o]);
17
- if (e != null && w)
18
- for (var o of w(e))
19
- n.indexOf(o) < 0 && D.call(e, o) && (t[o] = e[o]);
20
- return t;
12
+ }, x = (e, t) => L(e, P(t));
13
+ var $ = (e, t) => {
14
+ var r = {};
15
+ for (var n in e)
16
+ O.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
17
+ if (e != null && F)
18
+ for (var n of F(e))
19
+ t.indexOf(n) < 0 && b.call(e, n) && (r[n] = e[n]);
20
+ return r;
21
21
  };
22
- import { ref as F, computed as H, watch as R, shallowRef as j } from "vue";
23
- function G(...e) {
24
- var E;
22
+ import { ref as E, computed as l, watch as U, shallowRef as C } from "vue";
23
+ function q(e) {
24
+ if (!e) return "";
25
+ const t = e[0], r = e.slice(1);
26
+ return t.toUpperCase() + r;
27
+ }
28
+ function N() {
29
+ const e = E({
30
+ // 发起的调用
31
+ track: 0,
32
+ // 更新的调用
33
+ progress: 0,
34
+ // 完成的调用,包含报错情况
35
+ finished: 0,
36
+ // 完成(正常)的调用,不含报错情况
37
+ ok: 0
38
+ });
39
+ function t() {
40
+ const r = e.value, n = ++r.track;
41
+ return {
42
+ progress() {
43
+ r.progress >= n || (r.progress = n);
44
+ },
45
+ finish(u = !1) {
46
+ r.finished >= n || (r.finished = n, u || (r.ok = n));
47
+ },
48
+ expired(u) {
49
+ return u ? u === "progress" ? r.progress > n || r.finished >= n : u === "result:ok" ? r.progress > n || r.ok > n : r.progress > n || r.finished > n : r.track > n;
50
+ }
51
+ };
52
+ }
53
+ return t.tracking = l(() => e.value.track > 0), t.latest = {
54
+ // 已完成
55
+ finished: l(() => e.value.track === e.value.finished),
56
+ // 已成功
57
+ ok: l(() => e.value.track === e.value.ok)
58
+ }, t.has = {
59
+ // 存在完成
60
+ finished: l(() => e.value.finished > 0),
61
+ // 存在成功
62
+ ok: l(() => e.value.ok > 0),
63
+ // 存在更新
64
+ progress: l(() => e.value.progress > 0)
65
+ }, t;
66
+ }
67
+ function z(e, t) {
68
+ if (typeof t != "function") return e;
69
+ try {
70
+ const r = t(e);
71
+ return typeof r == "function" ? r : e;
72
+ } catch (r) {
73
+ return e;
74
+ }
75
+ }
76
+ function I(...e) {
77
+ var h;
25
78
  if (!Array.isArray(e) || !e.length) throw TypeError("参数错误:未传递");
26
- const { name: n, fn: t, options: o } = typeof e[0] == "function" ? { name: "method", fn: e[0], options: e[1] } : { name: e[0] || "method", fn: e[1], options: e[2] };
27
- if (typeof n != "string") throw TypeError("参数错误:name");
28
- if (typeof t != "function") throw TypeError("参数错误:fn");
29
- const p = F(!1), l = F(), _ = H(() => {
30
- var f;
31
- return (f = l.value) == null ? void 0 : f[0];
32
- }), m = F(), s = { called: 0, finished: 0 };
33
- function h(...f) {
34
- const d = ++s.called, A = (c) => {
35
- m.value = void 0, p.value = !0, l.value = c;
36
- }, u = (c, { scene: a, sn: r }) => {
37
- r > s.finished && (s.finished = r), s.called === s.finished && (a === "error" && (m.value = c), p.value = !1, l.value = void 0);
79
+ const { name: t, fn: r, options: n } = typeof e[0] == "function" ? { name: "method", fn: e[0], options: e[1] } : { name: e[0] || "method", fn: e[1], options: e[2] };
80
+ if (typeof t != "string") throw TypeError("参数错误:name");
81
+ if (typeof r != "function") throw TypeError("参数错误:fn");
82
+ const u = E(!1), p = E(), _ = l(() => {
83
+ var a;
84
+ return (a = p.value) == null ? void 0 : a[0];
85
+ }), k = E(), y = N();
86
+ function v(...a) {
87
+ const d = y(), A = (c) => {
88
+ k.value = void 0, u.value = !0, p.value = c;
89
+ }, f = (c, { scene: s }) => {
90
+ d.finish(s === "error"), !d.expired() && (s === "error" && (k.value = c), u.value = !1, p.value = void 0);
38
91
  };
39
- A(f);
92
+ A(a);
40
93
  try {
41
- const c = t(...f);
94
+ const c = r(...a);
42
95
  return c instanceof Promise ? c.then(
43
- () => u(void 0, { scene: "normal", sn: d }),
44
- (a) => u(a, { scene: "error", sn: d })
45
- ) : u(void 0, { scene: "normal", sn: d }), c;
96
+ () => f(void 0, { scene: "normal" }),
97
+ (s) => f(s, { scene: "error" })
98
+ ) : f(void 0, { scene: "normal" }), c;
46
99
  } catch (c) {
47
- throw u(c, { scene: "error", sn: d }), c;
100
+ throw f(c, { scene: "error" }), c;
48
101
  }
49
102
  }
50
- if (o) {
51
- const f = () => {
52
- }, y = Object.assign(
103
+ const m = z(v, n == null ? void 0 : n.setup);
104
+ if (n) {
105
+ const a = () => {
106
+ }, w = Object.assign(
53
107
  {},
54
- "immediate" in o ? { immediate: o.immediate } : {},
55
- (E = o.watchOptions) != null ? E : {}
56
- ), { handlerCreator: d } = y, A = T(y, ["handlerCreator"]), { watch: u } = o, a = (() => {
57
- const r = () => h();
58
- if (typeof d != "function") return r;
108
+ "immediate" in n ? { immediate: n.immediate } : {},
109
+ (h = n.watchOptions) != null ? h : {}
110
+ ), { handlerCreator: d } = w, A = $(w, ["handlerCreator"]), { watch: f } = n, s = (() => {
111
+ const i = () => m();
112
+ if (typeof d != "function") return i;
59
113
  try {
60
- const i = d(h);
61
- return typeof i == "function" ? i : r;
62
- } catch (i) {
63
- return r;
114
+ const o = d(m);
115
+ return typeof o == "function" ? o : i;
116
+ } catch (o) {
117
+ return i;
64
118
  }
65
119
  })();
66
- R(u != null ? u : f, a, A);
120
+ U(f != null ? f : a, s, A);
67
121
  }
68
122
  return {
69
- [n]: h,
70
- [`${n}Loading`]: p,
71
- [`${n}Arguments`]: l,
72
- [`${n}ArgumentFirst`]: _,
73
- [`${n}Error`]: m
123
+ [t]: m,
124
+ [`${t}Loading`]: u,
125
+ [`${t}Arguments`]: p,
126
+ [`${t}ArgumentFirst`]: _,
127
+ [`${t}Error`]: k
74
128
  };
75
129
  }
76
- function P(e) {
77
- if (!e) return "";
78
- const n = e[0], t = e.slice(1);
79
- return n.toUpperCase() + t;
80
- }
81
- const L = "__va_fae";
82
- function k(...e) {
130
+ const R = "__va_fae";
131
+ function Q(...e) {
83
132
  if (!Array.isArray(e) || !e.length) throw TypeError("参数错误:未传递");
84
- const { name: n, fn: t, options: o } = typeof e[0] == "function" ? { name: "data", fn: e[0], options: e[1] } : { name: e[0] || "data", fn: e[1], options: e[2] };
85
- if (typeof n != "string") throw TypeError("参数错误:name");
86
- if (typeof t != "function") throw TypeError("参数错误:fn");
87
- const c = o || {}, { enhanceFirstArgument: p, initialData: l, shallow: _ } = c, m = T(c, ["enhanceFirstArgument", "initialData", "shallow"]), s = F({
88
- // 调用序号(即:fn called 次调用)
89
- called: 0,
90
- // 完成序号(即:fn 第 finished 次调用完成)
91
- finished: 0,
92
- // 数据被更新的调用序号(即:data 数据由第 dataUpdateByCalled 次调用更新)
93
- dataUpdateByCalled: 0,
94
- // 数据完成更新序号(即:data 数据由第 dataUpdateByFinished 次调用完成后更新)
95
- dataUpdateByFinished: 0
96
- }), h = _ ? j(l) : F(l), E = H(() => !(s.value.dataUpdateByFinished >= s.value.finished || s.value.dataUpdateByCalled > s.value.finished));
97
- function y(a, { sn: r, scene: i }) {
98
- r < s.value.dataUpdateByCalled || (h.value = a, s.value.dataUpdateByCalled = r, i === "finish" && (s.value.dataUpdateByFinished = r));
133
+ const { name: t, fn: r, options: n } = typeof e[0] == "function" ? { name: "data", fn: e[0], options: e[1] } : { name: e[0] || "data", fn: e[1], options: e[2] };
134
+ if (typeof t != "string") throw TypeError("参数错误:name");
135
+ if (typeof r != "function") throw TypeError("参数错误:fn");
136
+ const c = n || {}, { enhanceFirstArgument: u, initialData: p, shallow: _ } = c, k = $(c, ["enhanceFirstArgument", "initialData", "shallow"]), y = _ ? C(p) : E(p), v = C();
137
+ function m(s, { track: i, scene: o }) {
138
+ o === "update" && i.progress(), !(o === "finish" && i.expired("result:ok")) && (o === "update" && i.expired("progress") || (y.value = s, v.value = i));
99
139
  }
100
- function f(a, { scene: r, sn: i }) {
101
- r === "normal" && y(a, { sn: i, scene: "finish" }), i > s.value.finished && (s.value.finished = i);
140
+ function h(s, { scene: i, track: o }) {
141
+ o.finish(i === "error"), i === "normal" && m(s, { track: o, scene: "finish" });
102
142
  }
103
- function d(a, {
104
- enhanceFirstArgument: r,
105
- sn: i
143
+ function w(s, {
144
+ enhanceFirstArgument: i,
145
+ track: o
106
146
  }) {
107
- if (!r) return a;
108
- const [v, ...O] = a;
109
- return [U(C({
110
- [L]: !0
111
- }, a.length ? { firstArgument: v } : {}), {
112
- getData: () => h.value,
113
- updateData: (B) => (y(B, { sn: i, scene: "update" }), B)
114
- }), ...O];
147
+ if (!i) return s;
148
+ const [g, ...j] = s;
149
+ return [x(T({
150
+ [R]: !0
151
+ }, s.length ? { firstArgument: g } : {}), {
152
+ getData: () => y.value,
153
+ updateData: (D) => (m(D, { track: o, scene: "update" }), D)
154
+ }), ...j];
115
155
  }
116
- function A(...a) {
117
- const r = ++s.value.called;
118
- a = d(a, { enhanceFirstArgument: p, sn: r });
156
+ const a = N();
157
+ function d(...s) {
158
+ const i = a();
159
+ s = w(s, { enhanceFirstArgument: u, track: i });
119
160
  try {
120
- const i = t(...a);
121
- return i instanceof Promise ? i.then(
161
+ const o = r(...s);
162
+ return o instanceof Promise ? o.then(
122
163
  // promise 正常结束
123
- (v) => f(v, { scene: "normal", sn: r }),
164
+ (g) => h(g, { scene: "normal", track: i }),
124
165
  // promise 出现拒绝
125
- (v) => f(v, { scene: "error", sn: r })
126
- ) : f(i, { scene: "normal", sn: r }), i;
127
- } catch (i) {
128
- throw f(i, { scene: "error", sn: r }), i;
166
+ (g) => h(g, { scene: "error", track: i })
167
+ ) : h(o, { scene: "normal", track: i }), o;
168
+ } catch (o) {
169
+ throw h(o, { scene: "error", track: i }), o;
129
170
  }
130
171
  }
131
- const u = G(`query${P(n)}`, A, m);
132
- return U(C({}, u), {
133
- [n]: h,
134
- [`${n}Expired`]: E
172
+ const A = I(`query${q(t)}`, d, k), f = l(() => a.tracking.value ? v.value ? v.value.expired("result") : a.has.finished.value : !1);
173
+ return x(T({}, A), {
174
+ [t]: y,
175
+ [`${t}Expired`]: f
135
176
  });
136
177
  }
137
- function J(e, n) {
138
- if (!q(e)) throw Error("请配置 options.enhanceFirstArgument = true");
139
- const t = e;
140
- return arguments.length === 2 && t.firstArgument === void 0 ? U(C({}, t), { firstArgument: n }) : t;
178
+ function S(e, t) {
179
+ if (!M(e)) throw Error("请配置 options.enhanceFirstArgument = true");
180
+ const r = e;
181
+ return arguments.length === 2 && r.firstArgument === void 0 ? x(T({}, r), { firstArgument: t }) : r;
141
182
  }
142
- function q(e) {
143
- return typeof e == "object" && !!e && L in e;
183
+ function M(e) {
184
+ return typeof e == "object" && !!e && R in e;
144
185
  }
145
186
  export {
146
- J as unFirstArgumentEnhanced,
147
- G as useAsync,
148
- k as useAsyncData,
149
- G as useAsyncFunction
187
+ S as unFirstArgumentEnhanced,
188
+ I as useAsync,
189
+ Q as useAsyncData,
190
+ I as useAsyncFunction
150
191
  };
@@ -1 +1 @@
1
- (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n.VueAsyncx={},n.Vue))})(this,function(n,e){"use strict";var q=Object.defineProperty,x=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var O=(n,e,o)=>e in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o,_=(n,e)=>{for(var o in e||(e={}))j.call(e,o)&&O(n,o,e[o]);if(U)for(var o of U(e))H.call(e,o)&&O(n,o,e[o]);return n},g=(n,e)=>x(n,G(e));var D=(n,e)=>{var o={};for(var d in n)j.call(n,d)&&e.indexOf(d)<0&&(o[d]=n[d]);if(n!=null&&U)for(var d of U(n))e.indexOf(d)<0&&H.call(n,d)&&(o[d]=n[d]);return o};function o(...t){var C;if(!Array.isArray(t)||!t.length)throw TypeError("参数错误:未传递");const{name:f,fn:l,options:m}=typeof t[0]=="function"?{name:"method",fn:t[0],options:t[1]}:{name:t[0]||"method",fn:t[1],options:t[2]};if(typeof f!="string")throw TypeError("参数错误:name");if(typeof l!="function")throw TypeError("参数错误:fn");const v=e.ref(!1),y=e.ref(),B=e.computed(()=>{var u;return(u=y.value)==null?void 0:u[0]}),F=e.ref(),s={called:0,finished:0};function A(...u){const p=++s.called,w=c=>{F.value=void 0,v.value=!0,y.value=c},h=(c,{scene:a,sn:r})=>{r>s.finished&&(s.finished=r),s.called===s.finished&&(a==="error"&&(F.value=c),v.value=!1,y.value=void 0)};w(u);try{const c=l(...u);return c instanceof Promise?c.then(()=>h(void 0,{scene:"normal",sn:p}),a=>h(a,{scene:"error",sn:p})):h(void 0,{scene:"normal",sn:p}),c}catch(c){throw h(c,{scene:"error",sn:p}),c}}if(m){const u=()=>{},E=Object.assign({},"immediate"in m?{immediate:m.immediate}:{},(C=m.watchOptions)!=null?C:{}),{handlerCreator:p}=E,w=D(E,["handlerCreator"]),{watch:h}=m,a=(()=>{const r=()=>A();if(typeof p!="function")return r;try{const i=p(A);return typeof i=="function"?i:r}catch(i){return r}})();e.watch(h!=null?h:u,a,w)}return{[f]:A,[`${f}Loading`]:v,[`${f}Arguments`]:y,[`${f}ArgumentFirst`]:B,[`${f}Error`]:F}}function d(t){if(!t)return"";const f=t[0],l=t.slice(1);return f.toUpperCase()+l}const $="__va_fae";function L(...t){if(!Array.isArray(t)||!t.length)throw TypeError("参数错误:未传递");const{name:f,fn:l,options:m}=typeof t[0]=="function"?{name:"data",fn:t[0],options:t[1]}:{name:t[0]||"data",fn:t[1],options:t[2]};if(typeof f!="string")throw TypeError("参数错误:name");if(typeof l!="function")throw TypeError("参数错误:fn");const c=m||{},{enhanceFirstArgument:v,initialData:y,shallow:B}=c,F=D(c,["enhanceFirstArgument","initialData","shallow"]),s=e.ref({called:0,finished:0,dataUpdateByCalled:0,dataUpdateByFinished:0}),A=B?e.shallowRef(y):e.ref(y),C=e.computed(()=>!(s.value.dataUpdateByFinished>=s.value.finished||s.value.dataUpdateByCalled>s.value.finished));function E(a,{sn:r,scene:i}){r<s.value.dataUpdateByCalled||(A.value=a,s.value.dataUpdateByCalled=r,i==="finish"&&(s.value.dataUpdateByFinished=r))}function u(a,{scene:r,sn:i}){r==="normal"&&E(a,{sn:i,scene:"finish"}),i>s.value.finished&&(s.value.finished=i)}function p(a,{enhanceFirstArgument:r,sn:i}){if(!r)return a;const[T,...R]=a;return[g(_({[$]:!0},a.length?{firstArgument:T}:{}),{getData:()=>A.value,updateData:b=>(E(b,{sn:i,scene:"update"}),b)}),...R]}function w(...a){const r=++s.value.called;a=p(a,{enhanceFirstArgument:v,sn:r});try{const i=l(...a);return i instanceof Promise?i.then(T=>u(T,{scene:"normal",sn:r}),T=>u(T,{scene:"error",sn:r})):u(i,{scene:"normal",sn:r}),i}catch(i){throw u(i,{scene:"error",sn:r}),i}}const h=o(`query${d(f)}`,w,F);return g(_({},h),{[f]:A,[`${f}Expired`]:C})}function N(t,f){if(!P(t))throw Error("请配置 options.enhanceFirstArgument = true");const l=t;return arguments.length===2&&l.firstArgument===void 0?g(_({},l),{firstArgument:f}):l}function P(t){return typeof t=="object"&&!!t&&$ in t}n.unFirstArgumentEnhanced=N,n.useAsync=o,n.useAsyncData=L,n.useAsyncFunction=o,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(r=typeof globalThis!="undefined"?globalThis:r||self,t(r.VueAsyncx={},r.Vue))})(this,function(r,t){"use strict";var S=Object.defineProperty,U=Object.defineProperties;var V=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var R=(r,t,f)=>t in r?S(r,t,{enumerable:!0,configurable:!0,writable:!0,value:f}):r[t]=f,_=(r,t)=>{for(var f in t||(t={}))C.call(t,f)&&R(r,f,t[f]);if(x)for(var f of x(t))N.call(t,f)&&R(r,f,t[f]);return r},D=(r,t)=>U(r,V(t));var O=(r,t)=>{var f={};for(var d in r)C.call(r,d)&&t.indexOf(d)<0&&(f[d]=r[d]);if(r!=null&&x)for(var d of x(r))t.indexOf(d)<0&&N.call(r,d)&&(f[d]=r[d]);return f};function f(e){if(!e)return"";const o=e[0],n=e.slice(1);return o.toUpperCase()+n}function d(){const e=t.ref({track:0,progress:0,finished:0,ok:0});function o(){const n=e.value,i=++n.track;return{progress(){n.progress>=i||(n.progress=i)},finish(p=!1){n.finished>=i||(n.finished=i,p||(n.ok=i))},expired(p){return p?p==="progress"?n.progress>i||n.finished>=i:p==="result:ok"?n.progress>i||n.ok>i:n.progress>i||n.finished>i:n.track>i}}}return o.tracking=t.computed(()=>e.value.track>0),o.latest={finished:t.computed(()=>e.value.track===e.value.finished),ok:t.computed(()=>e.value.track===e.value.ok)},o.has={finished:t.computed(()=>e.value.finished>0),ok:t.computed(()=>e.value.ok>0),progress:t.computed(()=>e.value.progress>0)},o}function P(e,o){if(typeof o!="function")return e;try{const n=o(e);return typeof n=="function"?n:e}catch(n){return e}}function $(...e){var y;if(!Array.isArray(e)||!e.length)throw TypeError("参数错误:未传递");const{name:o,fn:n,options:i}=typeof e[0]=="function"?{name:"method",fn:e[0],options:e[1]}:{name:e[0]||"method",fn:e[1],options:e[2]};if(typeof o!="string")throw TypeError("参数错误:name");if(typeof n!="function")throw TypeError("参数错误:fn");const p=t.ref(!1),m=t.ref(),b=t.computed(()=>{var l;return(l=m.value)==null?void 0:l[0]}),g=t.ref(),E=d();function w(...l){const k=E(),v=a=>{g.value=void 0,p.value=!0,m.value=a},h=(a,{scene:u})=>{k.finish(u==="error"),!k.expired()&&(u==="error"&&(g.value=a),p.value=!1,m.value=void 0)};v(l);try{const a=n(...l);return a instanceof Promise?a.then(()=>h(void 0,{scene:"normal"}),u=>h(u,{scene:"error"})):h(void 0,{scene:"normal"}),a}catch(a){throw h(a,{scene:"error"}),a}}const A=P(w,i==null?void 0:i.setup);if(i){const l=()=>{},T=Object.assign({},"immediate"in i?{immediate:i.immediate}:{},(y=i.watchOptions)!=null?y:{}),{handlerCreator:k}=T,v=O(T,["handlerCreator"]),{watch:h}=i,u=(()=>{const c=()=>A();if(typeof k!="function")return c;try{const s=k(A);return typeof s=="function"?s:c}catch(s){return c}})();t.watch(h!=null?h:l,u,v)}return{[o]:A,[`${o}Loading`]:p,[`${o}Arguments`]:m,[`${o}ArgumentFirst`]:b,[`${o}Error`]:g}}const j="__va_fae";function q(...e){if(!Array.isArray(e)||!e.length)throw TypeError("参数错误:未传递");const{name:o,fn:n,options:i}=typeof e[0]=="function"?{name:"data",fn:e[0],options:e[1]}:{name:e[0]||"data",fn:e[1],options:e[2]};if(typeof o!="string")throw TypeError("参数错误:name");if(typeof n!="function")throw TypeError("参数错误:fn");const a=i||{},{enhanceFirstArgument:p,initialData:m,shallow:b}=a,g=O(a,["enhanceFirstArgument","initialData","shallow"]),E=b?t.shallowRef(m):t.ref(m),w=t.shallowRef();function A(u,{track:c,scene:s}){s==="update"&&c.progress(),!(s==="finish"&&c.expired("result:ok"))&&(s==="update"&&c.expired("progress")||(E.value=u,w.value=c))}function y(u,{scene:c,track:s}){s.finish(c==="error"),c==="normal"&&A(u,{track:s,scene:"finish"})}function T(u,{enhanceFirstArgument:c,track:s}){if(!c)return u;const[F,...M]=u;return[D(_({[j]:!0},u.length?{firstArgument:F}:{}),{getData:()=>E.value,updateData:H=>(A(H,{track:s,scene:"update"}),H)}),...M]}const l=d();function k(...u){const c=l();u=T(u,{enhanceFirstArgument:p,track:c});try{const s=n(...u);return s instanceof Promise?s.then(F=>y(F,{scene:"normal",track:c}),F=>y(F,{scene:"error",track:c})):y(s,{scene:"normal",track:c}),s}catch(s){throw y(s,{scene:"error",track:c}),s}}const v=$(`query${f(o)}`,k,g),h=t.computed(()=>l.tracking.value?w.value?w.value.expired("result"):l.has.finished.value:!1);return D(_({},v),{[o]:E,[`${o}Expired`]:h})}function G(e,o){if(!L(e))throw Error("请配置 options.enhanceFirstArgument = true");const n=e;return arguments.length===2&&n.firstArgument===void 0?D(_({},n),{firstArgument:o}):n}function L(e){return typeof e=="object"&&!!e&&j in e}r.unFirstArgumentEnhanced=G,r.useAsync=$,r.useAsyncData=q,r.useAsyncFunction=$,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-asyncx",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "dist/vue-asyncx.d.ts",
@@ -20,7 +20,8 @@
20
20
  "utils",
21
21
  "async",
22
22
  "vueuse",
23
- "hooks"
23
+ "hooks",
24
+ "ahooks"
24
25
  ],
25
26
  "author": "Xu Yiming",
26
27
  "license": "MIT",
@@ -31,6 +32,7 @@
31
32
  "devDependencies": {
32
33
  "@types/node": "^20.14.11",
33
34
  "@vitest/coverage-v8": "^2.0.4",
35
+ "es-toolkit": "^1.42.0",
34
36
  "jsdom": "^24.1.1",
35
37
  "typescript": "^5.5.4",
36
38
  "vite": "^5.3.4",