@plasius/react-state 1.0.10 → 1.0.12

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 ADDED
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ MetadataStore: () => MetadataStore,
24
+ StoreProvider: () => StoreProvider,
25
+ __noop: () => __noop,
26
+ createScopedStoreContext: () => createScopedStoreContext,
27
+ createStore: () => createStore,
28
+ useDispatch: () => useDispatch,
29
+ useStore: () => useStore
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/types.ts
34
+ var __noop = null;
35
+
36
+ // src/create-scoped-store.tsx
37
+ var import_react = require("react");
38
+
39
+ // src/store.ts
40
+ function createStore(reducer, initialState) {
41
+ let state = initialState;
42
+ const listeners = /* @__PURE__ */ new Set();
43
+ const keyListeners = /* @__PURE__ */ new Map();
44
+ const selectorListeners = /* @__PURE__ */ new Set();
45
+ const getState = () => state;
46
+ const dispatch = (action) => {
47
+ const prevState = state;
48
+ const nextState = reducer(state, action);
49
+ if (Object.is(prevState, nextState)) {
50
+ state = nextState;
51
+ return;
52
+ }
53
+ state = nextState;
54
+ for (const listener of [...listeners]) listener();
55
+ for (const [key, set] of keyListeners.entries()) {
56
+ if (!Object.is(prevState[key], state[key])) {
57
+ for (const listener of [...set]) listener(state[key]);
58
+ }
59
+ }
60
+ selectorListeners.forEach((entry) => {
61
+ const nextValue = entry.selector(state);
62
+ if (!Object.is(entry.lastValue, nextValue)) {
63
+ entry.lastValue = nextValue;
64
+ entry.listener(nextValue);
65
+ }
66
+ });
67
+ };
68
+ const subscribe = (listener) => {
69
+ listeners.add(listener);
70
+ return () => {
71
+ listeners.delete(listener);
72
+ };
73
+ };
74
+ const subscribeToKey = (key, listener) => {
75
+ const set = keyListeners.get(key) ?? /* @__PURE__ */ new Set();
76
+ set.add(listener);
77
+ keyListeners.set(key, set);
78
+ return () => {
79
+ set.delete(listener);
80
+ if (set.size === 0) keyListeners.delete(key);
81
+ };
82
+ };
83
+ const subscribeWithSelector = (selector, listener) => {
84
+ const entry = {
85
+ selector,
86
+ listener,
87
+ lastValue: selector(state)
88
+ };
89
+ selectorListeners.add(entry);
90
+ return () => {
91
+ selectorListeners.delete(entry);
92
+ };
93
+ };
94
+ return {
95
+ getState,
96
+ dispatch,
97
+ subscribe,
98
+ subscribeToKey,
99
+ subscribeWithSelector
100
+ };
101
+ }
102
+
103
+ // src/create-scoped-store.tsx
104
+ var import_jsx_runtime = require("react/jsx-runtime");
105
+ function shallowEqual(a, b) {
106
+ if (Object.is(a, b)) return true;
107
+ if (typeof a !== "object" || a === null || typeof b !== "object" || b === null)
108
+ return false;
109
+ const ak = Object.keys(a), bk = Object.keys(b);
110
+ if (ak.length !== bk.length) return false;
111
+ for (let i = 0; i < ak.length; i++) {
112
+ const k = ak[i];
113
+ if (!Object.prototype.hasOwnProperty.call(b, k) || !Object.is(a[k], b[k]))
114
+ return false;
115
+ }
116
+ return true;
117
+ }
118
+ function createScopedStoreContext(reducer, initialState) {
119
+ const Context = (0, import_react.createContext)(null);
120
+ const store = createStore(reducer, initialState);
121
+ const Provider = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, { value: store, children });
122
+ const useStore2 = () => {
123
+ const ctx = (0, import_react.useContext)(Context);
124
+ if (!ctx) throw new Error("Store not found in context");
125
+ return (0, import_react.useSyncExternalStore)(ctx.subscribe, ctx.getState, ctx.getState);
126
+ };
127
+ const useDispatch2 = () => {
128
+ const ctx = (0, import_react.useContext)(Context);
129
+ if (!ctx) throw new Error("Dispatch not found in context");
130
+ return (action) => ctx.dispatch(action);
131
+ };
132
+ function useSelector(selector, isEqual = shallowEqual) {
133
+ const ctx = (0, import_react.useContext)(Context);
134
+ if (!ctx) throw new Error("Store not found in context");
135
+ const state = (0, import_react.useSyncExternalStore)(
136
+ ctx.subscribe,
137
+ ctx.getState,
138
+ ctx.getState
139
+ );
140
+ const lastRef = (0, import_react.useRef)(null);
141
+ const last = lastRef.current;
142
+ const nextSelected = selector(state);
143
+ if (last && last.state === state && isEqual(last.selected, nextSelected)) {
144
+ return last.selected;
145
+ }
146
+ lastRef.current = { state, selected: nextSelected };
147
+ return nextSelected;
148
+ }
149
+ return {
150
+ store,
151
+ Context,
152
+ Provider,
153
+ useStore: useStore2,
154
+ useDispatch: useDispatch2,
155
+ useSelector
156
+ };
157
+ }
158
+
159
+ // src/provider.tsx
160
+ var import_react2 = require("react");
161
+ var import_jsx_runtime2 = require("react/jsx-runtime");
162
+ var StoreContext = (0, import_react2.createContext)(void 0);
163
+ function useStoreInstance() {
164
+ const store = (0, import_react2.useContext)(StoreContext);
165
+ if (!store) {
166
+ throw new Error(
167
+ "StoreProvider is missing in the React tree. Wrap your app with <StoreProvider store={...}>."
168
+ );
169
+ }
170
+ return store;
171
+ }
172
+ function StoreProvider({
173
+ store,
174
+ children
175
+ }) {
176
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StoreContext.Provider, { value: store, children });
177
+ }
178
+ function useStore() {
179
+ const store = useStoreInstance();
180
+ const [state, setState] = (0, import_react2.useState)(() => store.getState());
181
+ (0, import_react2.useEffect)(() => {
182
+ const unsubscribe = store.subscribe(() => {
183
+ setState(store.getState());
184
+ });
185
+ return unsubscribe;
186
+ }, [store]);
187
+ return state;
188
+ }
189
+ function useDispatch() {
190
+ const store = useStoreInstance();
191
+ return store.dispatch;
192
+ }
193
+
194
+ // src/metadata-store.ts
195
+ var MetadataStore = class {
196
+ symbol;
197
+ constructor(description) {
198
+ this.symbol = Symbol(description);
199
+ }
200
+ set(target, meta) {
201
+ Object.defineProperty(target, this.symbol, {
202
+ value: meta,
203
+ writable: false,
204
+ enumerable: false
205
+ });
206
+ }
207
+ get(target) {
208
+ return target[this.symbol];
209
+ }
210
+ has(target) {
211
+ return this.symbol in target;
212
+ }
213
+ };
214
+ // Annotate the CommonJS export names for ESM import in node:
215
+ 0 && (module.exports = {
216
+ MetadataStore,
217
+ StoreProvider,
218
+ __noop,
219
+ createScopedStoreContext,
220
+ createStore,
221
+ useDispatch,
222
+ useStore
223
+ });
224
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/types.ts","../src/create-scoped-store.tsx","../src/store.ts","../src/provider.tsx","../src/metadata-store.ts"],"sourcesContent":["export * from \"./types.js\";\nexport * from \"./create-scoped-store.js\";\nexport * from \"./store.js\";\nexport * from \"./provider.js\";\nexport * from \"./metadata-store.js\";\n","export type Reducer<S, A> = (state: S, action: A) => S;\nexport type Listener = () => void;\nexport type Unsubscribe = () => void;\nexport const __noop = null;","import { createContext, useContext, useRef, useSyncExternalStore } from \"react\";\nimport type { IState, IAction, Store } from \"./store.js\";\nimport { createStore } from \"./store.js\";\n\nfunction shallowEqual(a: any, b: any) {\n if (Object.is(a, b)) return true;\n if (\n typeof a !== \"object\" ||\n a === null ||\n typeof b !== \"object\" ||\n b === null\n )\n return false;\n const ak = Object.keys(a),\n bk = Object.keys(b);\n if (ak.length !== bk.length) return false;\n for (let i = 0; i < ak.length; i++) {\n const k = ak[i] as string;\n if (\n !Object.prototype.hasOwnProperty.call(b, k) ||\n !Object.is((a as any)[k], (b as any)[k])\n )\n return false;\n }\n return true;\n}\n\nexport function createScopedStoreContext<S extends IState, A extends IAction>(\n reducer: (state: S, action: A) => S,\n initialState: S\n) {\n const Context = createContext<Store<S, A> | null>(null);\n\n const store = createStore(reducer, initialState);\n\n const Provider = ({ children }: { children: React.ReactNode }) => (\n <Context.Provider value={store}>{children}</Context.Provider>\n );\n\n const useStore = (): S => {\n const ctx = useContext(Context);\n if (!ctx) throw new Error(\"Store not found in context\");\n return useSyncExternalStore(ctx.subscribe, ctx.getState, ctx.getState);\n };\n\n const useDispatch = (): ((action: A) => void) => {\n const ctx = useContext(Context);\n if (!ctx) throw new Error(\"Dispatch not found in context\");\n return (action: A) => ctx.dispatch(action);\n };\n\n function useSelector<T>(\n selector: (state: S) => T,\n isEqual: (a: T, b: T) => boolean = shallowEqual\n ): T {\n const ctx = useContext(Context);\n if (!ctx) throw new Error(\"Store not found in context\");\n\n // Subscribe to the raw state snapshot (stable reference until a dispatch)\n const state = useSyncExternalStore(\n ctx.subscribe,\n ctx.getState,\n ctx.getState\n );\n\n // Cache the selected slice per state snapshot to avoid returning fresh objects during render\n const lastRef = useRef<{ state: S; selected: T } | null>(null);\n const last = lastRef.current;\n const nextSelected = selector(state);\n\n if (last && last.state === state && isEqual(last.selected, nextSelected)) {\n return last.selected; // return cached reference to satisfy getSnapshot caching\n }\n\n lastRef.current = { state, selected: nextSelected };\n return nextSelected;\n }\n\n return {\n store,\n Context,\n Provider,\n useStore,\n useDispatch,\n useSelector,\n };\n}\n","import type { Reducer, Listener } from \"./types.js\";\n\n// Allow narrower parameter types for callbacks without fighting variance\ntype BivariantListener<T> = {\n bivarianceHack(value: T): void;\n}[\"bivarianceHack\"];\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface IState {}\nexport interface IAction {\n type: string;\n}\n\nexport interface Store<S extends IState, A extends IAction> {\n getState(): S;\n dispatch(action: A): void;\n /**\n * Subscribe to all state changes.\n */\n subscribe(listener: Listener): () => void;\n /**\n * Subscribe to changes of a specific key in the state.\n */\n subscribeToKey<K extends keyof S>(\n key: K,\n listener: (value: S[K]) => void\n ): () => void;\n /**\n * Subscribe to changes in a selected value from the state.\n */\n subscribeWithSelector<T>(\n selector: (state: S) => T,\n listener: (selected: T) => void\n ): () => void;\n}\n\nexport function createStore<S extends IState, A extends IAction>(\n reducer: Reducer<S, A>,\n initialState: S\n): Store<S, A> {\n let state = initialState;\n const listeners = new Set<Listener>();\n const keyListeners = new Map<keyof S, Set<BivariantListener<S[keyof S]>>>();\n\n interface SelectorEntry<T> {\n selector: (state: S) => T;\n listener: BivariantListener<T>;\n lastValue: T;\n }\n const selectorListeners = new Set<SelectorEntry<unknown>>();\n\n const getState = () => state;\n\n const dispatch = (action: A) => {\n const prevState = state;\n const nextState = reducer(state, action);\n\n // Distinct-until-changed: if the reducer returns the same reference,\n // skip all notifications (prevents unnecessary re-renders).\n if (Object.is(prevState, nextState)) {\n state = nextState; // keep any identity guarantees from reducer\n return;\n }\n\n state = nextState;\n\n // Notify global listeners (iterate over a snapshot so unsubscribe during\n // notify does not skip the next listener)\n for (const listener of [...listeners]) listener();\n\n // Notify key listeners only when that key actually changed (Object.is)\n for (const [key, set] of keyListeners.entries()) {\n if (!Object.is(prevState[key], state[key])) {\n for (const listener of [...set]) listener(state[key]);\n }\n }\n\n // Notify selector listeners only when selected value changed (Object.is)\n selectorListeners.forEach((entry) => {\n const nextValue = (entry.selector as (s: S) => unknown)(state);\n if (!Object.is(entry.lastValue, nextValue)) {\n entry.lastValue = nextValue as unknown;\n (entry.listener as (v: unknown) => void)(nextValue);\n }\n });\n };\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n };\n\n const subscribeToKey = <K extends keyof S>(\n key: K,\n listener: (value: S[K]) => void\n ) => {\n const set =\n keyListeners.get(key) ?? new Set<BivariantListener<S[keyof S]>>();\n set.add(listener as unknown as BivariantListener<S[keyof S]>);\n keyListeners.set(key, set);\n return () => {\n set.delete(listener as unknown as BivariantListener<S[keyof S]>);\n if (set.size === 0) keyListeners.delete(key);\n };\n };\n\n const subscribeWithSelector = <T>(\n selector: (state: S) => T,\n listener: (selected: T) => void\n ) => {\n const entry: SelectorEntry<T> = {\n selector,\n listener: listener as BivariantListener<T>,\n lastValue: selector(state),\n };\n selectorListeners.add(entry as unknown as SelectorEntry<unknown>);\n return () => {\n selectorListeners.delete(entry as unknown as SelectorEntry<unknown>);\n };\n };\n\n return {\n getState,\n dispatch,\n subscribe,\n subscribeToKey,\n subscribeWithSelector,\n };\n}\n","import React, { createContext, useContext, useEffect, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { Store, IState, IAction } from \"./store.js\";\n\nconst StoreContext = createContext<Store<IState, IAction> | undefined>(undefined);\n\nfunction useStoreInstance<S extends IState, A extends IAction>(): Store<S, A> {\n const store = useContext(StoreContext) as Store<S, A> | undefined;\n if (!store) {\n throw new Error(\n \"StoreProvider is missing in the React tree. Wrap your app with <StoreProvider store={...}>.\"\n );\n }\n return store;\n}\n\ninterface StoreProviderProps<S extends IState, A extends IAction> {\n store: Store<S, A>;\n children: ReactNode;\n}\n\nexport function StoreProvider<S extends IState, A extends IAction>({\n store,\n children,\n}: StoreProviderProps<S, A>) {\n return (\n <StoreContext.Provider value={store as unknown as Store<IState, IAction>}>\n {children}\n </StoreContext.Provider>\n );\n}\n\nexport function useStore<S extends IState>(): S {\n const store = useStoreInstance<S, IAction>();\n const [state, setState] = useState<S>(() => store.getState());\n\n useEffect(() => {\n // Subscribe to store changes and update local state.\n const unsubscribe = store.subscribe(() => {\n setState(store.getState());\n });\n return unsubscribe;\n }, [store]);\n\n return state;\n}\n\nexport function useDispatch<A extends IAction>(): Store<IState, A>[\"dispatch\"] {\n const store = useStoreInstance<IState, A>();\n // Return the store's dispatch directly; consumers can call dispatch(action).\n return store.dispatch as Store<IState, A>[\"dispatch\"];\n}\n","// metadata-store.ts\nexport class MetadataStore<T extends object, Meta extends object> {\n private readonly symbol: symbol;\n\n constructor(description: string) {\n this.symbol = Symbol(description);\n }\n\n set(target: T, meta: Meta) {\n Object.defineProperty(target, this.symbol as PropertyKey, {\n value: meta,\n writable: false,\n enumerable: false,\n });\n }\n\n get(target: T): Meta | undefined {\n return (target as Record<PropertyKey, Meta>)[this.symbol as PropertyKey];\n }\n\n has(target: T): boolean {\n return (this.symbol as PropertyKey) in target;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,SAAS;;;ACHtB,mBAAwE;;;ACoCjE,SAAS,YACd,SACA,cACa;AACb,MAAI,QAAQ;AACZ,QAAM,YAAY,oBAAI,IAAc;AACpC,QAAM,eAAe,oBAAI,IAAiD;AAO1E,QAAM,oBAAoB,oBAAI,IAA4B;AAE1D,QAAM,WAAW,MAAM;AAEvB,QAAM,WAAW,CAAC,WAAc;AAC9B,UAAM,YAAY;AAClB,UAAM,YAAY,QAAQ,OAAO,MAAM;AAIvC,QAAI,OAAO,GAAG,WAAW,SAAS,GAAG;AACnC,cAAQ;AACR;AAAA,IACF;AAEA,YAAQ;AAIR,eAAW,YAAY,CAAC,GAAG,SAAS,EAAG,UAAS;AAGhD,eAAW,CAAC,KAAK,GAAG,KAAK,aAAa,QAAQ,GAAG;AAC/C,UAAI,CAAC,OAAO,GAAG,UAAU,GAAG,GAAG,MAAM,GAAG,CAAC,GAAG;AAC1C,mBAAW,YAAY,CAAC,GAAG,GAAG,EAAG,UAAS,MAAM,GAAG,CAAC;AAAA,MACtD;AAAA,IACF;AAGA,sBAAkB,QAAQ,CAAC,UAAU;AACnC,YAAM,YAAa,MAAM,SAA+B,KAAK;AAC7D,UAAI,CAAC,OAAO,GAAG,MAAM,WAAW,SAAS,GAAG;AAC1C,cAAM,YAAY;AAClB,QAAC,MAAM,SAAkC,SAA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W,YAAY;AACrC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,cAAmD;AAAA,EACjE;AAAA,EACA;AACF,GAA6B;AAC3B,SACE,6CAAC,aAAa,UAAb,EAAsB,OAAO,OAC3B,UACH;AAEJ;AAEO,SAAS,WAAgC;AAC9C,QAAM,QAAQ,iBAA6B;AAC3C,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAY,MAAM,MAAM,SAAS,CAAC;AAE5D,+BAAU,MAAM;AAEd,UAAM,cAAc,MAAM,UAAU,MAAM;AACxC,eAAS,MAAM,SAAS,CAAC;AAAA,IAC3B,CAAC;AACD,WAAO;AAAA,EACT,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO;AACT;AAEO,SAAS,cAA+D;AAC7E,QAAM,QAAQ,iBAA4B;AAE1C,SAAO,MAAM;AACf;;;AClDO,IAAM,gBAAN,MAA2D;AAAA,EAC/C;AAAA,EAEjB,YAAY,aAAqB;AAC/B,SAAK,SAAS,OAAO,WAAW;AAAA,EAClC;AAAA,EAEA,IAAI,QAAW,MAAY;AACzB,WAAO,eAAe,QAAQ,KAAK,QAAuB;AAAA,MACxD,OAAO;AAAA,MACP,UAAU;AAAA,MACV,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AAAA,EAEA,IAAI,QAA6B;AAC/B,WAAQ,OAAqC,KAAK,MAAqB;AAAA,EACzE;AAAA,EAEA,IAAI,QAAoB;AACtB,WAAQ,KAAK,UAA0B;AAAA,EACzC;AACF;","names":["useStore","useDispatch","import_react","import_jsx_runtime"]}
@@ -0,0 +1,60 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+
5
+ type Reducer<S, A> = (state: S, action: A) => S;
6
+ type Listener = () => void;
7
+ type Unsubscribe = () => void;
8
+ declare const __noop: null;
9
+
10
+ interface IState {
11
+ }
12
+ interface IAction {
13
+ type: string;
14
+ }
15
+ interface Store<S extends IState, A extends IAction> {
16
+ getState(): S;
17
+ dispatch(action: A): void;
18
+ /**
19
+ * Subscribe to all state changes.
20
+ */
21
+ subscribe(listener: Listener): () => void;
22
+ /**
23
+ * Subscribe to changes of a specific key in the state.
24
+ */
25
+ subscribeToKey<K extends keyof S>(key: K, listener: (value: S[K]) => void): () => void;
26
+ /**
27
+ * Subscribe to changes in a selected value from the state.
28
+ */
29
+ subscribeWithSelector<T>(selector: (state: S) => T, listener: (selected: T) => void): () => void;
30
+ }
31
+ declare function createStore<S extends IState, A extends IAction>(reducer: Reducer<S, A>, initialState: S): Store<S, A>;
32
+
33
+ declare function createScopedStoreContext<S extends IState, A extends IAction>(reducer: (state: S, action: A) => S, initialState: S): {
34
+ store: Store<S, A>;
35
+ Context: react.Context<Store<S, A> | null>;
36
+ Provider: ({ children }: {
37
+ children: React.ReactNode;
38
+ }) => react_jsx_runtime.JSX.Element;
39
+ useStore: () => S;
40
+ useDispatch: () => ((action: A) => void);
41
+ useSelector: <T>(selector: (state: S) => T, isEqual?: (a: T, b: T) => boolean) => T;
42
+ };
43
+
44
+ interface StoreProviderProps<S extends IState, A extends IAction> {
45
+ store: Store<S, A>;
46
+ children: ReactNode;
47
+ }
48
+ declare function StoreProvider<S extends IState, A extends IAction>({ store, children, }: StoreProviderProps<S, A>): react_jsx_runtime.JSX.Element;
49
+ declare function useStore<S extends IState>(): S;
50
+ declare function useDispatch<A extends IAction>(): Store<IState, A>["dispatch"];
51
+
52
+ declare class MetadataStore<T extends object, Meta extends object> {
53
+ private readonly symbol;
54
+ constructor(description: string);
55
+ set(target: T, meta: Meta): void;
56
+ get(target: T): Meta | undefined;
57
+ has(target: T): boolean;
58
+ }
59
+
60
+ export { type IAction, type IState, type Listener, MetadataStore, type Reducer, type Store, StoreProvider, type Unsubscribe, __noop, createScopedStoreContext, createStore, useDispatch, useStore };
@@ -0,0 +1,60 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+
5
+ type Reducer<S, A> = (state: S, action: A) => S;
6
+ type Listener = () => void;
7
+ type Unsubscribe = () => void;
8
+ declare const __noop: null;
9
+
10
+ interface IState {
11
+ }
12
+ interface IAction {
13
+ type: string;
14
+ }
15
+ interface Store<S extends IState, A extends IAction> {
16
+ getState(): S;
17
+ dispatch(action: A): void;
18
+ /**
19
+ * Subscribe to all state changes.
20
+ */
21
+ subscribe(listener: Listener): () => void;
22
+ /**
23
+ * Subscribe to changes of a specific key in the state.
24
+ */
25
+ subscribeToKey<K extends keyof S>(key: K, listener: (value: S[K]) => void): () => void;
26
+ /**
27
+ * Subscribe to changes in a selected value from the state.
28
+ */
29
+ subscribeWithSelector<T>(selector: (state: S) => T, listener: (selected: T) => void): () => void;
30
+ }
31
+ declare function createStore<S extends IState, A extends IAction>(reducer: Reducer<S, A>, initialState: S): Store<S, A>;
32
+
33
+ declare function createScopedStoreContext<S extends IState, A extends IAction>(reducer: (state: S, action: A) => S, initialState: S): {
34
+ store: Store<S, A>;
35
+ Context: react.Context<Store<S, A> | null>;
36
+ Provider: ({ children }: {
37
+ children: React.ReactNode;
38
+ }) => react_jsx_runtime.JSX.Element;
39
+ useStore: () => S;
40
+ useDispatch: () => ((action: A) => void);
41
+ useSelector: <T>(selector: (state: S) => T, isEqual?: (a: T, b: T) => boolean) => T;
42
+ };
43
+
44
+ interface StoreProviderProps<S extends IState, A extends IAction> {
45
+ store: Store<S, A>;
46
+ children: ReactNode;
47
+ }
48
+ declare function StoreProvider<S extends IState, A extends IAction>({ store, children, }: StoreProviderProps<S, A>): react_jsx_runtime.JSX.Element;
49
+ declare function useStore<S extends IState>(): S;
50
+ declare function useDispatch<A extends IAction>(): Store<IState, A>["dispatch"];
51
+
52
+ declare class MetadataStore<T extends object, Meta extends object> {
53
+ private readonly symbol;
54
+ constructor(description: string);
55
+ set(target: T, meta: Meta): void;
56
+ get(target: T): Meta | undefined;
57
+ has(target: T): boolean;
58
+ }
59
+
60
+ export { type IAction, type IState, type Listener, MetadataStore, type Reducer, type Store, StoreProvider, type Unsubscribe, __noop, createScopedStoreContext, createStore, useDispatch, useStore };
package/dist/index.js ADDED
@@ -0,0 +1,191 @@
1
+ // src/types.ts
2
+ var __noop = null;
3
+
4
+ // src/create-scoped-store.tsx
5
+ import { createContext, useContext, useRef, useSyncExternalStore } from "react";
6
+
7
+ // src/store.ts
8
+ function createStore(reducer, initialState) {
9
+ let state = initialState;
10
+ const listeners = /* @__PURE__ */ new Set();
11
+ const keyListeners = /* @__PURE__ */ new Map();
12
+ const selectorListeners = /* @__PURE__ */ new Set();
13
+ const getState = () => state;
14
+ const dispatch = (action) => {
15
+ const prevState = state;
16
+ const nextState = reducer(state, action);
17
+ if (Object.is(prevState, nextState)) {
18
+ state = nextState;
19
+ return;
20
+ }
21
+ state = nextState;
22
+ for (const listener of [...listeners]) listener();
23
+ for (const [key, set] of keyListeners.entries()) {
24
+ if (!Object.is(prevState[key], state[key])) {
25
+ for (const listener of [...set]) listener(state[key]);
26
+ }
27
+ }
28
+ selectorListeners.forEach((entry) => {
29
+ const nextValue = entry.selector(state);
30
+ if (!Object.is(entry.lastValue, nextValue)) {
31
+ entry.lastValue = nextValue;
32
+ entry.listener(nextValue);
33
+ }
34
+ });
35
+ };
36
+ const subscribe = (listener) => {
37
+ listeners.add(listener);
38
+ return () => {
39
+ listeners.delete(listener);
40
+ };
41
+ };
42
+ const subscribeToKey = (key, listener) => {
43
+ const set = keyListeners.get(key) ?? /* @__PURE__ */ new Set();
44
+ set.add(listener);
45
+ keyListeners.set(key, set);
46
+ return () => {
47
+ set.delete(listener);
48
+ if (set.size === 0) keyListeners.delete(key);
49
+ };
50
+ };
51
+ const subscribeWithSelector = (selector, listener) => {
52
+ const entry = {
53
+ selector,
54
+ listener,
55
+ lastValue: selector(state)
56
+ };
57
+ selectorListeners.add(entry);
58
+ return () => {
59
+ selectorListeners.delete(entry);
60
+ };
61
+ };
62
+ return {
63
+ getState,
64
+ dispatch,
65
+ subscribe,
66
+ subscribeToKey,
67
+ subscribeWithSelector
68
+ };
69
+ }
70
+
71
+ // src/create-scoped-store.tsx
72
+ import { jsx } from "react/jsx-runtime";
73
+ function shallowEqual(a, b) {
74
+ if (Object.is(a, b)) return true;
75
+ if (typeof a !== "object" || a === null || typeof b !== "object" || b === null)
76
+ return false;
77
+ const ak = Object.keys(a), bk = Object.keys(b);
78
+ if (ak.length !== bk.length) return false;
79
+ for (let i = 0; i < ak.length; i++) {
80
+ const k = ak[i];
81
+ if (!Object.prototype.hasOwnProperty.call(b, k) || !Object.is(a[k], b[k]))
82
+ return false;
83
+ }
84
+ return true;
85
+ }
86
+ function createScopedStoreContext(reducer, initialState) {
87
+ const Context = createContext(null);
88
+ const store = createStore(reducer, initialState);
89
+ const Provider = ({ children }) => /* @__PURE__ */ jsx(Context.Provider, { value: store, children });
90
+ const useStore2 = () => {
91
+ const ctx = useContext(Context);
92
+ if (!ctx) throw new Error("Store not found in context");
93
+ return useSyncExternalStore(ctx.subscribe, ctx.getState, ctx.getState);
94
+ };
95
+ const useDispatch2 = () => {
96
+ const ctx = useContext(Context);
97
+ if (!ctx) throw new Error("Dispatch not found in context");
98
+ return (action) => ctx.dispatch(action);
99
+ };
100
+ function useSelector(selector, isEqual = shallowEqual) {
101
+ const ctx = useContext(Context);
102
+ if (!ctx) throw new Error("Store not found in context");
103
+ const state = useSyncExternalStore(
104
+ ctx.subscribe,
105
+ ctx.getState,
106
+ ctx.getState
107
+ );
108
+ const lastRef = useRef(null);
109
+ const last = lastRef.current;
110
+ const nextSelected = selector(state);
111
+ if (last && last.state === state && isEqual(last.selected, nextSelected)) {
112
+ return last.selected;
113
+ }
114
+ lastRef.current = { state, selected: nextSelected };
115
+ return nextSelected;
116
+ }
117
+ return {
118
+ store,
119
+ Context,
120
+ Provider,
121
+ useStore: useStore2,
122
+ useDispatch: useDispatch2,
123
+ useSelector
124
+ };
125
+ }
126
+
127
+ // src/provider.tsx
128
+ import { createContext as createContext2, useContext as useContext2, useEffect, useState } from "react";
129
+ import { jsx as jsx2 } from "react/jsx-runtime";
130
+ var StoreContext = createContext2(void 0);
131
+ function useStoreInstance() {
132
+ const store = useContext2(StoreContext);
133
+ if (!store) {
134
+ throw new Error(
135
+ "StoreProvider is missing in the React tree. Wrap your app with <StoreProvider store={...}>."
136
+ );
137
+ }
138
+ return store;
139
+ }
140
+ function StoreProvider({
141
+ store,
142
+ children
143
+ }) {
144
+ return /* @__PURE__ */ jsx2(StoreContext.Provider, { value: store, children });
145
+ }
146
+ function useStore() {
147
+ const store = useStoreInstance();
148
+ const [state, setState] = useState(() => store.getState());
149
+ useEffect(() => {
150
+ const unsubscribe = store.subscribe(() => {
151
+ setState(store.getState());
152
+ });
153
+ return unsubscribe;
154
+ }, [store]);
155
+ return state;
156
+ }
157
+ function useDispatch() {
158
+ const store = useStoreInstance();
159
+ return store.dispatch;
160
+ }
161
+
162
+ // src/metadata-store.ts
163
+ var MetadataStore = class {
164
+ symbol;
165
+ constructor(description) {
166
+ this.symbol = Symbol(description);
167
+ }
168
+ set(target, meta) {
169
+ Object.defineProperty(target, this.symbol, {
170
+ value: meta,
171
+ writable: false,
172
+ enumerable: false
173
+ });
174
+ }
175
+ get(target) {
176
+ return target[this.symbol];
177
+ }
178
+ has(target) {
179
+ return this.symbol in target;
180
+ }
181
+ };
182
+ export {
183
+ MetadataStore,
184
+ StoreProvider,
185
+ __noop,
186
+ createScopedStoreContext,
187
+ createStore,
188
+ useDispatch,
189
+ useStore
190
+ };
191
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../src/create-scoped-store.tsx","../src/store.ts","../src/provider.tsx","../src/metadata-store.ts"],"sourcesContent":["export type Reducer<S, A> = (state: S, action: A) => S;\nexport type Listener = () => void;\nexport type Unsubscribe = () => void;\nexport const __noop = null;","import { createContext, useContext, useRef, useSyncExternalStore } from \"react\";\nimport type { IState, IAction, Store } from \"./store.js\";\nimport { createStore } from \"./store.js\";\n\nfunction shallowEqual(a: any, b: any) {\n if (Object.is(a, b)) return true;\n if (\n typeof a !== \"object\" ||\n a === null ||\n typeof b !== \"object\" ||\n b === null\n )\n return false;\n const ak = Object.keys(a),\n bk = Object.keys(b);\n if (ak.length !== bk.length) return false;\n for (let i = 0; i < ak.length; i++) {\n const k = ak[i] as string;\n if (\n !Object.prototype.hasOwnProperty.call(b, k) ||\n !Object.is((a as any)[k], (b as any)[k])\n )\n return false;\n }\n return true;\n}\n\nexport function createScopedStoreContext<S extends IState, A extends IAction>(\n reducer: (state: S, action: A) => S,\n initialState: S\n) {\n const Context = createContext<Store<S, A> | null>(null);\n\n const store = createStore(reducer, initialState);\n\n const Provider = ({ children }: { children: React.ReactNode }) => (\n <Context.Provider value={store}>{children}</Context.Provider>\n );\n\n const useStore = (): S => {\n const ctx = useContext(Context);\n if (!ctx) throw new Error(\"Store not found in context\");\n return useSyncExternalStore(ctx.subscribe, ctx.getState, ctx.getState);\n };\n\n const useDispatch = (): ((action: A) => void) => {\n const ctx = useContext(Context);\n if (!ctx) throw new Error(\"Dispatch not found in context\");\n return (action: A) => ctx.dispatch(action);\n };\n\n function useSelector<T>(\n selector: (state: S) => T,\n isEqual: (a: T, b: T) => boolean = shallowEqual\n ): T {\n const ctx = useContext(Context);\n if (!ctx) throw new Error(\"Store not found in context\");\n\n // Subscribe to the raw state snapshot (stable reference until a dispatch)\n const state = useSyncExternalStore(\n ctx.subscribe,\n ctx.getState,\n ctx.getState\n );\n\n // Cache the selected slice per state snapshot to avoid returning fresh objects during render\n const lastRef = useRef<{ state: S; selected: T } | null>(null);\n const last = lastRef.current;\n const nextSelected = selector(state);\n\n if (last && last.state === state && isEqual(last.selected, nextSelected)) {\n return last.selected; // return cached reference to satisfy getSnapshot caching\n }\n\n lastRef.current = { state, selected: nextSelected };\n return nextSelected;\n }\n\n return {\n store,\n Context,\n Provider,\n useStore,\n useDispatch,\n useSelector,\n };\n}\n","import type { Reducer, Listener } from \"./types.js\";\n\n// Allow narrower parameter types for callbacks without fighting variance\ntype BivariantListener<T> = {\n bivarianceHack(value: T): void;\n}[\"bivarianceHack\"];\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface IState {}\nexport interface IAction {\n type: string;\n}\n\nexport interface Store<S extends IState, A extends IAction> {\n getState(): S;\n dispatch(action: A): void;\n /**\n * Subscribe to all state changes.\n */\n subscribe(listener: Listener): () => void;\n /**\n * Subscribe to changes of a specific key in the state.\n */\n subscribeToKey<K extends keyof S>(\n key: K,\n listener: (value: S[K]) => void\n ): () => void;\n /**\n * Subscribe to changes in a selected value from the state.\n */\n subscribeWithSelector<T>(\n selector: (state: S) => T,\n listener: (selected: T) => void\n ): () => void;\n}\n\nexport function createStore<S extends IState, A extends IAction>(\n reducer: Reducer<S, A>,\n initialState: S\n): Store<S, A> {\n let state = initialState;\n const listeners = new Set<Listener>();\n const keyListeners = new Map<keyof S, Set<BivariantListener<S[keyof S]>>>();\n\n interface SelectorEntry<T> {\n selector: (state: S) => T;\n listener: BivariantListener<T>;\n lastValue: T;\n }\n const selectorListeners = new Set<SelectorEntry<unknown>>();\n\n const getState = () => state;\n\n const dispatch = (action: A) => {\n const prevState = state;\n const nextState = reducer(state, action);\n\n // Distinct-until-changed: if the reducer returns the same reference,\n // skip all notifications (prevents unnecessary re-renders).\n if (Object.is(prevState, nextState)) {\n state = nextState; // keep any identity guarantees from reducer\n return;\n }\n\n state = nextState;\n\n // Notify global listeners (iterate over a snapshot so unsubscribe during\n // notify does not skip the next listener)\n for (const listener of [...listeners]) listener();\n\n // Notify key listeners only when that key actually changed (Object.is)\n for (const [key, set] of keyListeners.entries()) {\n if (!Object.is(prevState[key], state[key])) {\n for (const listener of [...set]) listener(state[key]);\n }\n }\n\n // Notify selector listeners only when selected value changed (Object.is)\n selectorListeners.forEach((entry) => {\n const nextValue = (entry.selector as (s: S) => unknown)(state);\n if (!Object.is(entry.lastValue, nextValue)) {\n entry.lastValue = nextValue as unknown;\n (entry.listener as (v: unknown) => void)(nextValue);\n }\n });\n };\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n };\n\n const subscribeToKey = <K extends keyof S>(\n key: K,\n listener: (value: S[K]) => void\n ) => {\n const set =\n keyListeners.get(key) ?? new Set<BivariantListener<S[keyof S]>>();\n set.add(listener as unknown as BivariantListener<S[keyof S]>);\n keyListeners.set(key, set);\n return () => {\n set.delete(listener as unknown as BivariantListener<S[keyof S]>);\n if (set.size === 0) keyListeners.delete(key);\n };\n };\n\n const subscribeWithSelector = <T>(\n selector: (state: S) => T,\n listener: (selected: T) => void\n ) => {\n const entry: SelectorEntry<T> = {\n selector,\n listener: listener as BivariantListener<T>,\n lastValue: selector(state),\n };\n selectorListeners.add(entry as unknown as SelectorEntry<unknown>);\n return () => {\n selectorListeners.delete(entry as unknown as SelectorEntry<unknown>);\n };\n };\n\n return {\n getState,\n dispatch,\n subscribe,\n subscribeToKey,\n subscribeWithSelector,\n };\n}\n","import React, { createContext, useContext, useEffect, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport type { Store, IState, IAction } from \"./store.js\";\n\nconst StoreContext = createContext<Store<IState, IAction> | undefined>(undefined);\n\nfunction useStoreInstance<S extends IState, A extends IAction>(): Store<S, A> {\n const store = useContext(StoreContext) as Store<S, A> | undefined;\n if (!store) {\n throw new Error(\n \"StoreProvider is missing in the React tree. Wrap your app with <StoreProvider store={...}>.\"\n );\n }\n return store;\n}\n\ninterface StoreProviderProps<S extends IState, A extends IAction> {\n store: Store<S, A>;\n children: ReactNode;\n}\n\nexport function StoreProvider<S extends IState, A extends IAction>({\n store,\n children,\n}: StoreProviderProps<S, A>) {\n return (\n <StoreContext.Provider value={store as unknown as Store<IState, IAction>}>\n {children}\n </StoreContext.Provider>\n );\n}\n\nexport function useStore<S extends IState>(): S {\n const store = useStoreInstance<S, IAction>();\n const [state, setState] = useState<S>(() => store.getState());\n\n useEffect(() => {\n // Subscribe to store changes and update local state.\n const unsubscribe = store.subscribe(() => {\n setState(store.getState());\n });\n return unsubscribe;\n }, [store]);\n\n return state;\n}\n\nexport function useDispatch<A extends IAction>(): Store<IState, A>[\"dispatch\"] {\n const store = useStoreInstance<IState, A>();\n // Return the store's dispatch directly; consumers can call dispatch(action).\n return store.dispatch as Store<IState, A>[\"dispatch\"];\n}\n","// metadata-store.ts\nexport class MetadataStore<T extends object, Meta extends object> {\n private readonly symbol: symbol;\n\n constructor(description: string) {\n this.symbol = Symbol(description);\n }\n\n set(target: T, meta: Meta) {\n Object.defineProperty(target, this.symbol as PropertyKey, {\n value: meta,\n writable: false,\n enumerable: false,\n });\n }\n\n get(target: T): Meta | undefined {\n return (target as Record<PropertyKey, Meta>)[this.symbol as PropertyKey];\n }\n\n has(target: T): boolean {\n return (this.symbol as PropertyKey) in target;\n }\n}\n"],"mappings":";AAGO,IAAM,SAAS;;;ACHtB,SAAS,eAAe,YAAY,QAAQ,4BAA4B;;;ACoCjE,SAAS,YACd,SACA,cACa;AACb,MAAI,QAAQ;AACZ,QAAM,YAAY,oBAAI,IAAc;AACpC,QAAM,eAAe,oBAAI,IAAiD;AAO1E,QAAM,oBAAoB,oBAAI,IAA4B;AAE1D,QAAM,WAAW,MAAM;AAEvB,QAAM,WAAW,CAAC,WAAc;AAC9B,UAAM,YAAY;AAClB,UAAM,YAAY,QAAQ,OAAO,MAAM;AAIvC,QAAI,OAAO,GAAG,WAAW,SAAS,GAAG;AACnC,cAAQ;AACR;AAAA,IACF;AAEA,YAAQ;AAIR,eAAW,YAAY,CAAC,GAAG,SAAS,EAAG,UAAS;AAGhD,eAAW,CAAC,KAAK,GAAG,KAAK,aAAa,QAAQ,GAAG;AAC/C,UAAI,CAAC,OAAO,GAAG,UAAU,GAAG,GAAG,MAAM,GAAG,CAAC,GAAG;AAC1C,mBAAW,YAAY,CAAC,GAAG,GAAG,EAAG,UAAS,MAAM,GAAG,CAAC;AAAA,MACtD;AAAA,IACF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 -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasius/react-state",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Tiny, testable, typesafe React Scoped Store helper.",
5
5
  "keywords": [
6
6
  "react",
@@ -30,15 +30,17 @@
30
30
  "license": "Apache-2.0",
31
31
  "author": "Plasius LTD",
32
32
  "type": "module",
33
- "main": "./dist/index.cjs",
34
- "module": "./dist/index.js",
35
- "types": "./dist/index.d.ts",
33
+ "sideEffects": false,
34
+ "files": [
35
+ "dist"
36
+ ],
36
37
  "exports": {
37
38
  ".": {
38
39
  "types": "./dist/index.d.ts",
39
40
  "import": "./dist/index.js",
40
41
  "require": "./dist/index.cjs"
41
- }
42
+ },
43
+ "./package.json": "./package.json"
42
44
  },
43
45
  "scripts": {
44
46
  "build": "tsup",
@@ -68,5 +70,15 @@
68
70
  "dependencies": {
69
71
  "@types/react": "^19.1.13",
70
72
  "react": "^19.1.1"
71
- }
73
+ },
74
+ "funding": [
75
+ {
76
+ "type": "patreon",
77
+ "url": "https://patreon.com/PlasiusLTD"
78
+ },
79
+ {
80
+ "type": "github",
81
+ "url": "https://github.com/sponsors/Plasius-LTD"
82
+ }
83
+ ]
72
84
  }
package/.eslintrc.cjs DELETED
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- parser: "@typescript-eslint/parser",
4
- plugins: ["@typescript-eslint"],
5
- extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
6
- ignorePatterns: ["dist", "node_modules"],
7
- };