@t8/react-pending 1.0.5 → 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.
Files changed (2) hide show
  1. package/dist/index.js +7 -3
  2. package/package.json +3 -3
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
- setRevision(Math.random());
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.5",
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",
@@ -8,7 +8,7 @@
8
8
  "build": "npx npm-run-all clean compile",
9
9
  "clean": "node -e \"require('node:fs').rmSync('dist', {force: true, recursive: true});\"",
10
10
  "compile": "npx esbuild index.ts --bundle --outdir=dist --platform=neutral --external:react",
11
- "gh-pages": "npx ghstage --color-scheme=indigo --ymid=103784239 --backstory=https://axtk.github.io/x/t8_react_pending",
11
+ "gh-pages": "npx ghstage --theme=t8 --ymid=103784239 --backstory=https://axtk.github.io/x/t8_react_pending",
12
12
  "prepublishOnly": "npx npm-run-all build gh-pages",
13
13
  "preversion": "npx npm-run-all shape build",
14
14
  "shape": "npx codeshape"
@@ -32,6 +32,6 @@
32
32
  "@types/react": "^19.1.10"
33
33
  },
34
34
  "dependencies": {
35
- "@t8/react-store": "^1.0.5"
35
+ "@t8/react-store": "^1.0.7"
36
36
  }
37
37
  }