@varlet/axle 0.13.2 → 1.0.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/lib/use.cjs CHANGED
@@ -36,58 +36,11 @@ var use_exports = {};
36
36
  __export(use_exports, {
37
37
  cleanupCacheBuffer: () => cleanupCacheBuffer,
38
38
  createUseAxle: () => createUseAxle,
39
- normalizeValueGetter: () => normalizeValueGetter,
40
- useAverageProgress: () => useAverageProgress,
41
- useHasLoading: () => useHasLoading,
42
- useValues: () => useValues
39
+ normalizeValueGetter: () => normalizeValueGetter
43
40
  });
44
41
  module.exports = __toCommonJS(use_exports);
45
- var import_vue4 = require("vue");
46
- var import_rattail = require("rattail");
47
-
48
- // src/composables/useAverageProgress.ts
49
42
  var import_vue = require("vue");
50
- function useAverageProgress(...progressCollection) {
51
- const averageProgress = (0, import_vue.ref)(0);
52
- (0, import_vue.watch)(
53
- () => progressCollection.map((progress) => progress.value),
54
- (newProgressCollection) => {
55
- const total = newProgressCollection.reduce((total2, progress) => total2 + progress, 0);
56
- averageProgress.value = total / progressCollection.length;
57
- },
58
- { immediate: true }
59
- );
60
- return averageProgress;
61
- }
62
-
63
- // src/composables/useHasLoading.ts
64
- var import_vue2 = require("vue");
65
- function useHasLoading(...loadings) {
66
- const hasLoading = (0, import_vue2.ref)(false);
67
- (0, import_vue2.watch)(
68
- () => loadings.map((loading) => loading.value),
69
- (newLoadings) => {
70
- hasLoading.value = newLoadings.some(Boolean);
71
- },
72
- { immediate: true }
73
- );
74
- return hasLoading;
75
- }
76
-
77
- // src/composables/useValues.ts
78
- var import_vue3 = require("vue");
79
- function useValues(...valueCollection) {
80
- return (0, import_vue3.computed)({
81
- get: () => valueCollection.map((value) => value.value),
82
- set(values) {
83
- valueCollection.forEach((value, index) => {
84
- value.value = values[index];
85
- });
86
- }
87
- });
88
- }
89
-
90
- // src/use.ts
43
+ var import_rattail = require("rattail");
91
44
  function normalizeValueGetter(valueGetter) {
92
45
  return (0, import_rattail.isFunction)(valueGetter) ? valueGetter() : valueGetter;
93
46
  }
@@ -136,12 +89,12 @@ function createUseAxle(options) {
136
89
  onError = () => {
137
90
  }
138
91
  } = options2;
139
- const value = (0, import_vue4.ref)(initialValue);
140
- const loading = (0, import_vue4.ref)(false);
141
- const error = (0, import_vue4.ref)();
142
- const downloadProgress = (0, import_vue4.ref)(0);
143
- const uploadProgress = (0, import_vue4.ref)(0);
144
- const pollingCanceled = (0, import_vue4.ref)(false);
92
+ const value = (0, import_vue.ref)(initialValue);
93
+ const loading = (0, import_vue.ref)(false);
94
+ const error = (0, import_vue.ref)();
95
+ const downloadProgress = (0, import_vue.ref)(0);
96
+ const uploadProgress = (0, import_vue.ref)(0);
97
+ const pollingCanceled = (0, import_vue.ref)(false);
145
98
  const refs = {
146
99
  value,
147
100
  loading,
@@ -268,29 +221,29 @@ function createUseAxle(options) {
268
221
  if (immediate) {
269
222
  runWithInitialConfig();
270
223
  }
271
- if ((0, import_vue4.getCurrentInstance)()) {
272
- (0, import_vue4.onActivated)(() => {
224
+ if ((0, import_vue.getCurrentInstance)()) {
225
+ (0, import_vue.onActivated)(() => {
273
226
  deactivated = false;
274
227
  addVisibilityChangeListener();
275
228
  addWindowFocusListener();
276
229
  startPolling();
277
230
  });
278
- (0, import_vue4.onMounted)(() => {
231
+ (0, import_vue.onMounted)(() => {
279
232
  addVisibilityChangeListener();
280
233
  addWindowFocusListener();
281
234
  });
282
- (0, import_vue4.onDeactivated)(() => {
235
+ (0, import_vue.onDeactivated)(() => {
283
236
  deactivated = true;
284
237
  removeVisibilityChangeListener();
285
238
  removeWindowFocusListener();
286
239
  clearPolling();
287
240
  });
288
- (0, import_vue4.onUnmounted)(() => {
241
+ (0, import_vue.onUnmounted)(() => {
289
242
  removeVisibilityChangeListener();
290
243
  removeWindowFocusListener();
291
244
  cancelPolling();
292
245
  });
293
- (0, import_vue4.onUnmounted)(() => {
246
+ (0, import_vue.onUnmounted)(() => {
294
247
  unmounted = true;
295
248
  if (abortOnUnmount) {
296
249
  abort();
@@ -300,7 +253,7 @@ function createUseAxle(options) {
300
253
  const normalizedWatchOptions = watchOptions === true ? { params: true, config: true } : __spreadValues({ params: false, config: false }, watchOptions);
301
254
  const enableWatchParams = (0, import_rattail.isFunction)(initialParamsOrGetter) && normalizedWatchOptions.params;
302
255
  const enableWatchConfig = (0, import_rattail.isFunction)(initialConfigOrGetter) && normalizedWatchOptions.config;
303
- (0, import_vue4.watch)(
256
+ (0, import_vue.watch)(
304
257
  () => [
305
258
  enableWatchParams ? normalizeValueGetter(initialParamsOrGetter) : void 0,
306
259
  enableWatchConfig ? normalizeValueGetter(initialConfigOrGetter) : void 0,
@@ -394,8 +347,5 @@ function createUseAxle(options) {
394
347
  0 && (module.exports = {
395
348
  cleanupCacheBuffer,
396
349
  createUseAxle,
397
- normalizeValueGetter,
398
- useAverageProgress,
399
- useHasLoading,
400
- useValues
350
+ normalizeValueGetter
401
351
  });
package/lib/use.d.cts CHANGED
@@ -1,13 +1,7 @@
1
- import { Ref, WritableComputedRef } from 'vue';
1
+ import { Ref } from 'vue';
2
2
  import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-857fe07c.js';
3
3
  import 'axios';
4
4
 
5
- declare function useAverageProgress(...progressCollection: Ref<number>[]): Ref<number>;
6
-
7
- declare function useHasLoading(...loadings: Ref<boolean>[]): Ref<boolean>;
8
-
9
- declare function useValues<T extends Ref<any>[]>(...valueCollection: T): WritableComputedRef<T[number]['value'][]>;
10
-
11
5
  type Runnable = () => boolean;
12
6
  interface RunOptions<V, P, D> {
13
7
  url?: string;
@@ -88,4 +82,4 @@ declare function normalizeValueGetter<T>(valueGetter: T | (() => T)): T;
88
82
  declare function cleanupCacheBuffer(): void;
89
83
  declare function createUseAxle(options: CreateUseAxleOptions): UseAxle;
90
84
 
91
- export { CreateUseAxleOptions, ResetValueOptions, Run, RunOptions, Runnable, UseAxle, UseAxleExtra, UseAxleInstance, UseAxleOptions, UseAxleOptionsWithRunnable, UseAxleRefs, WatchOptions, cleanupCacheBuffer, createUseAxle, normalizeValueGetter, useAverageProgress, useHasLoading, useValues };
85
+ export { CreateUseAxleOptions, ResetValueOptions, Run, RunOptions, Runnable, UseAxle, UseAxleExtra, UseAxleInstance, UseAxleOptions, UseAxleOptionsWithRunnable, UseAxleRefs, WatchOptions, cleanupCacheBuffer, createUseAxle, normalizeValueGetter };
package/lib/use.d.ts CHANGED
@@ -1,13 +1,7 @@
1
- import { Ref, WritableComputedRef } from 'vue';
1
+ import { Ref } from 'vue';
2
2
  import { A as AxleRequestConfig, d as RunnerMethod, e as AxleInstance } from './instance-857fe07c.js';
3
3
  import 'axios';
4
4
 
5
- declare function useAverageProgress(...progressCollection: Ref<number>[]): Ref<number>;
6
-
7
- declare function useHasLoading(...loadings: Ref<boolean>[]): Ref<boolean>;
8
-
9
- declare function useValues<T extends Ref<any>[]>(...valueCollection: T): WritableComputedRef<T[number]['value'][]>;
10
-
11
5
  type Runnable = () => boolean;
12
6
  interface RunOptions<V, P, D> {
13
7
  url?: string;
@@ -88,4 +82,4 @@ declare function normalizeValueGetter<T>(valueGetter: T | (() => T)): T;
88
82
  declare function cleanupCacheBuffer(): void;
89
83
  declare function createUseAxle(options: CreateUseAxleOptions): UseAxle;
90
84
 
91
- export { CreateUseAxleOptions, ResetValueOptions, Run, RunOptions, Runnable, UseAxle, UseAxleExtra, UseAxleInstance, UseAxleOptions, UseAxleOptionsWithRunnable, UseAxleRefs, WatchOptions, cleanupCacheBuffer, createUseAxle, normalizeValueGetter, useAverageProgress, useHasLoading, useValues };
85
+ export { CreateUseAxleOptions, ResetValueOptions, Run, RunOptions, Runnable, UseAxle, UseAxleExtra, UseAxleInstance, UseAxleOptions, UseAxleOptionsWithRunnable, UseAxleRefs, WatchOptions, cleanupCacheBuffer, createUseAxle, normalizeValueGetter };
package/lib/use.js CHANGED
@@ -3,52 +3,8 @@ import {
3
3
  } from "./chunk-G2ADBYYC.js";
4
4
 
5
5
  // src/use.ts
6
- import { getCurrentInstance, onActivated, onDeactivated, onMounted, onUnmounted, ref as ref3, watch as watch3 } from "vue";
6
+ import { getCurrentInstance, onActivated, onDeactivated, onMounted, onUnmounted, ref, watch } from "vue";
7
7
  import { isFunction } from "rattail";
8
-
9
- // src/composables/useAverageProgress.ts
10
- import { ref, watch } from "vue";
11
- function useAverageProgress(...progressCollection) {
12
- const averageProgress = ref(0);
13
- watch(
14
- () => progressCollection.map((progress) => progress.value),
15
- (newProgressCollection) => {
16
- const total = newProgressCollection.reduce((total2, progress) => total2 + progress, 0);
17
- averageProgress.value = total / progressCollection.length;
18
- },
19
- { immediate: true }
20
- );
21
- return averageProgress;
22
- }
23
-
24
- // src/composables/useHasLoading.ts
25
- import { ref as ref2, watch as watch2 } from "vue";
26
- function useHasLoading(...loadings) {
27
- const hasLoading = ref2(false);
28
- watch2(
29
- () => loadings.map((loading) => loading.value),
30
- (newLoadings) => {
31
- hasLoading.value = newLoadings.some(Boolean);
32
- },
33
- { immediate: true }
34
- );
35
- return hasLoading;
36
- }
37
-
38
- // src/composables/useValues.ts
39
- import { computed } from "vue";
40
- function useValues(...valueCollection) {
41
- return computed({
42
- get: () => valueCollection.map((value) => value.value),
43
- set(values) {
44
- valueCollection.forEach((value, index) => {
45
- value.value = values[index];
46
- });
47
- }
48
- });
49
- }
50
-
51
- // src/use.ts
52
8
  function normalizeValueGetter(valueGetter) {
53
9
  return isFunction(valueGetter) ? valueGetter() : valueGetter;
54
10
  }
@@ -97,12 +53,12 @@ function createUseAxle(options) {
97
53
  onError = () => {
98
54
  }
99
55
  } = options2;
100
- const value = ref3(initialValue);
101
- const loading = ref3(false);
102
- const error = ref3();
103
- const downloadProgress = ref3(0);
104
- const uploadProgress = ref3(0);
105
- const pollingCanceled = ref3(false);
56
+ const value = ref(initialValue);
57
+ const loading = ref(false);
58
+ const error = ref();
59
+ const downloadProgress = ref(0);
60
+ const uploadProgress = ref(0);
61
+ const pollingCanceled = ref(false);
106
62
  const refs = {
107
63
  value,
108
64
  loading,
@@ -261,7 +217,7 @@ function createUseAxle(options) {
261
217
  const normalizedWatchOptions = watchOptions === true ? { params: true, config: true } : __spreadValues({ params: false, config: false }, watchOptions);
262
218
  const enableWatchParams = isFunction(initialParamsOrGetter) && normalizedWatchOptions.params;
263
219
  const enableWatchConfig = isFunction(initialConfigOrGetter) && normalizedWatchOptions.config;
264
- watch3(
220
+ watch(
265
221
  () => [
266
222
  enableWatchParams ? normalizeValueGetter(initialParamsOrGetter) : void 0,
267
223
  enableWatchConfig ? normalizeValueGetter(initialConfigOrGetter) : void 0,
@@ -354,8 +310,5 @@ function createUseAxle(options) {
354
310
  export {
355
311
  cleanupCacheBuffer,
356
312
  createUseAxle,
357
- normalizeValueGetter,
358
- useAverageProgress,
359
- useHasLoading,
360
- useValues
313
+ normalizeValueGetter
361
314
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/axle",
3
- "version": "0.13.2",
3
+ "version": "1.0.0",
4
4
  "description": "Progressive request tool based on axios",
5
5
  "keywords": [
6
6
  "axle",