state-jet 1.0.5 → 1.0.6

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/hooks.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSyncExternalStore = useSyncExternalStore;
4
+ const react_1 = require("react");
5
+ function useSyncExternalStore(subscribe, getSnapshot) {
6
+ // State to hold the current snapshot of the store
7
+ const [snapshot, setSnapshot] = (0, react_1.useState)(getSnapshot());
8
+ // Effect to subscribe to the external store
9
+ (0, react_1.useEffect)(() => {
10
+ // Function to update the snapshot when the store changes
11
+ const handleStoreChange = () => {
12
+ setSnapshot(getSnapshot());
13
+ };
14
+ // Subscribe to the store and get the unsubscribe function
15
+ const unsubscribe = subscribe(handleStoreChange);
16
+ // Ensure the snapshot is up-to-date after subscribing
17
+ handleStoreChange();
18
+ // Cleanup function to unsubscribe when the component unmounts
19
+ return () => {
20
+ unsubscribe();
21
+ };
22
+ }, [subscribe, getSnapshot]);
23
+ // Return the current snapshot
24
+ return snapshot;
25
+ }
package/dist/store.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useStateGlobal = void 0;
4
- const react_1 = require("react");
5
4
  const immer_1 = require("immer");
6
5
  const persistence_1 = require("./persistence");
6
+ const hooks_1 = require("./hooks");
7
7
  const devtools_1 = require("./devtools");
8
8
  const store = new Map();
9
9
  const pendingUpdates = new Map();
@@ -66,7 +66,7 @@ const useStateGlobal = (key, initialValue, options) => {
66
66
  }
67
67
  };
68
68
  const useStore = () => {
69
- return (0, react_1.useSyncExternalStore)((callback) => {
69
+ return (0, hooks_1.useSyncExternalStore)((callback) => {
70
70
  state.listeners.add(callback);
71
71
  return () => state.listeners.delete(callback);
72
72
  }, () => state.value);
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "state-jet",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Ultra-lightweight global state management for React",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "module": "dist/index.mjs",
8
- "files": ["dist"],
8
+ "files": [
9
+ "dist"
10
+ ],
9
11
  "exports": {
10
12
  ".": {
11
13
  "import": "./dist/index.mjs",
@@ -20,7 +22,10 @@
20
22
  "react",
21
23
  "state-management",
22
24
  "global-state",
23
- "signals"
25
+ "signals",
26
+ "state-jet",
27
+ "state",
28
+ "jet"
24
29
  ],
25
30
  "author": "venkateshsundaram",
26
31
  "license": "MIT",
@@ -35,12 +40,10 @@
35
40
  "lint": "eslint src --ext .ts,.tsx"
36
41
  },
37
42
  "devDependencies": {
38
- "@types/react": "^19.0.3",
39
- "@types/react-dom": "^19.0.2",
43
+ "@types/react": "^18.2.0",
40
44
  "eslint": "^8.57.1",
41
45
  "immer": "^10.1.1",
42
- "react": "19.0.0",
43
- "react-dom": "19.0.0",
46
+ "react": "^18.2.0",
44
47
  "typescript": "^5.7.3",
45
48
  "vitest": "^2.1.8"
46
49
  },