@varlet/axle 0.12.0 → 0.13.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
@@ -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,
@@ -270,18 +271,22 @@ function createUseAxle(options) {
270
271
  (0, import_vue4.onActivated)(() => {
271
272
  deactivated = false;
272
273
  addVisibilityChangeListener();
274
+ addWindowFocusListener();
273
275
  startPolling();
274
276
  });
275
277
  (0, import_vue4.onMounted)(() => {
276
278
  addVisibilityChangeListener();
279
+ addWindowFocusListener();
277
280
  });
278
281
  (0, import_vue4.onDeactivated)(() => {
279
282
  deactivated = true;
280
283
  removeVisibilityChangeListener();
284
+ removeWindowFocusListener();
281
285
  clearPolling();
282
286
  });
283
287
  (0, import_vue4.onUnmounted)(() => {
284
288
  removeVisibilityChangeListener();
289
+ removeWindowFocusListener();
285
290
  cancelPolling();
286
291
  });
287
292
  if (abortOnUnmount) {
@@ -301,8 +306,7 @@ function createUseAxle(options) {
301
306
  ],
302
307
  () => {
303
308
  runWithInitialConfig();
304
- },
305
- { deep: true }
309
+ }
306
310
  );
307
311
  }
308
312
  }
@@ -322,6 +326,21 @@ function createUseAxle(options) {
322
326
  function abort() {
323
327
  controller.abort();
324
328
  }
329
+ function addWindowFocusListener() {
330
+ if (typeof window !== "undefined") {
331
+ window.addEventListener("focus", handleWindowFocus);
332
+ }
333
+ }
334
+ function removeWindowFocusListener() {
335
+ if (typeof window !== "undefined") {
336
+ window.removeEventListener("focus", handleWindowFocus);
337
+ }
338
+ }
339
+ function handleWindowFocus() {
340
+ if (refreshOnWindowFocus) {
341
+ runWithInitialConfig();
342
+ }
343
+ }
325
344
  function addVisibilityChangeListener() {
326
345
  if (typeof document !== "undefined") {
327
346
  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,
@@ -231,18 +232,22 @@ function createUseAxle(options) {
231
232
  onActivated(() => {
232
233
  deactivated = false;
233
234
  addVisibilityChangeListener();
235
+ addWindowFocusListener();
234
236
  startPolling();
235
237
  });
236
238
  onMounted(() => {
237
239
  addVisibilityChangeListener();
240
+ addWindowFocusListener();
238
241
  });
239
242
  onDeactivated(() => {
240
243
  deactivated = true;
241
244
  removeVisibilityChangeListener();
245
+ removeWindowFocusListener();
242
246
  clearPolling();
243
247
  });
244
248
  onUnmounted(() => {
245
249
  removeVisibilityChangeListener();
250
+ removeWindowFocusListener();
246
251
  cancelPolling();
247
252
  });
248
253
  if (abortOnUnmount) {
@@ -262,8 +267,7 @@ function createUseAxle(options) {
262
267
  ],
263
268
  () => {
264
269
  runWithInitialConfig();
265
- },
266
- { deep: true }
270
+ }
267
271
  );
268
272
  }
269
273
  }
@@ -283,6 +287,21 @@ function createUseAxle(options) {
283
287
  function abort() {
284
288
  controller.abort();
285
289
  }
290
+ function addWindowFocusListener() {
291
+ if (typeof window !== "undefined") {
292
+ window.addEventListener("focus", handleWindowFocus);
293
+ }
294
+ }
295
+ function removeWindowFocusListener() {
296
+ if (typeof window !== "undefined") {
297
+ window.removeEventListener("focus", handleWindowFocus);
298
+ }
299
+ }
300
+ function handleWindowFocus() {
301
+ if (refreshOnWindowFocus) {
302
+ runWithInitialConfig();
303
+ }
304
+ }
286
305
  function addVisibilityChangeListener() {
287
306
  if (typeof document !== "undefined") {
288
307
  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.0",
4
4
  "description": "Progressive request tool based on axios",
5
5
  "keywords": [
6
6
  "axle",