srasm 0.0.3 → 0.0.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.
package/dist/index.cjs CHANGED
@@ -54,6 +54,22 @@ function deepEqual(obj1, obj2) {
54
54
  return true;
55
55
  }
56
56
 
57
+ // src/utils/tryRegisterSRASMDevtools.ts
58
+ function tryRegisterSRASMDevtools(storeName, api) {
59
+ if (typeof window === "undefined") return;
60
+ const w = window;
61
+ let tries = 0;
62
+ const t = setInterval(() => {
63
+ const dt = w.__SRASM_DEVTOOLS__;
64
+ if (dt && typeof dt.registerStore === "function") {
65
+ dt.registerStore(storeName, api);
66
+ clearInterval(t);
67
+ }
68
+ tries++;
69
+ if (tries > 50) clearInterval(t);
70
+ }, 100);
71
+ }
72
+
57
73
  // src/context/createStateStore.ts
58
74
  var import_with_selector = require("use-sync-external-store/with-selector");
59
75
  function createStateStore(initialSlices) {
@@ -137,11 +153,24 @@ function createStateStore(initialSlices) {
137
153
  refetch: fetchData
138
154
  };
139
155
  }
140
- const SRASMProvider = ({
141
- children
142
- }) => {
156
+ const SRASMProvider = ({ children }) => {
143
157
  return children;
144
158
  };
159
+ const storeAPI = {
160
+ getState: () => storeState,
161
+ // Subscribe to ALL slices
162
+ subscribe: (listener) => {
163
+ const unsubs = Object.keys(storeState).map(
164
+ (k) => subscribeSlice(k, listener)
165
+ );
166
+ return () => unsubs.forEach((u) => u());
167
+ },
168
+ // THIS is the ONLY setter that should mutate state
169
+ setState: (key, payload, useDeepEqualCheck = false) => {
170
+ updateSlice(key, payload, useDeepEqualCheck);
171
+ }
172
+ };
173
+ tryRegisterSRASMDevtools("default", storeAPI);
145
174
  return { SRASMProvider, useSRASM, useSRASMAsync };
146
175
  }
147
176
 
package/dist/index.d.cts CHANGED
@@ -12,7 +12,7 @@ import React from 'react';
12
12
  * The `useSRASM` hook can be used by your React components to access and update the state.
13
13
  */
14
14
  declare function createStateStore<Slices extends Record<string, any>>(initialSlices: Slices): {
15
- SRASMProvider: ({ children, }: {
15
+ SRASMProvider: ({ children }: {
16
16
  children: React.ReactNode;
17
17
  }) => React.ReactElement<{
18
18
  children: React.ReactNode;
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ import React from 'react';
12
12
  * The `useSRASM` hook can be used by your React components to access and update the state.
13
13
  */
14
14
  declare function createStateStore<Slices extends Record<string, any>>(initialSlices: Slices): {
15
- SRASMProvider: ({ children, }: {
15
+ SRASMProvider: ({ children }: {
16
16
  children: React.ReactNode;
17
17
  }) => React.ReactElement<{
18
18
  children: React.ReactNode;
package/dist/index.js CHANGED
@@ -18,6 +18,22 @@ function deepEqual(obj1, obj2) {
18
18
  return true;
19
19
  }
20
20
 
21
+ // src/utils/tryRegisterSRASMDevtools.ts
22
+ function tryRegisterSRASMDevtools(storeName, api) {
23
+ if (typeof window === "undefined") return;
24
+ const w = window;
25
+ let tries = 0;
26
+ const t = setInterval(() => {
27
+ const dt = w.__SRASM_DEVTOOLS__;
28
+ if (dt && typeof dt.registerStore === "function") {
29
+ dt.registerStore(storeName, api);
30
+ clearInterval(t);
31
+ }
32
+ tries++;
33
+ if (tries > 50) clearInterval(t);
34
+ }, 100);
35
+ }
36
+
21
37
  // src/context/createStateStore.ts
22
38
  import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
23
39
  function createStateStore(initialSlices) {
@@ -101,11 +117,24 @@ function createStateStore(initialSlices) {
101
117
  refetch: fetchData
102
118
  };
103
119
  }
104
- const SRASMProvider = ({
105
- children
106
- }) => {
120
+ const SRASMProvider = ({ children }) => {
107
121
  return children;
108
122
  };
123
+ const storeAPI = {
124
+ getState: () => storeState,
125
+ // Subscribe to ALL slices
126
+ subscribe: (listener) => {
127
+ const unsubs = Object.keys(storeState).map(
128
+ (k) => subscribeSlice(k, listener)
129
+ );
130
+ return () => unsubs.forEach((u) => u());
131
+ },
132
+ // THIS is the ONLY setter that should mutate state
133
+ setState: (key, payload, useDeepEqualCheck = false) => {
134
+ updateSlice(key, payload, useDeepEqualCheck);
135
+ }
136
+ };
137
+ tryRegisterSRASMDevtools("default", storeAPI);
109
138
  return { SRASMProvider, useSRASM, useSRASMAsync };
110
139
  }
111
140
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "srasm",
3
3
  "private": false,
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",