@aiszlab/relax 1.2.16 → 1.2.17-beta.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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @author murukal
3
+ *
4
+ * @description
5
+ * a number counter with some useful apis
6
+ */
7
+ export declare const useCounter: () => {
8
+ count: number;
9
+ next: () => void;
10
+ prev: () => void;
11
+ first: () => void;
12
+ };
@@ -0,0 +1,28 @@
1
+ import { useState, useCallback } from 'react';
2
+
3
+ /**
4
+ * @author murukal
5
+ *
6
+ * @description
7
+ * a number counter with some useful apis
8
+ */
9
+ const useCounter = () => {
10
+ const [count, setCount] = useState(0);
11
+ const next = useCallback(() => {
12
+ setCount((prev) => prev + 1);
13
+ }, []);
14
+ const prev = useCallback(() => {
15
+ setCount((prev) => prev - 1);
16
+ }, []);
17
+ const first = useCallback(() => {
18
+ setCount(0);
19
+ }, []);
20
+ return {
21
+ count,
22
+ next,
23
+ prev,
24
+ first
25
+ };
26
+ };
27
+
28
+ export { useCounter };
@@ -10,14 +10,14 @@ import { Observable, debounceTime } from 'rxjs';
10
10
  const useDebounceCallback = (callable, { delay = 1000 } = {
11
11
  delay: 1000
12
12
  }) => {
13
- // runner
14
- const runner = useRef();
13
+ // trigger
14
+ const trigger = useRef();
15
15
  // listener
16
16
  const listener = useRef();
17
17
  /// initialze listener function for debouce
18
18
  const initialize = useCallback(() => {
19
19
  listener.current = new Observable((subscriber) => {
20
- runner.current = subscriber;
20
+ trigger.current = subscriber;
21
21
  })
22
22
  .pipe(debounceTime(delay))
23
23
  .subscribe({
@@ -42,12 +42,12 @@ const useDebounceCallback = (callable, { delay = 1000 } = {
42
42
  /// next function has been debounced for hooks user
43
43
  const next = useCallback((value) => {
44
44
  var _a;
45
- (_a = runner.current) === null || _a === void 0 ? void 0 : _a.next(value);
45
+ (_a = trigger.current) === null || _a === void 0 ? void 0 : _a.next(value);
46
46
  }, []);
47
47
  /// flush the debounce
48
48
  const complete = useCallback(() => {
49
49
  var _a;
50
- (_a = runner.current) === null || _a === void 0 ? void 0 : _a.complete();
50
+ (_a = trigger.current) === null || _a === void 0 ? void 0 : _a.complete();
51
51
  }, []);
52
52
  /// cancel only valid in debounce time
53
53
  /// if the callback has been called, it can not be canceled
@@ -33,6 +33,9 @@ const useImageLoader = ({ src }) => {
33
33
  (_a = loader.current) === null || _a === void 0 ? void 0 : _a.error(null);
34
34
  });
35
35
  image.src = src;
36
+ return () => {
37
+ image.remove();
38
+ };
36
39
  }, [src]);
37
40
  return status;
38
41
  };
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export { useRefs } from './hooks/use-refs';
18
18
  export { useToggleable } from './hooks/use-toggleable';
19
19
  export { useEvent } from './hooks/use-event';
20
20
  export { useUpdateEffect } from './hooks/use-update-effect';
21
+ export { useCounter } from './hooks/use-counter';
21
22
  /**
22
23
  * @description
23
24
  * is
@@ -45,3 +46,4 @@ export { type Partialable } from './utils/partial-able';
45
46
  export { type RequiredIn } from './utils/required-in';
46
47
  export { type ThenableEffectCallback, callAsEffect } from './utils/thenable-effect-callback';
47
48
  export { unique, uniqueBy } from './utils/unique';
49
+ export { range } from './utils/range';
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ export { useRefs } from './hooks/use-refs.js';
14
14
  export { useToggleable } from './hooks/use-toggleable.js';
15
15
  export { useEvent } from './hooks/use-event.js';
16
16
  export { useUpdateEffect } from './hooks/use-update-effect.js';
17
+ export { useCounter } from './hooks/use-counter.js';
17
18
  export { isRefable } from './is/is-refable.js';
18
19
  export { isUndefined } from './is/is-undefined.js';
19
20
  export { isStateGetter } from './is/is-state-getter.js';
@@ -30,3 +31,4 @@ export { isFunction } from './is/is-function.js';
30
31
  export { isThenable } from './is/is-thenable.js';
31
32
  export { callAsEffect } from './utils/thenable-effect-callback.js';
32
33
  export { unique, uniqueBy } from './utils/unique.js';
34
+ export { range } from './utils/range.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns an array of numbers, starting at `from` and ending at `to`.
3
+ * @param from number
4
+ * @param to number
5
+ * @returns number[]
6
+ */
7
+ export declare const range: (from: number, to: number) => number[];
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Returns an array of numbers, starting at `from` and ending at `to`.
3
+ * @param from number
4
+ * @param to number
5
+ * @returns number[]
6
+ */
7
+ const range = (from, to) => {
8
+ const length = to - from + 1;
9
+ return Array.from({ length }, (_, index) => index + from);
10
+ };
11
+
12
+ export { range };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.16",
3
+ "version": "1.2.17-beta.1",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {