@aiszlab/relax 1.3.9 → 1.3.11

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.
@@ -18,4 +18,5 @@ declare function useControlledState<T>(): UsedControlledState<Partialable<T>>;
18
18
  declare function useControlledState<T>(controlledState: T): UsedControlledState<T>;
19
19
  declare function useControlledState<T>(controlledState: T, useControlledStateBy: UseControlledStateBy<undefined>): UsedControlledState<T>;
20
20
  declare function useControlledState<T>(controlledState: Partialable<T>, useControlledStateBy: RequiredIn<UseControlledStateBy<T>, "defaultState">): UsedControlledState<T>;
21
+ declare function useControlledState<T>(controlledState: T, useControlledStateBy: UseControlledStateBy<T>): UsedControlledState<T>;
21
22
  export { useControlledState };
@@ -1,24 +1,13 @@
1
- import { useRef, useEffect } from 'react';
2
- import { useDefault } from './use-default.js';
1
+ import { useRef } from 'react';
3
2
 
4
3
  var useMemorable = function useMemorable(getter, condition, shouldUpdate) {
5
- var isMounted = useRef(false);
6
- var cacheRef = useRef({
7
- value: useDefault(getter),
8
- condition: condition
9
- });
10
- useEffect(function () {
11
- // value has got in the first render, skip this render time
12
- if (!isMounted.current) {
13
- isMounted.current = true;
14
- return;
15
- }
16
- if (!shouldUpdate(cacheRef.current.condition, condition)) return;
4
+ var cacheRef = useRef(null);
5
+ if (cacheRef.current === null || shouldUpdate(cacheRef.current.condition, condition)) {
17
6
  cacheRef.current = {
18
7
  value: getter(),
19
8
  condition: condition
20
9
  };
21
- });
10
+ }
22
11
  return cacheRef.current.value;
23
12
  };
24
13
 
@@ -3,4 +3,7 @@ import type { State } from "@aiszlab/relax/types";
3
3
  * @description
4
4
  * use reactive
5
5
  */
6
- export declare const useReactive: <T>(initialState: State<T>) => void;
6
+ declare const useReactive: <T>(initialState: State<T>) => {
7
+ value: T;
8
+ };
9
+ export { useReactive };
@@ -0,0 +1,30 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
+ import { useState, useRef } from 'react';
3
+ import { useEvent } from './use-event.js';
4
+
5
+ /**
6
+ * @description
7
+ * use reactive
8
+ */
9
+ var useReactive = function useReactive(initialState) {
10
+ var _useState = useState(initialState),
11
+ _useState2 = _slicedToArray(_useState, 2),
12
+ _state = _useState2[0],
13
+ _setState = _useState2[1];
14
+ var getter = useEvent(function () {
15
+ return _state;
16
+ });
17
+ var setter = useEvent(function (_target, _key, value) {
18
+ _setState(value);
19
+ return true;
20
+ });
21
+ var ref = useRef(new Proxy({
22
+ value: _state
23
+ }, {
24
+ get: getter,
25
+ set: setter
26
+ }));
27
+ return ref.current;
28
+ };
29
+
30
+ export { useReactive };
package/dist/index.d.ts CHANGED
@@ -34,6 +34,7 @@ export { useLocalStorageState } from "./hooks/use-local-storage-state";
34
34
  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
+ export { useReactive } from "./hooks/use-reactive";
37
38
  /**
38
39
  * @description
39
40
  * is
@@ -43,7 +44,6 @@ export { isUndefined } from "./is/is-undefined";
43
44
  export { isNull } from "./is/is-null";
44
45
  export { isVoid } from "./is/is-void";
45
46
  export { isArray } from "./is/is-array";
46
- export { isComplex } from "./is/is-complex";
47
47
  export { isEmpty } from "./is/is-empty";
48
48
  export { isDomUsable } from "./is/is-dom-usable";
49
49
  export { isMobile } from "./is/is-mobile";
@@ -53,6 +53,7 @@ export { isFunction } from "./is/is-function";
53
53
  export { isThenable } from "./is/is-thenable";
54
54
  export { isHTMLElement } from "./is/is-html-element";
55
55
  export { isHTMLInputElement } from "./is/is-html-input-element";
56
+ export { isObject } from "./is/is-object";
56
57
  /**
57
58
  * @description
58
59
  * utils
package/dist/index.js CHANGED
@@ -30,12 +30,12 @@ export { useLocalStorageState } from './hooks/use-local-storage-state.js';
30
30
  export { useSessionStorageState } from './hooks/use-session-storage-state.js';
31
31
  export { useIsMounted } from './hooks/use-is-mounted.js';
32
32
  export { useInfiniteScroll } from './hooks/use-infinite-scroll.js';
33
+ export { useReactive } from './hooks/use-reactive.js';
33
34
  export { isRefable } from './is/is-refable.js';
34
35
  export { isUndefined } from './is/is-undefined.js';
35
36
  export { isNull } from './is/is-null.js';
36
37
  export { isVoid } from './is/is-void.js';
37
38
  export { isArray } from './is/is-array.js';
38
- export { isComplex } from './is/is-complex.js';
39
39
  export { isEmpty } from './is/is-empty.js';
40
40
  export { isDomUsable } from './is/is-dom-usable.js';
41
41
  export { isMobile } from './is/is-mobile.js';
@@ -45,6 +45,7 @@ export { isFunction } from './is/is-function.js';
45
45
  export { isThenable } from './is/is-thenable.js';
46
46
  export { isHTMLElement } from './is/is-html-element.js';
47
47
  export { isHTMLInputElement } from './is/is-html-input-element.js';
48
+ export { isObject } from './is/is-object.js';
48
49
  export { effect } from './utils/effect.js';
49
50
  export { unique, uniqueBy } from './utils/unique.js';
50
51
  export { range } from './utils/range.js';
@@ -1,6 +1,6 @@
1
- import _typeof from '@babel/runtime/helpers/typeof';
2
1
  import { isVoid } from './is-void.js';
3
2
  import { isArray } from './is-array.js';
3
+ import { isObject } from './is-object.js';
4
4
 
5
5
  /**
6
6
  * @author murukal
@@ -11,14 +11,14 @@ import { isArray } from './is-array.js';
11
11
  var isEmpty = function isEmpty(value) {
12
12
  // null or undefined
13
13
  if (isVoid(value)) return true;
14
- // object
15
- if (_typeof(value) === "object") {
16
- return Object.keys(value).length === 0;
17
- }
18
14
  // array
19
15
  if (isArray(value)) {
20
16
  return value.length === 0;
21
17
  }
18
+ // object
19
+ if (isObject(value)) {
20
+ return Object.keys(value).length === 0;
21
+ }
22
22
  return !!value;
23
23
  };
24
24
 
@@ -2,4 +2,5 @@
2
2
  * @description
3
3
  * if is function
4
4
  */
5
- export declare const isFunction: (value: unknown) => value is Function;
5
+ declare const isFunction: (value: unknown) => value is Function;
6
+ export { isFunction };
@@ -3,4 +3,4 @@ import type { Voidable } from "../types";
3
3
  * @param value - The element being tested
4
4
  * @returns Returns true if x is an HTML input tag, false otherwise
5
5
  */
6
- export declare const isHTMLInputElement: (value: Voidable<EventTarget>) => value is HTMLInputElement;
6
+ export declare const isHTMLInputElement: (value: Voidable<EventTarget> | unknown) => value is HTMLInputElement;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @description
3
+ * is object
4
+ */
5
+ declare const isObject: (value: unknown) => value is Object;
6
+ export { isObject };
@@ -0,0 +1,11 @@
1
+ import _typeof from '@babel/runtime/helpers/typeof';
2
+
3
+ /**
4
+ * @description
5
+ * is object
6
+ */
7
+ var isObject = function isObject(value) {
8
+ return !!value && _typeof(value) === "object";
9
+ };
10
+
11
+ export { isObject };
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "description": "react utils collection",
5
- "type": "module",
6
5
  "exports": {
7
6
  ".": {
8
7
  "types": "./dist/index.d.ts",
@@ -1,5 +0,0 @@
1
- /**
2
- * @description
3
- * complex
4
- */
5
- export declare const isComplex: (value: unknown) => value is Object;
@@ -1,11 +0,0 @@
1
- import _typeof from '@babel/runtime/helpers/typeof';
2
-
3
- /**
4
- * @description
5
- * complex
6
- */
7
- var isComplex = function isComplex(value) {
8
- return _typeof(value) === "object" || typeof value === "function";
9
- };
10
-
11
- export { isComplex };