@t8/react-pending 1.0.6 → 1.0.7
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/dist/index.js +7 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -12,10 +12,10 @@ function isStore(x) {
|
|
|
12
12
|
// node_modules/@t8/store/src/Store.ts
|
|
13
13
|
var Store = class {
|
|
14
14
|
state;
|
|
15
|
-
callbacks;
|
|
15
|
+
callbacks = [];
|
|
16
|
+
revision = 0;
|
|
16
17
|
constructor(data) {
|
|
17
18
|
this.state = data;
|
|
18
|
-
this.callbacks = [];
|
|
19
19
|
}
|
|
20
20
|
onUpdate(callback) {
|
|
21
21
|
this.callbacks.push(callback);
|
|
@@ -32,6 +32,8 @@ var Store = class {
|
|
|
32
32
|
let prevState = this.state;
|
|
33
33
|
let nextState = update instanceof Function ? update(this.state) : update;
|
|
34
34
|
this.state = nextState;
|
|
35
|
+
if (this.revision === Number.MAX_SAFE_INTEGER) this.revision = 1;
|
|
36
|
+
else this.revision++;
|
|
35
37
|
for (let callback of this.callbacks) callback(nextState, prevState);
|
|
36
38
|
}
|
|
37
39
|
};
|
|
@@ -44,6 +46,7 @@ function useStore(store, shouldUpdate = true) {
|
|
|
44
46
|
let initedRef = useRef(false);
|
|
45
47
|
let state = store.getState();
|
|
46
48
|
let setState = useMemo(() => store.setState.bind(store), [store]);
|
|
49
|
+
let initialStoreRevision = useRef(store.revision);
|
|
47
50
|
useEffect(() => {
|
|
48
51
|
if (!shouldUpdate) return;
|
|
49
52
|
let unsubscribe = store.onUpdate((nextState, prevState) => {
|
|
@@ -52,7 +55,8 @@ function useStore(store, shouldUpdate = true) {
|
|
|
52
55
|
});
|
|
53
56
|
if (!initedRef.current) {
|
|
54
57
|
initedRef.current = true;
|
|
55
|
-
|
|
58
|
+
if (store.revision !== initialStoreRevision.current)
|
|
59
|
+
setRevision(Math.random());
|
|
56
60
|
}
|
|
57
61
|
return () => {
|
|
58
62
|
unsubscribe();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t8/react-pending",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Concise async action state tracking for React apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"@types/react": "^19.1.10"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@t8/react-store": "^1.0.
|
|
35
|
+
"@t8/react-store": "^1.0.7"
|
|
36
36
|
}
|
|
37
37
|
}
|