@venizia/ardor-react 0.4.8-4 → 0.4.8-5
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.
|
@@ -35,7 +35,7 @@ export interface IUseStoredState {
|
|
|
35
35
|
* that writes through `BrowserStorage`, and with other tabs. Pass a stable `codec` and `defaultValue`.
|
|
36
36
|
* A write or a removal that the storage refuses is kept in this hook until the storage next changes.
|
|
37
37
|
* With `writeDelayMs` the value waits in the same place for the delay: a change of the storage from
|
|
38
|
-
* outside drops it, and an unmount
|
|
38
|
+
* outside drops it, and an unmount, a new key or storage, a `pagehide` event or a hidden page writes it at once.
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* ```tsx
|
|
@@ -7,7 +7,7 @@ const isUpdater = (next) => typeof next === 'function';
|
|
|
7
7
|
* that writes through `BrowserStorage`, and with other tabs. Pass a stable `codec` and `defaultValue`.
|
|
8
8
|
* A write or a removal that the storage refuses is kept in this hook until the storage next changes.
|
|
9
9
|
* With `writeDelayMs` the value waits in the same place for the delay: a change of the storage from
|
|
10
|
-
* outside drops it, and an unmount
|
|
10
|
+
* outside drops it, and an unmount, a new key or storage, a `pagehide` event or a hidden page writes it at once.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```tsx
|
|
@@ -35,14 +35,30 @@ export const useStoredState = (opts) => {
|
|
|
35
35
|
const write = React.useCallback((entry) => {
|
|
36
36
|
keep(BrowserStorage.set(entry) ? undefined : entry);
|
|
37
37
|
}, [keep]);
|
|
38
|
-
|
|
38
|
+
const isDelayed = writeDelayMs > 0;
|
|
39
|
+
const flush = React.useCallback(() => {
|
|
40
|
+
if (timerRef.current !== undefined && keptRef.current) {
|
|
41
|
+
write(keptRef.current);
|
|
42
|
+
}
|
|
43
|
+
}, [write]);
|
|
44
|
+
// A new key or storage, an unmount, and a page that closes or hides write the pending value to the
|
|
45
|
+
// key it was set for: closing a tab does not unmount.
|
|
39
46
|
React.useEffect(() => {
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
47
|
+
const onHide = () => {
|
|
48
|
+
if (document.visibilityState === 'hidden') {
|
|
49
|
+
flush();
|
|
43
50
|
}
|
|
44
51
|
};
|
|
45
|
-
|
|
52
|
+
if (isDelayed) {
|
|
53
|
+
window.addEventListener('pagehide', flush);
|
|
54
|
+
document.addEventListener('visibilitychange', onHide);
|
|
55
|
+
}
|
|
56
|
+
return () => {
|
|
57
|
+
window.removeEventListener('pagehide', flush);
|
|
58
|
+
document.removeEventListener('visibilitychange', onHide);
|
|
59
|
+
flush();
|
|
60
|
+
};
|
|
61
|
+
}, [key, storage, isDelayed, flush]);
|
|
46
62
|
const subscribe = React.useCallback((listener) => {
|
|
47
63
|
return BrowserStorage.subscribe({
|
|
48
64
|
key,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ardor-react",
|
|
3
|
-
"version": "0.4.8-
|
|
3
|
+
"version": "0.4.8-5",
|
|
4
4
|
"description": "ARDOR React bindings - the application context, the injectable and logger hooks that read it, typed Redux hook factories, and the framework-agnostic UI hooks (debounce, autosave, confirm, clipboard, element size, window dimensions). No react-admin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ardor",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"prepublishOnly": "make rebuild"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@venizia/ardor-kernel": "0.4.8-
|
|
62
|
+
"@venizia/ardor-kernel": "0.4.8-5"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@happy-dom/global-registrator": "^21.0.4",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
"@types/react-dom": "^19",
|
|
72
72
|
"@venizia/dev-configs": "^0.4.8-2",
|
|
73
73
|
"@venizia/ignis-filter": "^0.4.7-2",
|
|
74
|
-
"@venizia/ignis-helpers": "^0.4.8-
|
|
74
|
+
"@venizia/ignis-helpers": "^0.4.8-4",
|
|
75
75
|
"@venizia/ignis-inversion": "^0.4.7-2",
|
|
76
|
-
"@venizia/ignis-kernel": "^0.4.8-
|
|
76
|
+
"@venizia/ignis-kernel": "^0.4.8-4",
|
|
77
77
|
"eslint": "^10.13.0",
|
|
78
78
|
"oxlint": "1.89.0",
|
|
79
79
|
"oxlint-tsgolint": "7.0.2004",
|
|
@@ -88,9 +88,9 @@
|
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"@reduxjs/toolkit": ">=2.13.0",
|
|
90
90
|
"@venizia/ignis-filter": "^0.4.7-2",
|
|
91
|
-
"@venizia/ignis-helpers": "^0.4.8-
|
|
91
|
+
"@venizia/ignis-helpers": "^0.4.8-4",
|
|
92
92
|
"@venizia/ignis-inversion": "^0.4.7-2",
|
|
93
|
-
"@venizia/ignis-kernel": "^0.4.8-
|
|
93
|
+
"@venizia/ignis-kernel": "^0.4.8-4",
|
|
94
94
|
"react": ">=19.3.1",
|
|
95
95
|
"react-redux": ">=9.3.0",
|
|
96
96
|
"reflect-metadata": ">=0.2.2"
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"react",
|
|
112
112
|
"react-redux"
|
|
113
113
|
],
|
|
114
|
-
"limit": "
|
|
114
|
+
"limit": "3540 B"
|
|
115
115
|
}
|
|
116
116
|
],
|
|
117
117
|
"engines": {
|