@aiszlab/relax 1.3.16 → 1.3.18

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,63 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+ var react = require('react');
5
+ var useDebounceCallback = require('./use-debounce-callback.cjs');
6
+ var useMounted = require('./use-mounted.cjs');
7
+
8
+ /**
9
+ * @description
10
+ * listen parent size change
11
+ * provider with\height to child
12
+ */
13
+ var useParentSize = function useParentSize() {
14
+ var parentRef = react.useRef(null);
15
+ var _useState = react.useState(0),
16
+ _useState2 = _slicedToArray(_useState, 2),
17
+ width = _useState2[0],
18
+ setWidth = _useState2[1];
19
+ var _useState3 = react.useState(0),
20
+ _useState4 = _slicedToArray(_useState3, 2),
21
+ height = _useState4[0],
22
+ setHeight = _useState4[1];
23
+ var _animation = react.useRef(0);
24
+ var _useDebounceCallback = useDebounceCallback.useDebounceCallback(function (_ref) {
25
+ var width = _ref.width,
26
+ height = _ref.height;
27
+ setWidth(width);
28
+ setHeight(height);
29
+ }, 300),
30
+ resize = _useDebounceCallback.next,
31
+ abort = _useDebounceCallback.abort;
32
+ useMounted.useMounted(function () {
33
+ var resizer = new ResizeObserver(function (entries) {
34
+ entries.forEach(function (entry) {
35
+ var _entry$contentRect;
36
+ var _ref2 = (_entry$contentRect = entry === null || entry === void 0 ? void 0 : entry.contentRect) !== null && _entry$contentRect !== void 0 ? _entry$contentRect : {},
37
+ width = _ref2.width,
38
+ height = _ref2.height;
39
+ _animation.current = window.requestAnimationFrame(function () {
40
+ resize({
41
+ width: width,
42
+ height: height
43
+ });
44
+ });
45
+ });
46
+ });
47
+ if (parentRef.current) {
48
+ resizer.observe(parentRef.current);
49
+ }
50
+ return function () {
51
+ cancelAnimationFrame(_animation.current);
52
+ resizer.disconnect();
53
+ abort();
54
+ };
55
+ });
56
+ return {
57
+ parentRef: parentRef,
58
+ width: width,
59
+ height: height
60
+ };
61
+ };
62
+
63
+ exports.useParentSize = useParentSize;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description
3
+ * listen parent size change
4
+ * provider with\height to child
5
+ */
6
+ export declare const useParentSize: <T extends HTMLElement = HTMLDivElement>() => {
7
+ parentRef: import("react").RefObject<T>;
8
+ width: number;
9
+ height: number;
10
+ };
@@ -0,0 +1,61 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
+ import { useRef, useState } from 'react';
3
+ import { useDebounceCallback } from './use-debounce-callback.mjs';
4
+ import { useMounted } from './use-mounted.mjs';
5
+
6
+ /**
7
+ * @description
8
+ * listen parent size change
9
+ * provider with\height to child
10
+ */
11
+ var useParentSize = function useParentSize() {
12
+ var parentRef = useRef(null);
13
+ var _useState = useState(0),
14
+ _useState2 = _slicedToArray(_useState, 2),
15
+ width = _useState2[0],
16
+ setWidth = _useState2[1];
17
+ var _useState3 = useState(0),
18
+ _useState4 = _slicedToArray(_useState3, 2),
19
+ height = _useState4[0],
20
+ setHeight = _useState4[1];
21
+ var _animation = useRef(0);
22
+ var _useDebounceCallback = useDebounceCallback(function (_ref) {
23
+ var width = _ref.width,
24
+ height = _ref.height;
25
+ setWidth(width);
26
+ setHeight(height);
27
+ }, 300),
28
+ resize = _useDebounceCallback.next,
29
+ abort = _useDebounceCallback.abort;
30
+ useMounted(function () {
31
+ var resizer = new ResizeObserver(function (entries) {
32
+ entries.forEach(function (entry) {
33
+ var _entry$contentRect;
34
+ var _ref2 = (_entry$contentRect = entry === null || entry === void 0 ? void 0 : entry.contentRect) !== null && _entry$contentRect !== void 0 ? _entry$contentRect : {},
35
+ width = _ref2.width,
36
+ height = _ref2.height;
37
+ _animation.current = window.requestAnimationFrame(function () {
38
+ resize({
39
+ width: width,
40
+ height: height
41
+ });
42
+ });
43
+ });
44
+ });
45
+ if (parentRef.current) {
46
+ resizer.observe(parentRef.current);
47
+ }
48
+ return function () {
49
+ cancelAnimationFrame(_animation.current);
50
+ resizer.disconnect();
51
+ abort();
52
+ };
53
+ });
54
+ return {
55
+ parentRef: parentRef,
56
+ width: width,
57
+ height: height
58
+ };
59
+ };
60
+
61
+ export { useParentSize };
@@ -9,8 +9,7 @@ var useEvent = require('./use-event.cjs');
9
9
  */
10
10
  var useRaf = function useRaf(_callback) {
11
11
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
12
- _ref$timely = _ref.timely,
13
- timely = _ref$timely === void 0 ? false : _ref$timely;
12
+ timely = _ref.timely;
14
13
  var callback = useEvent.useEvent(_callback);
15
14
  var timed = react.useRef(null);
16
15
  var isTimed = react.useRef(false);
@@ -1,7 +1,20 @@
1
+ type UsingRaf = [
2
+ _callback: Function,
3
+ {
4
+ /**
5
+ * @description
6
+ * run callback immediately
7
+ * if `timely` is true, run callback immediately
8
+ * otherwise, wait for next frame
9
+ */
10
+ timely?: boolean;
11
+ }?
12
+ ];
13
+ type UsedRaf = () => void;
14
+ type UseRaf = (...args: UsingRaf) => UsedRaf;
1
15
  /**
2
16
  * @description
3
17
  * raf
4
18
  */
5
- export declare const useRaf: (_callback: Function, { timely, }?: {
6
- timely?: boolean;
7
- }) => () => void;
19
+ export declare const useRaf: UseRaf;
20
+ export {};
@@ -7,8 +7,7 @@ import { useEvent } from './use-event.mjs';
7
7
  */
8
8
  var useRaf = function useRaf(_callback) {
9
9
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
10
- _ref$timely = _ref.timely,
11
- timely = _ref$timely === void 0 ? false : _ref$timely;
10
+ timely = _ref.timely;
12
11
  var callback = useEvent(_callback);
13
12
  var timed = useRef(null);
14
13
  var isTimed = useRef(false);
@@ -1,3 +1,3 @@
1
1
  import type { Nullable, Voidable } from "@aiszlab/relax/types";
2
- import { type Refable } from "../react";
2
+ import { type Refable } from "../react/mount-ref";
3
3
  export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (reference: T) => void;
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+ var react = require('react');
5
+ var isDomUsable = require('../is/is-dom-usable.cjs');
6
+ var useDebounceCallback = require('./use-debounce-callback.cjs');
7
+ var useMounted = require('./use-mounted.cjs');
8
+
9
+ /**
10
+ * @description
11
+ * Use the current screen size.
12
+ */
13
+ var useScreenSize = function useScreenSize() {
14
+ var _useState = react.useState(function () {
15
+ if (!isDomUsable.isDomUsable()) return {
16
+ width: 0,
17
+ height: 0
18
+ };
19
+ return {
20
+ width: window.innerWidth,
21
+ height: window.innerHeight
22
+ };
23
+ }),
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ size = _useState2[0],
26
+ setSize = _useState2[1];
27
+ var _useDebounceCallback = useDebounceCallback.useDebounceCallback(function () {
28
+ setSize({
29
+ width: window.innerWidth,
30
+ height: window.innerHeight
31
+ });
32
+ }, 300),
33
+ resize = _useDebounceCallback.next,
34
+ abort = _useDebounceCallback.abort;
35
+ useMounted.useMounted(function () {
36
+ window.addEventListener("resize", resize);
37
+ return function () {
38
+ window.removeEventListener("resize", resize);
39
+ abort();
40
+ };
41
+ });
42
+ return size;
43
+ };
44
+
45
+ exports.useScreenSize = useScreenSize;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @description
3
+ * Use the current screen size.
4
+ */
5
+ export declare const useScreenSize: () => {
6
+ width: number;
7
+ height: number;
8
+ };
@@ -0,0 +1,43 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
+ import { useState } from 'react';
3
+ import { isDomUsable } from '../is/is-dom-usable.mjs';
4
+ import { useDebounceCallback } from './use-debounce-callback.mjs';
5
+ import { useMounted } from './use-mounted.mjs';
6
+
7
+ /**
8
+ * @description
9
+ * Use the current screen size.
10
+ */
11
+ var useScreenSize = function useScreenSize() {
12
+ var _useState = useState(function () {
13
+ if (!isDomUsable()) return {
14
+ width: 0,
15
+ height: 0
16
+ };
17
+ return {
18
+ width: window.innerWidth,
19
+ height: window.innerHeight
20
+ };
21
+ }),
22
+ _useState2 = _slicedToArray(_useState, 2),
23
+ size = _useState2[0],
24
+ setSize = _useState2[1];
25
+ var _useDebounceCallback = useDebounceCallback(function () {
26
+ setSize({
27
+ width: window.innerWidth,
28
+ height: window.innerHeight
29
+ });
30
+ }, 300),
31
+ resize = _useDebounceCallback.next,
32
+ abort = _useDebounceCallback.abort;
33
+ useMounted(function () {
34
+ window.addEventListener("resize", resize);
35
+ return function () {
36
+ window.removeEventListener("resize", resize);
37
+ abort();
38
+ };
39
+ });
40
+ return size;
41
+ };
42
+
43
+ export { useScreenSize };
package/dist/index.cjs CHANGED
@@ -33,6 +33,8 @@ var useSessionStorageState = require('./hooks/use-session-storage-state.cjs');
33
33
  var useIsMounted = require('./hooks/use-is-mounted.cjs');
34
34
  var useInfiniteScroll = require('./hooks/use-infinite-scroll.cjs');
35
35
  var useReactive = require('./hooks/use-reactive.cjs');
36
+ var useParentSize = require('./hooks/use-parent-size.cjs');
37
+ var useScreenSize = require('./hooks/use-screen-size.cjs');
36
38
  var isRefable = require('./is/is-refable.cjs');
37
39
  var isUndefined = require('./is/is-undefined.cjs');
38
40
  var isNull = require('./is/is-null.cjs');
@@ -50,6 +52,7 @@ var isHtmlInputElement = require('./is/is-html-input-element.cjs');
50
52
  var isObject = require('./is/is-object.cjs');
51
53
  var effect = require('./utils/effect.cjs');
52
54
  var unique = require('./utils/unique.cjs');
55
+ var uniqueBy = require('./utils/unique-by.cjs');
53
56
  var range = require('./utils/range.cjs');
54
57
  var clamp = require('./utils/clamp.cjs');
55
58
  var chain = require('./utils/chain.cjs');
@@ -104,6 +107,8 @@ exports.useSessionStorageState = useSessionStorageState.useSessionStorageState;
104
107
  exports.useIsMounted = useIsMounted.useIsMounted;
105
108
  exports.useInfiniteScroll = useInfiniteScroll.useInfiniteScroll;
106
109
  exports.useReactive = useReactive.useReactive;
110
+ exports.useParentSize = useParentSize.useParentSize;
111
+ exports.useScreenSize = useScreenSize.useScreenSize;
107
112
  exports.isRefable = isRefable.isRefable;
108
113
  exports.isUndefined = isUndefined.isUndefined;
109
114
  exports.isNull = isNull.isNull;
@@ -121,7 +126,7 @@ exports.isHTMLInputElement = isHtmlInputElement.isHTMLInputElement;
121
126
  exports.isObject = isObject.isObject;
122
127
  exports.effect = effect.effect;
123
128
  exports.unique = unique.unique;
124
- exports.uniqueBy = unique.uniqueBy;
129
+ exports.uniqueBy = uniqueBy.uniqueBy;
125
130
  exports.range = range.range;
126
131
  exports.clamp = clamp.clamp;
127
132
  exports.chain = chain.chain;
package/dist/index.d.ts CHANGED
@@ -35,6 +35,8 @@ export { useSessionStorageState } from "./hooks/use-session-storage-state";
35
35
  export { useIsMounted } from "./hooks/use-is-mounted";
36
36
  export { useInfiniteScroll } from "./hooks/use-infinite-scroll";
37
37
  export { useReactive } from "./hooks/use-reactive";
38
+ export { useParentSize } from "./hooks/use-parent-size";
39
+ export { useScreenSize } from "./hooks/use-screen-size";
38
40
  /**
39
41
  * @description
40
42
  * is
@@ -59,7 +61,8 @@ export { isObject } from "./is/is-object";
59
61
  * utils
60
62
  */
61
63
  export { effect } from "./utils/effect";
62
- export { unique, uniqueBy } from "./utils/unique";
64
+ export { unique } from "./utils/unique";
65
+ export { uniqueBy } from "./utils/unique-by";
63
66
  export { range } from "./utils/range";
64
67
  export { clamp } from "./utils/clamp";
65
68
  export { chain } from "./utils/chain";
package/dist/index.mjs CHANGED
@@ -31,6 +31,8 @@ export { useSessionStorageState } from './hooks/use-session-storage-state.mjs';
31
31
  export { useIsMounted } from './hooks/use-is-mounted.mjs';
32
32
  export { useInfiniteScroll } from './hooks/use-infinite-scroll.mjs';
33
33
  export { useReactive } from './hooks/use-reactive.mjs';
34
+ export { useParentSize } from './hooks/use-parent-size.mjs';
35
+ export { useScreenSize } from './hooks/use-screen-size.mjs';
34
36
  export { isRefable } from './is/is-refable.mjs';
35
37
  export { isUndefined } from './is/is-undefined.mjs';
36
38
  export { isNull } from './is/is-null.mjs';
@@ -47,7 +49,8 @@ export { isHTMLElement } from './is/is-html-element.mjs';
47
49
  export { isHTMLInputElement } from './is/is-html-input-element.mjs';
48
50
  export { isObject } from './is/is-object.mjs';
49
51
  export { effect } from './utils/effect.mjs';
50
- export { unique, uniqueBy } from './utils/unique.mjs';
52
+ export { unique } from './utils/unique.mjs';
53
+ export { uniqueBy } from './utils/unique-by.mjs';
51
54
  export { range } from './utils/range.mjs';
52
55
  export { clamp } from './utils/clamp.mjs';
53
56
  export { chain } from './utils/chain.mjs';
@@ -1 +1 @@
1
- export type First<T, R = undefined> = T extends [infer D, ...Array<unknown>] ? D : R;
1
+ export type First<T, R = undefined> = T extends string ? string : T extends [infer D, ...Array<unknown>] ? D : R;
@@ -5,17 +5,12 @@ var isFunction = require('../is/is-function.cjs');
5
5
  var waitable = require('./waitable.cjs');
6
6
 
7
7
  var debounce = function debounce(debouncer, wait) {
8
- var isCallable = isFunction.isFunction(debouncer);
9
- var callback = isCallable ? debouncer : debouncer.callback;
10
- var pipe = isCallable ? function () {
11
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12
- args[_key] = arguments[_key];
13
- }
14
- return args;
15
- } : debouncer.pipe;
8
+ var _isFunction = isFunction.isFunction(debouncer);
9
+ var callback = _isFunction ? debouncer : debouncer.callback;
10
+ // @ts-ignore
16
11
  var waiter = new waitable.Waitable({
17
12
  callback: callback,
18
- pipe: pipe,
13
+ pipe: _isFunction ? void 0 : debouncer.pipe,
19
14
  timer: rxjs.debounceTime(wait)
20
15
  });
21
16
  return {
@@ -16,8 +16,8 @@ export interface Debounced<T extends Callable> {
16
16
  */
17
17
  abort: () => void;
18
18
  }
19
- export type Debouncer<T extends Callable, R extends Array<unknown> = Parameters<T>> = {
20
- callback: (...args: R) => ReturnType<T>;
19
+ export type Debouncer<T extends Callable, R = unknown> = {
20
+ callback: (args: R) => ReturnType<T>;
21
21
  pipe: (...args: Parameters<T>) => R | Promise<R>;
22
22
  };
23
- export declare const debounce: <T extends Callable, R extends Array<unknown> = Parameters<T>>(debouncer: Debouncer<T, R> | T, wait: number) => Debounced<T>;
23
+ export declare const debounce: <T extends Callable, R = unknown>(debouncer: Debouncer<T, R> | T, wait: number) => Debounced<T>;
@@ -3,17 +3,12 @@ import { isFunction } from '../is/is-function.mjs';
3
3
  import { Waitable } from './waitable.mjs';
4
4
 
5
5
  var debounce = function debounce(debouncer, wait) {
6
- var isCallable = isFunction(debouncer);
7
- var callback = isCallable ? debouncer : debouncer.callback;
8
- var pipe = isCallable ? function () {
9
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
- args[_key] = arguments[_key];
11
- }
12
- return args;
13
- } : debouncer.pipe;
6
+ var _isFunction = isFunction(debouncer);
7
+ var callback = _isFunction ? debouncer : debouncer.callback;
8
+ // @ts-ignore
14
9
  var waiter = new Waitable({
15
10
  callback: callback,
16
- pipe: pipe,
11
+ pipe: _isFunction ? void 0 : debouncer.pipe,
17
12
  timer: debounceTime(wait)
18
13
  });
19
14
  return {
@@ -7,7 +7,10 @@ var toArray = require('./to-array.cjs');
7
7
  * first element of array
8
8
  */
9
9
  var first = function first(value) {
10
- return toArray.toArray(value).at(0);
10
+ // @ts-ignore
11
+ return toArray.toArray(value, {
12
+ separator: ""
13
+ }).at(0);
11
14
  };
12
15
 
13
16
  exports.first = first;
@@ -5,7 +5,10 @@ import { toArray } from './to-array.mjs';
5
5
  * first element of array
6
6
  */
7
7
  var first = function first(value) {
8
- return toArray(value).at(0);
8
+ // @ts-ignore
9
+ return toArray(value, {
10
+ separator: ""
11
+ }).at(0);
9
12
  };
10
13
 
11
14
  export { first };
@@ -7,7 +7,10 @@ var toArray = require('./to-array.cjs');
7
7
  * last element of array
8
8
  */
9
9
  var last = function last(value) {
10
- return toArray.toArray(value).at(-1);
10
+ // @ts-ignore
11
+ return toArray.toArray(value, {
12
+ separator: ""
13
+ }).at(-1);
11
14
  };
12
15
 
13
16
  exports.last = last;
@@ -5,7 +5,10 @@ import { toArray } from './to-array.mjs';
5
5
  * last element of array
6
6
  */
7
7
  var last = function last(value) {
8
- return toArray(value).at(-1);
8
+ // @ts-ignore
9
+ return toArray(value, {
10
+ separator: ""
11
+ }).at(-1);
9
12
  };
10
13
 
11
14
  export { last };
@@ -5,17 +5,12 @@ var isFunction = require('../is/is-function.cjs');
5
5
  var rxjs = require('rxjs');
6
6
 
7
7
  var throttle = function throttle(throttler, wait) {
8
- var isCallable = isFunction.isFunction(throttler);
9
- var callback = isCallable ? throttler : throttler.callback;
10
- var pipe = isCallable ? function () {
11
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12
- args[_key] = arguments[_key];
13
- }
14
- return args;
15
- } : throttler.pipe;
8
+ var _isFunction = isFunction.isFunction(throttler);
9
+ var callback = _isFunction ? throttler : throttler.callback;
10
+ // @ts-ignore
16
11
  var waiter = new waitable.Waitable({
17
12
  callback: callback,
18
- pipe: pipe,
13
+ pipe: _isFunction ? void 0 : throttler.pipe,
19
14
  timer: rxjs.throttleTime(wait)
20
15
  });
21
16
  return {
@@ -1,5 +1,5 @@
1
1
  import type { Debounced, Debouncer } from "./debounce";
2
2
  import { type Callable } from "../hooks/use-event";
3
3
  export type Throttled<T extends Callable> = Debounced<T>;
4
- export type Throttler<T extends Callable, R extends Array<unknown> = Parameters<T>> = Debouncer<T, R>;
5
- export declare const throttle: <T extends Callable, R extends Array<unknown> = Parameters<T>>(throttler: Throttler<T, R> | T, wait: number) => Throttled<T>;
4
+ export type Throttler<T extends Callable, R = unknown> = Debouncer<T, R>;
5
+ export declare const throttle: <T extends Callable, R = unknown>(throttler: Throttler<T, R> | T, wait: number) => Throttled<T>;
@@ -3,17 +3,12 @@ import { isFunction } from '../is/is-function.mjs';
3
3
  import { throttleTime } from 'rxjs';
4
4
 
5
5
  var throttle = function throttle(throttler, wait) {
6
- var isCallable = isFunction(throttler);
7
- var callback = isCallable ? throttler : throttler.callback;
8
- var pipe = isCallable ? function () {
9
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
- args[_key] = arguments[_key];
11
- }
12
- return args;
13
- } : throttler.pipe;
6
+ var _isFunction = isFunction(throttler);
7
+ var callback = _isFunction ? throttler : throttler.callback;
8
+ // @ts-ignore
14
9
  var waiter = new Waitable({
15
10
  callback: callback,
16
- pipe: pipe,
11
+ pipe: _isFunction ? void 0 : throttler.pipe,
17
12
  timer: throttleTime(wait)
18
13
  });
19
14
  return {
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var unique = require('./unique.cjs');
4
+
5
+ /**
6
+ * @description
7
+ * unique by
8
+ */
9
+ var uniqueBy = function uniqueBy(value, pipe) {
10
+ if (!pipe) {
11
+ return unique.unique(value);
12
+ }
13
+ return Array.from(Array.from(value).reduce(function (prev, _value) {
14
+ var _key = pipe(_value);
15
+ if (!prev.has(_key)) {
16
+ prev.set(pipe(_value), _value);
17
+ }
18
+ return prev;
19
+ }, new Map()).values());
20
+ };
21
+
22
+ exports.uniqueBy = uniqueBy;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * unique by
4
+ */
5
+ export declare const uniqueBy: <T, P>(value: Iterable<T>, pipe?: (item: T) => P) => any[];
@@ -0,0 +1,20 @@
1
+ import { unique } from './unique.mjs';
2
+
3
+ /**
4
+ * @description
5
+ * unique by
6
+ */
7
+ var uniqueBy = function uniqueBy(value, pipe) {
8
+ if (!pipe) {
9
+ return unique(value);
10
+ }
11
+ return Array.from(Array.from(value).reduce(function (prev, _value) {
12
+ var _key = pipe(_value);
13
+ if (!prev.has(_key)) {
14
+ prev.set(pipe(_value), _value);
15
+ }
16
+ return prev;
17
+ }, new Map()).values());
18
+ };
19
+
20
+ export { uniqueBy };
@@ -12,13 +12,5 @@ var unique = function unique() {
12
12
  return unionize.union(new Set(_value));
13
13
  }, new Set()));
14
14
  };
15
- /**
16
- * @description
17
- * unique by
18
- */
19
- var uniqueBy = function uniqueBy(value, callback) {
20
- return Array.from(new Set(Array.from(value).map(callback)));
21
- };
22
15
 
23
16
  exports.unique = unique;
24
- exports.uniqueBy = uniqueBy;
@@ -3,8 +3,3 @@
3
3
  * unique
4
4
  */
5
5
  export declare const unique: <T = unknown>(...values: Array<Iterable<T>>) => T[];
6
- /**
7
- * @description
8
- * unique by
9
- */
10
- export declare const uniqueBy: <T, P>(value: Iterable<T>, callback: (item: T) => P) => P[];
@@ -10,12 +10,5 @@ var unique = function unique() {
10
10
  return unionize.union(new Set(_value));
11
11
  }, new Set()));
12
12
  };
13
- /**
14
- * @description
15
- * unique by
16
- */
17
- var uniqueBy = function uniqueBy(value, callback) {
18
- return Array.from(new Set(Array.from(value).map(callback)));
19
- };
20
13
 
21
- export { unique, uniqueBy };
14
+ export { unique };
@@ -33,8 +33,8 @@ var Waitable = /*#__PURE__*/function () {
33
33
  _classPrivateFieldInitSpec(this, _callback, void 0);
34
34
  _classPrivateFieldSet(_cook$, this, null);
35
35
  _classPrivateFieldSet(_waiter$, this, null);
36
- _classPrivateFieldSet(_pipe, this, props.pipe);
37
36
  _classPrivateFieldSet(_timer, this, props.timer);
37
+ _classPrivateFieldSet(_pipe, this, props.pipe);
38
38
  _classPrivateFieldSet(_callback, this, props.callback);
39
39
  _assertClassBrand(_Waitable_brand, this, _use).call(this);
40
40
  }
@@ -88,11 +88,20 @@ function _use() {
88
88
  _classPrivateFieldSet(_waiter$, _this, subscriber);
89
89
  }).pipe(_classPrivateFieldGet(_timer, this), rxjs.switchMap(function (args) {
90
90
  var _classPrivateFieldGet6;
91
+ if (!_classPrivateFieldGet(_pipe, _this)) {
92
+ return rxjs.of(args);
93
+ }
91
94
  var piped = (_classPrivateFieldGet6 = _classPrivateFieldGet(_pipe, _this)).call.apply(_classPrivateFieldGet6, [_this].concat(_toConsumableArray(args)));
92
95
  return isThenable.isThenable(piped) ? rxjs.from(piped) : rxjs.of(piped);
93
96
  })).subscribe(function (args) {
94
- var _classPrivateFieldGet7;
95
- (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
97
+ if (!_classPrivateFieldGet(_pipe, _this)) {
98
+ var _classPrivateFieldGet7;
99
+ // @ts-ignore
100
+ (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)).call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
101
+ } else {
102
+ // @ts-ignore
103
+ _classPrivateFieldGet(_callback, _this).call(_this, args);
104
+ }
96
105
  }));
97
106
  }
98
107
 
@@ -1,15 +1,21 @@
1
1
  import { type MonoTypeOperatorFunction } from "rxjs";
2
- interface Props<T extends Array<unknown> = Array<unknown>, R extends Array<unknown> = T> {
2
+ interface PropsWithoutPipe<T extends Array<unknown> = Array<unknown>> {
3
3
  callback: (...args: T) => unknown;
4
- pipe: (...args: R) => T | Promise<T>;
5
- timer: MonoTypeOperatorFunction<R>;
4
+ pipe: undefined;
5
+ timer: MonoTypeOperatorFunction<T>;
6
6
  }
7
+ interface PropsWithPipe<T extends Array<unknown> = Array<unknown>, R = unknown> {
8
+ callback: (value: R) => unknown;
9
+ pipe: (...args: T) => R | Promise<R>;
10
+ timer: MonoTypeOperatorFunction<T>;
11
+ }
12
+ type Props<T extends Array<unknown> = Array<unknown>, R = unknown> = PropsWithoutPipe<T> | PropsWithPipe<T, R>;
7
13
  /**
8
14
  * @description
9
15
  * waitable instance
10
16
  * for debounce...
11
17
  */
12
- export declare class Waitable<T extends Array<unknown>, R extends Array<unknown> = T> {
18
+ export declare class Waitable<T extends Array<unknown>, R = unknown> {
13
19
  #private;
14
20
  constructor(props: Props<T, R>);
15
21
  /**
@@ -31,6 +37,6 @@ export declare class Waitable<T extends Array<unknown>, R extends Array<unknown>
31
37
  * @description
32
38
  * trigger value
33
39
  */
34
- next(...args: R): void;
40
+ next(...args: T): void;
35
41
  }
36
42
  export {};
@@ -6,7 +6,7 @@ import _classPrivateFieldInitSpec from '@babel/runtime/helpers/classPrivateField
6
6
  import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet2';
7
7
  import _assertClassBrand from '@babel/runtime/helpers/assertClassBrand';
8
8
  import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet2';
9
- import { Observable, switchMap, from, of } from 'rxjs';
9
+ import { Observable, switchMap, of, from } from 'rxjs';
10
10
  import { isThenable } from '../is/is-thenable.mjs';
11
11
 
12
12
  /**
@@ -31,8 +31,8 @@ var Waitable = /*#__PURE__*/function () {
31
31
  _classPrivateFieldInitSpec(this, _callback, void 0);
32
32
  _classPrivateFieldSet(_cook$, this, null);
33
33
  _classPrivateFieldSet(_waiter$, this, null);
34
- _classPrivateFieldSet(_pipe, this, props.pipe);
35
34
  _classPrivateFieldSet(_timer, this, props.timer);
35
+ _classPrivateFieldSet(_pipe, this, props.pipe);
36
36
  _classPrivateFieldSet(_callback, this, props.callback);
37
37
  _assertClassBrand(_Waitable_brand, this, _use).call(this);
38
38
  }
@@ -86,11 +86,20 @@ function _use() {
86
86
  _classPrivateFieldSet(_waiter$, _this, subscriber);
87
87
  }).pipe(_classPrivateFieldGet(_timer, this), switchMap(function (args) {
88
88
  var _classPrivateFieldGet6;
89
+ if (!_classPrivateFieldGet(_pipe, _this)) {
90
+ return of(args);
91
+ }
89
92
  var piped = (_classPrivateFieldGet6 = _classPrivateFieldGet(_pipe, _this)).call.apply(_classPrivateFieldGet6, [_this].concat(_toConsumableArray(args)));
90
93
  return isThenable(piped) ? from(piped) : of(piped);
91
94
  })).subscribe(function (args) {
92
- var _classPrivateFieldGet7;
93
- (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
95
+ if (!_classPrivateFieldGet(_pipe, _this)) {
96
+ var _classPrivateFieldGet7;
97
+ // @ts-ignore
98
+ (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)).call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
99
+ } else {
100
+ // @ts-ignore
101
+ _classPrivateFieldGet(_callback, _this).call(_this, args);
102
+ }
94
103
  }));
95
104
  }
96
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.3.16",
3
+ "version": "1.3.18",
4
4
  "description": "react utils collection",
5
5
  "exports": {
6
6
  ".": {
@@ -48,18 +48,18 @@
48
48
  "@babel/preset-typescript": "^7.24.7",
49
49
  "@jest/globals": "^29.7.0",
50
50
  "@rollup/plugin-babel": "^6.0.4",
51
- "@rollup/plugin-node-resolve": "^15.2.3",
52
- "@rollup/plugin-typescript": "^11.1.6",
51
+ "@rollup/plugin-node-resolve": "^15.3.0",
52
+ "@rollup/plugin-typescript": "^12.1.0",
53
53
  "@testing-library/react": "^16.0.1",
54
54
  "@types/babel__core": "^7.20.5",
55
- "@types/react": "^18.3.6",
55
+ "@types/react": "^18.3.10",
56
56
  "@types/react-dom": "^18.3.0",
57
57
  "@types/react-is": "^18.3.0",
58
58
  "jest": "^29.7.0",
59
59
  "jest-environment-jsdom": "^29.7.0",
60
60
  "react": "^18.3.1",
61
61
  "react-dom": "^18.3.1",
62
- "rollup": "^4.21.3",
62
+ "rollup": "^4.22.5",
63
63
  "typescript": "5.6.2"
64
64
  },
65
65
  "peerDependencies": {