state-jet 1.0.4 → 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/README.md CHANGED
@@ -5,7 +5,7 @@ A zero-boilerplate, ultra-fast global state management library for React. No con
5
5
  ## 🚀 Why state-jet?
6
6
  - ✅ **No Context, No Providers** – Works outside React, reducing unnecessary re-renders.
7
7
  - ✅ **Automatic Re-Renders** – Only components using specific state values update.
8
- - ✅ **Super Lightweight** – Ultra minified!
8
+ - ✅ **Super Lightweight** – Ultra small!
9
9
  - ✅ **SSR & Next.js Support** – Works on both client and server.
10
10
 
11
11
  ## 🛠 Installation
@@ -30,7 +30,7 @@ function Counter() {
30
30
  |Feature|Redux|Recoil|MobX|Jotai|state-jet|
31
31
  |:----|:----|:----|:----|:----|:----|
32
32
  |Setup Required|✅ Yes|✅ Yes|⚠️ Yes|❌ No|❌ No|
33
- |Bundle Size|🚀 Large|🚀 Medium|⚡ Small|⚡ Small|🔥 Ultra-Small (<1KB)|
33
+ |Bundle Size|🚀 Large|🚀 Medium|⚡ Small|⚡ Small|🔥 Ultra-Small|
34
34
  |Reactivity|⚠️ Reducers|✅ Atoms|✅ Proxy-Based|✅ Signals|✅ Signal-Like|
35
35
  |Renders Only Affected|❌ No|✅ Yes|✅ Yes|✅ Yes|✅ Yes|
36
36
  |Derived/Computed State|❌ No|✅ Yes|✅ Yes|✅ Yes|✅ Yes|
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
+ }
@@ -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.4",
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
  },
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = App;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const index_1 = require("../src/index");
6
- const middleware_1 = require("../src/middleware");
7
- const counter = (0, index_1.useStateGlobal)("counter", 0, { middleware: [middleware_1.loggerMiddleware] });
8
- function App() {
9
- const { undo, redo } = counter;
10
- const count = counter.useStore();
11
- return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("button", { onClick: () => counter.set(count + 1), children: "+" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => counter.set(count - 1), children: "-" }), (0, jsx_runtime_1.jsx)("button", { onClick: undo, children: "Undo" }), (0, jsx_runtime_1.jsx)("button", { onClick: redo, children: "Redo" }), (0, jsx_runtime_1.jsxs)("p", { children: ["Count: ", count] })] }));
12
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes