@aiszlab/relax 1.2.22 → 1.2.24

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.
@@ -16,7 +16,7 @@ const useCounter = (_a = { initialValue: 0, max: Infinity, min: 0 }) => {
16
16
  setCount((prev) => Math.min(max, prev + step));
17
17
  }, [max]);
18
18
  const prev = useCallback((step = 1) => {
19
- setCount((prev) => Math.max(prev - step));
19
+ setCount((prev) => Math.max(min, prev - step));
20
20
  }, [min]);
21
21
  const first = useCallback(() => {
22
22
  setCount(min);
@@ -1,4 +1,3 @@
1
- import { useEvent } from '../hooks/use-event';
2
1
  interface Options {
3
2
  /**
4
3
  * @description
@@ -10,14 +9,14 @@ interface Options {
10
9
  */
11
10
  readonly delay: number;
12
11
  }
13
- type Callable<T, R> = ReturnType<typeof useEvent<[T], R>>;
12
+ type Callable<T, R> = (value: T) => R;
14
13
  /**
15
14
  * @author murukal
16
15
  *
17
16
  * @description
18
17
  * debounce callback
19
18
  */
20
- export declare const useDebounceCallback: <T, R>(_callable: (args_0: T) => R, options?: Options) => {
19
+ export declare const useDebounceCallback: <T, R>(_callable: Callable<T, R>, options?: Options) => {
21
20
  next: (value: T) => void;
22
21
  complete: () => void;
23
22
  cancel: () => void;
@@ -1,3 +1 @@
1
- type Callable<U extends Array<unknown>, R> = (...args: U) => R;
2
- export declare const useEvent: <U extends unknown[], R>(callable: Callable<U, R>) => Callable<U, R>;
3
- export {};
1
+ export declare const useEvent: <T extends Function>(callable: T) => T;
@@ -1,9 +1,9 @@
1
1
  import { useRef, useCallback } from 'react';
2
2
 
3
3
  const useEvent = (callable) => {
4
- const ref = useRef();
4
+ const ref = useRef(callable);
5
5
  ref.current = callable;
6
- return useCallback((...args) => ref.current(...args), []);
6
+ return useCallback(((...args) => ref.current(...args)), []);
7
7
  };
8
8
 
9
9
  export { useEvent };
@@ -1,5 +1,5 @@
1
1
  import { useLayoutEffect } from 'react';
2
- import { callAsEffect } from '../utils/thenable-effect-callback.mjs';
2
+ import { effect } from '../utils/effect.mjs';
3
3
 
4
4
  /**
5
5
  * @author murukal
@@ -9,7 +9,7 @@ import { callAsEffect } from '../utils/thenable-effect-callback.mjs';
9
9
  */
10
10
  const useMount = (callable) => {
11
11
  useLayoutEffect(() => {
12
- return callAsEffect(callable);
12
+ return effect(callable);
13
13
  }, []);
14
14
  };
15
15
 
@@ -1,5 +1,5 @@
1
1
  import { useEffect } from 'react';
2
- import { callAsEffect } from '../utils/thenable-effect-callback.mjs';
2
+ import { effect } from '../utils/effect.mjs';
3
3
 
4
4
  /**
5
5
  * @author murukal
@@ -9,7 +9,7 @@ import { callAsEffect } from '../utils/thenable-effect-callback.mjs';
9
9
  */
10
10
  const useMounted = (callable) => {
11
11
  useEffect(() => {
12
- return callAsEffect(callable);
12
+ return effect(callable);
13
13
  }, []);
14
14
  };
15
15
 
@@ -1,5 +1,5 @@
1
1
  import { type MutableRefObject, type RefCallback } from 'react';
2
- import type { Nullable } from '../utils/null-able';
2
+ import type { Nullable } from '../types';
3
3
  type Refable<T> = RefCallback<T> | MutableRefObject<T>;
4
4
  export declare const useRefs: <T>(...refs: Nullable<Refable<Nullable<T>>>[]) => (trigger: T) => void;
5
5
  export {};
@@ -1,4 +1,3 @@
1
- import { useEvent } from '../hooks/use-event';
2
1
  interface Options {
3
2
  /**
4
3
  * @description
@@ -10,14 +9,14 @@ interface Options {
10
9
  */
11
10
  readonly duration: number;
12
11
  }
13
- type Callable<T, R> = ReturnType<typeof useEvent<[T], R>>;
12
+ type Callable<T, R> = (value: T) => R;
14
13
  /**
15
14
  * @author murukal
16
15
  *
17
16
  * @description
18
17
  * throttle callback
19
18
  */
20
- export declare const useThrottleCallback: <T, R>(_callable: (args_0: T) => R, options?: Options) => {
19
+ export declare const useThrottleCallback: <T, R>(_callable: Callable<T, R>, options?: Options) => {
21
20
  next: (value: T) => void;
22
21
  complete: () => void;
23
22
  cancel: () => void;
@@ -1,4 +1,4 @@
1
- import { Key } from 'react';
1
+ import { type Key } from 'react';
2
2
  /**
3
3
  * @description
4
4
  * toggleable key
@@ -1,3 +1,3 @@
1
1
  import { DependencyList } from 'react';
2
- import { ThenableEffectCallback } from '../utils/thenable-effect-callback';
2
+ import type { ThenableEffectCallback } from '../types';
3
3
  export declare const useUpdateEffect: (callable: ThenableEffectCallback, deps?: DependencyList) => void;
@@ -1,13 +1,13 @@
1
1
  import { useRef, useEffect } from 'react';
2
2
  import { useMounted } from './use-mounted.mjs';
3
- import { callAsEffect } from '../utils/thenable-effect-callback.mjs';
3
+ import { effect } from '../utils/effect.mjs';
4
4
 
5
5
  const useUpdateEffect = (callable, deps) => {
6
6
  const isMounted = useRef(false);
7
7
  useEffect(() => {
8
8
  if (!isMounted.current)
9
9
  return;
10
- return callAsEffect(callable);
10
+ return effect(callable);
11
11
  }, deps);
12
12
  useMounted(() => {
13
13
  isMounted.current = true;
package/dist/index.d.ts CHANGED
@@ -41,10 +41,7 @@ export { isThenable } from './is/is-thenable';
41
41
  * @description
42
42
  * utils
43
43
  */
44
- export { type Nullable } from './utils/null-able';
45
- export { type Partialable } from './utils/partial-able';
46
- export { type RequiredIn } from './utils/required-in';
47
- export { type ThenableEffectCallback, callAsEffect } from './utils/thenable-effect-callback';
44
+ export { effect } from './utils/effect';
48
45
  export { unique, uniqueBy } from './utils/unique';
49
46
  export { range } from './utils/range';
50
47
  export { clamp } from './utils/clamp';
package/dist/index.mjs CHANGED
@@ -29,7 +29,7 @@ export { isOverflow } from './is/is-overflow.mjs';
29
29
  export { isStyleElement } from './is/is-style-element.mjs';
30
30
  export { isFunction } from './is/is-function.mjs';
31
31
  export { isThenable } from './is/is-thenable.mjs';
32
- export { callAsEffect } from './utils/thenable-effect-callback.mjs';
32
+ export { effect } from './utils/effect.mjs';
33
33
  export { unique, uniqueBy } from './utils/unique.mjs';
34
34
  export { range } from './utils/range.mjs';
35
35
  export { clamp } from './utils/clamp.mjs';
@@ -0,0 +1 @@
1
+ export type Arguments<T extends Function> = T extends (...args: infer A) => unknown ? A : never;
@@ -0,0 +1,5 @@
1
+ export type { Arguments } from './arguments';
2
+ export type { Nullable } from './nullable';
3
+ export type { Partialable } from './partialable';
4
+ export type { RequiredIn } from './required-in';
5
+ export type { ThenableEffectCallback } from './thenable-effect-callback';
@@ -4,8 +4,3 @@ import type { EffectCallback } from 'react';
4
4
  * thenable effect callback
5
5
  */
6
6
  export type ThenableEffectCallback = () => ReturnType<EffectCallback> | PromiseLike<ReturnType<EffectCallback>>;
7
- /**
8
- * @description
9
- * call thenable effect callback
10
- */
11
- export declare const callAsEffect: (callable: ThenableEffectCallback) => ReturnType<EffectCallback>;
@@ -1,4 +1,4 @@
1
- import type { Partialable } from '../utils/partial-able';
1
+ import type { Partialable } from '../types';
2
2
  type Callable<R> = (...args: R[]) => void;
3
3
  export declare const chain: <S>(...callbacks: Partialable<Callable<S>>[]) => Callable<S>;
4
4
  export {};
@@ -0,0 +1,7 @@
1
+ import type { EffectCallback } from 'react';
2
+ import type { ThenableEffectCallback } from '../types';
3
+ /**
4
+ * @description
5
+ * call thenable effect
6
+ */
7
+ export declare const effect: (callable: ThenableEffectCallback) => ReturnType<EffectCallback>;
@@ -2,9 +2,9 @@ import { isThenable } from '../is/is-thenable.mjs';
2
2
 
3
3
  /**
4
4
  * @description
5
- * call thenable effect callback
5
+ * call thenable effect
6
6
  */
7
- const callAsEffect = (callable) => {
7
+ const effect = (callable) => {
8
8
  const called = callable();
9
9
  // if result is void
10
10
  if (!called)
@@ -15,4 +15,4 @@ const callAsEffect = (callable) => {
15
15
  return called;
16
16
  };
17
17
 
18
- export { callAsEffect };
18
+ export { effect };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * convert any type data to a array
4
+ */
5
+ export declare const toArray: <T>(value: unknown) => T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.22",
3
+ "version": "1.2.24",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,7 +11,8 @@
11
11
  "./dom": {
12
12
  "types": "./dist/dom/index.d.ts",
13
13
  "default": "./dist/dom/index.mjs"
14
- }
14
+ },
15
+ "./types": "./dist/types/index.d.ts"
15
16
  },
16
17
  "scripts": {
17
18
  "dev": "rollup -c -w",
@@ -33,7 +34,7 @@
33
34
  "@types/react": "^18",
34
35
  "@types/react-dom": "^18",
35
36
  "@types/react-is": "^18",
36
- "rollup": "^3.27.0",
37
+ "rollup": "^4.12.0",
37
38
  "typescript": "^5.1.3"
38
39
  },
39
40
  "peerDependencies": {
File without changes