@varlet/axle 0.12.0 → 0.13.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/lib/use.cjs CHANGED
@@ -118,6 +118,7 @@ function createUseAxle(options) {
118
118
  pollingInterval,
119
119
  pollingOnHidden = true,
120
120
  pollingOnDeactivated = false,
121
+ refreshOnWindowFocus = false,
121
122
  value: initialValue,
122
123
  resetValue: initialResetValue,
123
124
  cloneResetValue: initialCloneResetValue,
@@ -164,9 +165,10 @@ function createUseAxle(options) {
164
165
  let pollingTimer = null;
165
166
  let deactivated = false;
166
167
  let hidden = false;
168
+ let unmounted = false;
167
169
  const run = Object.assign(async (options3 = {}) => {
168
170
  var _a, _b, _c, _d, _e;
169
- if (!runnable()) {
171
+ if (!runnable() || unmounted) {
170
172
  return;
171
173
  }
172
174
  pollingCanceled.value = false;
@@ -270,25 +272,30 @@ function createUseAxle(options) {
270
272
  (0, import_vue4.onActivated)(() => {
271
273
  deactivated = false;
272
274
  addVisibilityChangeListener();
275
+ addWindowFocusListener();
273
276
  startPolling();
274
277
  });
275
278
  (0, import_vue4.onMounted)(() => {
276
279
  addVisibilityChangeListener();
280
+ addWindowFocusListener();
277
281
  });
278
282
  (0, import_vue4.onDeactivated)(() => {
279
283
  deactivated = true;
280
284
  removeVisibilityChangeListener();
285
+ removeWindowFocusListener();
281
286
  clearPolling();
282
287
  });
283
288
  (0, import_vue4.onUnmounted)(() => {
284
289
  removeVisibilityChangeListener();
290
+ removeWindowFocusListener();
285
291
  cancelPolling();
286
292
  });
287
- if (abortOnUnmount) {
288
- (0, import_vue4.onUnmounted)(() => {
293
+ (0, import_vue4.onUnmounted)(() => {
294
+ unmounted = true;
295
+ if (abortOnUnmount) {
289
296
  abort();
290
- });
291
- }
297
+ }
298
+ });
292
299
  if (watchOptions) {
293
300
  const normalizedWatchOptions = watchOptions === true ? { params: true, config: true } : __spreadValues({ params: false, config: false }, watchOptions);
294
301
  const enableWatchParams = (0, import_rattail.isFunction)(initialParamsOrGetter) && normalizedWatchOptions.params;
@@ -301,8 +308,7 @@ function createUseAxle(options) {
301
308
  ],
302
309
  () => {
303
310
  runWithInitialConfig();
304
- },
305
- { deep: true }
311
+ }
306
312
  );
307
313
  }
308
314
  }
@@ -322,6 +328,21 @@ function createUseAxle(options) {
322
328
  function abort() {
323
329
  controller.abort();
324
330
  }
331
+ function addWindowFocusListener() {
332
+ if (typeof window !== "undefined") {
333
+ window.addEventListener("focus", handleWindowFocus);
334
+ }
335
+ }
336
+ function removeWindowFocusListener() {
337
+ if (typeof window !== "undefined") {
338
+ window.removeEventListener("focus", handleWindowFocus);
339
+ }
340
+ }
341
+ function handleWindowFocus() {
342
+ if (refreshOnWindowFocus) {
343
+ runWithInitialConfig();
344
+ }
345
+ }
325
346
  function addVisibilityChangeListener() {
326
347
  if (typeof document !== "undefined") {
327
348
  document.addEventListener("visibilitychange", handleVisibilityChange);
package/lib/use.d.cts CHANGED
@@ -58,6 +58,7 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<s
58
58
  pollingInterval?: number;
59
59
  pollingOnHidden?: boolean;
60
60
  pollingOnDeactivated?: boolean;
61
+ refreshOnWindowFocus?: boolean;
61
62
  params?: P | (() => P);
62
63
  onBefore?(refs: UseAxleRefs<V>): void;
63
64
  onAfter?(refs: UseAxleRefs<V>): void;
package/lib/use.d.ts CHANGED
@@ -58,6 +58,7 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<s
58
58
  pollingInterval?: number;
59
59
  pollingOnHidden?: boolean;
60
60
  pollingOnDeactivated?: boolean;
61
+ refreshOnWindowFocus?: boolean;
61
62
  params?: P | (() => P);
62
63
  onBefore?(refs: UseAxleRefs<V>): void;
63
64
  onAfter?(refs: UseAxleRefs<V>): void;
package/lib/use.js CHANGED
@@ -79,6 +79,7 @@ function createUseAxle(options) {
79
79
  pollingInterval,
80
80
  pollingOnHidden = true,
81
81
  pollingOnDeactivated = false,
82
+ refreshOnWindowFocus = false,
82
83
  value: initialValue,
83
84
  resetValue: initialResetValue,
84
85
  cloneResetValue: initialCloneResetValue,
@@ -125,9 +126,10 @@ function createUseAxle(options) {
125
126
  let pollingTimer = null;
126
127
  let deactivated = false;
127
128
  let hidden = false;
129
+ let unmounted = false;
128
130
  const run = Object.assign(async (options3 = {}) => {
129
131
  var _a, _b, _c, _d, _e;
130
- if (!runnable()) {
132
+ if (!runnable() || unmounted) {
131
133
  return;
132
134
  }
133
135
  pollingCanceled.value = false;
@@ -231,25 +233,30 @@ function createUseAxle(options) {
231
233
  onActivated(() => {
232
234
  deactivated = false;
233
235
  addVisibilityChangeListener();
236
+ addWindowFocusListener();
234
237
  startPolling();
235
238
  });
236
239
  onMounted(() => {
237
240
  addVisibilityChangeListener();
241
+ addWindowFocusListener();
238
242
  });
239
243
  onDeactivated(() => {
240
244
  deactivated = true;
241
245
  removeVisibilityChangeListener();
246
+ removeWindowFocusListener();
242
247
  clearPolling();
243
248
  });
244
249
  onUnmounted(() => {
245
250
  removeVisibilityChangeListener();
251
+ removeWindowFocusListener();
246
252
  cancelPolling();
247
253
  });
248
- if (abortOnUnmount) {
249
- onUnmounted(() => {
254
+ onUnmounted(() => {
255
+ unmounted = true;
256
+ if (abortOnUnmount) {
250
257
  abort();
251
- });
252
- }
258
+ }
259
+ });
253
260
  if (watchOptions) {
254
261
  const normalizedWatchOptions = watchOptions === true ? { params: true, config: true } : __spreadValues({ params: false, config: false }, watchOptions);
255
262
  const enableWatchParams = isFunction(initialParamsOrGetter) && normalizedWatchOptions.params;
@@ -262,8 +269,7 @@ function createUseAxle(options) {
262
269
  ],
263
270
  () => {
264
271
  runWithInitialConfig();
265
- },
266
- { deep: true }
272
+ }
267
273
  );
268
274
  }
269
275
  }
@@ -283,6 +289,21 @@ function createUseAxle(options) {
283
289
  function abort() {
284
290
  controller.abort();
285
291
  }
292
+ function addWindowFocusListener() {
293
+ if (typeof window !== "undefined") {
294
+ window.addEventListener("focus", handleWindowFocus);
295
+ }
296
+ }
297
+ function removeWindowFocusListener() {
298
+ if (typeof window !== "undefined") {
299
+ window.removeEventListener("focus", handleWindowFocus);
300
+ }
301
+ }
302
+ function handleWindowFocus() {
303
+ if (refreshOnWindowFocus) {
304
+ runWithInitialConfig();
305
+ }
306
+ }
286
307
  function addVisibilityChangeListener() {
287
308
  if (typeof document !== "undefined") {
288
309
  document.addEventListener("visibilitychange", handleVisibilityChange);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/axle",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
4
4
  "description": "Progressive request tool based on axios",
5
5
  "keywords": [
6
6
  "axle",