piral 0.14.3-beta.3296 → 0.14.3
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.
- package/esm/hooks/debounce.d.ts +8 -0
- package/esm/hooks/debounce.js +17 -0
- package/esm/hooks/debounce.js.map +1 -0
- package/esm/hooks/promise.d.ts +13 -0
- package/esm/hooks/promise.js +21 -0
- package/esm/hooks/promise.js.map +1 -0
- package/lib/hooks/debounce.d.ts +8 -0
- package/lib/hooks/debounce.js +21 -0
- package/lib/hooks/debounce.js.map +1 -0
- package/lib/hooks/promise.d.ts +13 -0
- package/lib/hooks/promise.js +25 -0
- package/lib/hooks/promise.js.map +1 -0
- package/package.json +22 -12
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook that returns the debounced (i.e., delayed) value.
|
|
3
|
+
* Useful when user input should not fire immediately, but rather
|
|
4
|
+
* only after a certain timespan without any changes passed.
|
|
5
|
+
* @param value The value to consider.
|
|
6
|
+
* @param delay The timespan to pass before applying the value.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useDebounce<T>(value: T, delay?: number): T;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that returns the debounced (i.e., delayed) value.
|
|
4
|
+
* Useful when user input should not fire immediately, but rather
|
|
5
|
+
* only after a certain timespan without any changes passed.
|
|
6
|
+
* @param value The value to consider.
|
|
7
|
+
* @param delay The timespan to pass before applying the value.
|
|
8
|
+
*/
|
|
9
|
+
export function useDebounce(value, delay = 300) {
|
|
10
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
13
|
+
return () => clearTimeout(handler);
|
|
14
|
+
}, [value, delay]);
|
|
15
|
+
return debouncedValue;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=debounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/hooks/debounce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAI,KAAQ,EAAE,KAAK,GAAG,GAAG;IAClD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QAClE,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEnB,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The currently captured Promise state.
|
|
3
|
+
*/
|
|
4
|
+
export interface UsePromiseResult<T> {
|
|
5
|
+
loading: boolean;
|
|
6
|
+
data: T;
|
|
7
|
+
error: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hook for introducing a complete local loading state for a promise.
|
|
11
|
+
* @param promise The callback for the promise to wait for.
|
|
12
|
+
*/
|
|
13
|
+
export declare function usePromise<T>(promise: () => Promise<T>): UsePromiseResult<T>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for introducing a complete local loading state for a promise.
|
|
4
|
+
* @param promise The callback for the promise to wait for.
|
|
5
|
+
*/
|
|
6
|
+
export function usePromise(promise) {
|
|
7
|
+
const [result, setResult] = useState({
|
|
8
|
+
loading: true,
|
|
9
|
+
data: undefined,
|
|
10
|
+
error: undefined,
|
|
11
|
+
});
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
let cancelled = false;
|
|
14
|
+
promise().then((data) => !cancelled && setResult({ data, error: undefined, loading: false }), (error) => !cancelled && setResult({ data: undefined, error, loading: false }));
|
|
15
|
+
return () => {
|
|
16
|
+
cancelled = true;
|
|
17
|
+
};
|
|
18
|
+
}, []);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/hooks/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAW5C;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAI,OAAyB;IACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAsB;QACxD,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,OAAO,EAAE,CAAC,IAAI,CACZ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAC7E,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAC/E,CAAC;QAEF,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook that returns the debounced (i.e., delayed) value.
|
|
3
|
+
* Useful when user input should not fire immediately, but rather
|
|
4
|
+
* only after a certain timespan without any changes passed.
|
|
5
|
+
* @param value The value to consider.
|
|
6
|
+
* @param delay The timespan to pass before applying the value.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useDebounce<T>(value: T, delay?: number): T;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebounce = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Hook that returns the debounced (i.e., delayed) value.
|
|
7
|
+
* Useful when user input should not fire immediately, but rather
|
|
8
|
+
* only after a certain timespan without any changes passed.
|
|
9
|
+
* @param value The value to consider.
|
|
10
|
+
* @param delay The timespan to pass before applying the value.
|
|
11
|
+
*/
|
|
12
|
+
function useDebounce(value, delay = 300) {
|
|
13
|
+
const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(value);
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
const handler = setTimeout(() => setDebouncedValue(value), delay);
|
|
16
|
+
return () => clearTimeout(handler);
|
|
17
|
+
}, [value, delay]);
|
|
18
|
+
return debouncedValue;
|
|
19
|
+
}
|
|
20
|
+
exports.useDebounce = useDebounce;
|
|
21
|
+
//# sourceMappingURL=debounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/hooks/debounce.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAE5C;;;;;;GAMG;AACH,SAAgB,WAAW,CAAI,KAAQ,EAAE,KAAK,GAAG,GAAG;IAClD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAE5D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QAClE,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEnB,OAAO,cAAc,CAAC;AACxB,CAAC;AATD,kCASC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The currently captured Promise state.
|
|
3
|
+
*/
|
|
4
|
+
export interface UsePromiseResult<T> {
|
|
5
|
+
loading: boolean;
|
|
6
|
+
data: T;
|
|
7
|
+
error: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hook for introducing a complete local loading state for a promise.
|
|
11
|
+
* @param promise The callback for the promise to wait for.
|
|
12
|
+
*/
|
|
13
|
+
export declare function usePromise<T>(promise: () => Promise<T>): UsePromiseResult<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePromise = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Hook for introducing a complete local loading state for a promise.
|
|
7
|
+
* @param promise The callback for the promise to wait for.
|
|
8
|
+
*/
|
|
9
|
+
function usePromise(promise) {
|
|
10
|
+
const [result, setResult] = (0, react_1.useState)({
|
|
11
|
+
loading: true,
|
|
12
|
+
data: undefined,
|
|
13
|
+
error: undefined,
|
|
14
|
+
});
|
|
15
|
+
(0, react_1.useEffect)(() => {
|
|
16
|
+
let cancelled = false;
|
|
17
|
+
promise().then((data) => !cancelled && setResult({ data, error: undefined, loading: false }), (error) => !cancelled && setResult({ data: undefined, error, loading: false }));
|
|
18
|
+
return () => {
|
|
19
|
+
cancelled = true;
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
exports.usePromise = usePromise;
|
|
25
|
+
//# sourceMappingURL=promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/hooks/promise.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAW5C;;;GAGG;AACH,SAAgB,UAAU,CAAI,OAAyB;IACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAsB;QACxD,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IACH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,OAAO,EAAE,CAAC,IAAI,CACZ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAC7E,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAC/E,CAAC;QAEF,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,MAAM,CAAC;AAChB,CAAC;AAnBD,gCAmBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral",
|
|
3
|
-
"version": "0.14.3
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "The all-in-one piral package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"smapiot",
|
|
@@ -48,19 +48,11 @@
|
|
|
48
48
|
"typedoc": "typedoc --json ../../../docs/types/piral.json src --exclude \"src/**/*.test.*\"",
|
|
49
49
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
50
50
|
},
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"@dbeining/react-atom": "^4.0.0",
|
|
53
|
-
"@types/fluent": "^0.11.0",
|
|
54
|
-
"@types/history": "^4.7.8",
|
|
55
|
-
"@types/react": "^17.0.0",
|
|
56
|
-
"@types/react-router": "^5.1.8",
|
|
57
|
-
"@types/react-router-dom": "^5.1.6"
|
|
58
|
-
},
|
|
59
51
|
"dependencies": {
|
|
60
52
|
"core-js": "^3.6.4",
|
|
61
53
|
"current-script-polyfill": "^1.0.0",
|
|
62
|
-
"piral-core": "0.14.3
|
|
63
|
-
"piral-ext": "0.14.3
|
|
54
|
+
"piral-core": "^0.14.3",
|
|
55
|
+
"piral-ext": "^0.14.3",
|
|
64
56
|
"promise-polyfill": "^8.1.0",
|
|
65
57
|
"react": "^17.0.1",
|
|
66
58
|
"react-dom": "^17.0.1",
|
|
@@ -69,5 +61,23 @@
|
|
|
69
61
|
"url-polyfill": "^1.1.5",
|
|
70
62
|
"whatwg-fetch": "^3.0.0"
|
|
71
63
|
},
|
|
72
|
-
"
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@dbeining/react-atom": "^4.0.0",
|
|
66
|
+
"@types/fluent": "^0.11.0",
|
|
67
|
+
"@types/history": "^4.7.8",
|
|
68
|
+
"@types/react": "^17.0.0",
|
|
69
|
+
"@types/react-router": "^5.1.8",
|
|
70
|
+
"@types/react-router-dom": "^5.1.6"
|
|
71
|
+
},
|
|
72
|
+
"sharedDependencies": [
|
|
73
|
+
"react",
|
|
74
|
+
"react-dom",
|
|
75
|
+
"react-router",
|
|
76
|
+
"react-router-dom",
|
|
77
|
+
"history",
|
|
78
|
+
"tslib",
|
|
79
|
+
"path-to-regexp",
|
|
80
|
+
"@libre/atom",
|
|
81
|
+
"@dbeining/react-atom"
|
|
82
|
+
]
|
|
73
83
|
}
|