@aiszlab/relax 1.2.39 → 1.2.41

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.
@@ -1,4 +1,4 @@
1
- import { DOMAttributes } from 'react';
1
+ import { type DOMAttributes } from 'react';
2
2
  type UseHoverBy<T> = {
3
3
  onEnter?: DOMAttributes<T>['onPointerEnter'];
4
4
  onLeave?: DOMAttributes<T>['onPointerLeave'];
@@ -1,7 +1,7 @@
1
- import * as React from 'react';
1
+ import { useRef } from 'react';
2
2
 
3
3
  var useMemorable = function useMemorable(getter, condition, shouldUpdate) {
4
- var cacheRef = React.useRef(null);
4
+ var cacheRef = useRef(null);
5
5
  if (cacheRef.current === null || shouldUpdate(cacheRef.current.condition, condition)) {
6
6
  cacheRef.current = {
7
7
  value: getter(),
@@ -4,4 +4,7 @@
4
4
  * @description
5
5
  * timeout effect
6
6
  */
7
- export declare const useTimeout: (handler: Function, wait: number) => void;
7
+ export declare const useTimeout: (handler: Function, wait: number) => {
8
+ flush: () => void;
9
+ cancel: () => void;
10
+ };
@@ -1,4 +1,6 @@
1
- import { useEffect } from 'react';
1
+ import { useRef, useEffect } from 'react';
2
+ import { Observable, delay } from 'rxjs';
3
+ import { useEvent } from './use-event.js';
2
4
 
3
5
  /**
4
6
  * @author murukal
@@ -7,13 +9,49 @@ import { useEffect } from 'react';
7
9
  * timeout effect
8
10
  */
9
11
  var useTimeout = function useTimeout(handler, wait) {
12
+ var timer = useRef(null);
13
+ var trigger = useRef(null);
14
+ // when user what to flush timeout handler
15
+ // if trigger already registed, just complete trigger
16
+ // not registed, call `handler` manaully
17
+ var flush = useEvent(function () {
18
+ if (trigger.current) {
19
+ var _timer$current;
20
+ trigger.current.complete();
21
+ (_timer$current = timer.current) === null || _timer$current === void 0 || _timer$current.unsubscribe();
22
+ } else {
23
+ handler();
24
+ }
25
+ trigger.current = null;
26
+ timer.current = null;
27
+ });
28
+ // cancel
29
+ var cancel = useEvent(function () {
30
+ var _trigger$current, _timer$current2;
31
+ (_trigger$current = trigger.current) === null || _trigger$current === void 0 || _trigger$current.error();
32
+ (_timer$current2 = timer.current) === null || _timer$current2 === void 0 || _timer$current2.unsubscribe();
33
+ trigger.current = null;
34
+ timer.current = null;
35
+ });
10
36
  useEffect(function () {
11
- var timer = setTimeout(handler, wait);
12
- return function () {
13
- if (!timer) return;
14
- clearTimeout(timer);
15
- };
37
+ // if 0, always mean not need to set timeout
38
+ if (wait <= 0) {
39
+ return;
40
+ }
41
+ var _timer = new Observable(function (_trigger) {
42
+ trigger.current = _trigger;
43
+ _trigger.next();
44
+ }).pipe(delay(wait)).subscribe(function () {
45
+ handler();
46
+ });
47
+ timer.current = _timer;
48
+ // unmount callback
49
+ return cancel;
16
50
  }, [wait]);
51
+ return {
52
+ flush: flush,
53
+ cancel: cancel
54
+ };
17
55
  };
18
56
 
19
57
  export { useTimeout };
@@ -3,5 +3,8 @@
3
3
  * exclude any value from array
4
4
  *
5
5
  * for performance, avoid using `Array.includes`, replace with `Set`
6
+ *
7
+ * @example
8
+ * exclude([1, 2, 3, 4, 5], [2, 4]) // [1, 3, 5]
6
9
  */
7
- export declare const exclude: (value: Array<unknown>, _excludeBy: Array<unknown>) => unknown[];
10
+ export declare const exclude: <T>(value: T[], _excludeBy: Array<unknown>) => T[];
@@ -3,6 +3,9 @@
3
3
  * exclude any value from array
4
4
  *
5
5
  * for performance, avoid using `Array.includes`, replace with `Set`
6
+ *
7
+ * @example
8
+ * exclude([1, 2, 3, 4, 5], [2, 4]) // [1, 3, 5]
6
9
  */
7
10
  var exclude = function exclude(value, _excludeBy) {
8
11
  var excludeBy = new Set(_excludeBy);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * convert to formData
4
+ */
5
+ export declare const toFormData: (data: Record<string, unknown>) => FormData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.39",
3
+ "version": "1.2.41",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {