@fun-tools/store 1.0.0 → 1.0.2
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 +494 -234
- package/dist/chunk-BEP626V3.js +245 -0
- package/dist/chunk-BEP626V3.js.map +1 -0
- package/dist/core/index.cjs +273 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.cjs +154 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -42
- package/dist/index.d.ts +51 -42
- package/dist/index.js +6 -177
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +273 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +2 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +11 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +49 -40
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// src/react/createStore.ts
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
|
|
4
|
+
// src/utils/functions/runAction.ts
|
|
5
|
+
function runAction(action, val) {
|
|
6
|
+
if (typeof action === "function") {
|
|
7
|
+
return action(val);
|
|
8
|
+
}
|
|
9
|
+
return action;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/core/configStore/cookAutoBuildHandlers/Handlers/array.handlers.ts
|
|
13
|
+
function arrayHandlers(getState, setState) {
|
|
14
|
+
if (!Array.isArray(getState())) return {};
|
|
15
|
+
return {
|
|
16
|
+
push: (val) => {
|
|
17
|
+
setState([...getState(), val]);
|
|
18
|
+
return val;
|
|
19
|
+
},
|
|
20
|
+
pop: () => {
|
|
21
|
+
const state = getState();
|
|
22
|
+
setState([...state.slice(0, -1)]);
|
|
23
|
+
return state[state.length - 1];
|
|
24
|
+
},
|
|
25
|
+
shift: () => {
|
|
26
|
+
const state = getState();
|
|
27
|
+
setState([...state.slice(1)]);
|
|
28
|
+
return state[0];
|
|
29
|
+
},
|
|
30
|
+
unShift: (val) => {
|
|
31
|
+
const state = getState();
|
|
32
|
+
setState([val, ...state]);
|
|
33
|
+
return val;
|
|
34
|
+
},
|
|
35
|
+
update: (index, val) => {
|
|
36
|
+
const state = getState();
|
|
37
|
+
const newState = [...state];
|
|
38
|
+
newState[index] = runAction(val, state[index]);
|
|
39
|
+
setState(newState);
|
|
40
|
+
return newState[index];
|
|
41
|
+
},
|
|
42
|
+
remove: (index) => {
|
|
43
|
+
const state = getState();
|
|
44
|
+
const removed = state[index];
|
|
45
|
+
const newState = state.filter((_, i) => i !== index);
|
|
46
|
+
setState([...newState]);
|
|
47
|
+
return removed;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/core/configStore/cookAutoBuildHandlers/Handlers/bool.handlers.ts
|
|
53
|
+
function boolHandlers(getState, setState) {
|
|
54
|
+
if (typeof getState() !== "boolean") return {};
|
|
55
|
+
return {
|
|
56
|
+
toggle: () => {
|
|
57
|
+
const state = getState();
|
|
58
|
+
setState(!state);
|
|
59
|
+
return state;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/core/configStore/cookAutoBuildHandlers/Handlers/object.handler.ts
|
|
65
|
+
function objectHandlers(getState, setState) {
|
|
66
|
+
if (typeof getState() !== "object") return {};
|
|
67
|
+
return {
|
|
68
|
+
update: (_path, val) => {
|
|
69
|
+
const state = getState();
|
|
70
|
+
const path = _path.toString().split(".");
|
|
71
|
+
const fn = (obj, index = 0) => {
|
|
72
|
+
var _a;
|
|
73
|
+
if (path.length === index) {
|
|
74
|
+
return runAction(val, obj);
|
|
75
|
+
}
|
|
76
|
+
const key = path[index];
|
|
77
|
+
return {
|
|
78
|
+
...obj,
|
|
79
|
+
[key]: fn((_a = obj == null ? void 0 : obj[key]) != null ? _a : {}, index + 1)
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const newState = fn(state);
|
|
83
|
+
setState(newState);
|
|
84
|
+
return newState;
|
|
85
|
+
},
|
|
86
|
+
updateMany: (val) => {
|
|
87
|
+
const state = getState();
|
|
88
|
+
const fn = (target, source) => {
|
|
89
|
+
if (typeof source !== "object" || source === null) return source;
|
|
90
|
+
if (Array.isArray(source)) return source;
|
|
91
|
+
const result = { ...target };
|
|
92
|
+
for (const key in source) {
|
|
93
|
+
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
94
|
+
result[key] = fn(target[key], source[key]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
99
|
+
const newState = fn(state, val);
|
|
100
|
+
setState(newState);
|
|
101
|
+
return newState;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/core/configStore/cookAutoBuildHandlers/index.ts
|
|
107
|
+
function cookAutoBuildHandlers(states, notify) {
|
|
108
|
+
const defaultStates = JSON.parse(JSON.stringify(states));
|
|
109
|
+
return Object.fromEntries(
|
|
110
|
+
Object.entries(states).map(([key, val]) => {
|
|
111
|
+
const getState = () => states[key];
|
|
112
|
+
const setState = (newStates) => {
|
|
113
|
+
states[key] = newStates;
|
|
114
|
+
notify();
|
|
115
|
+
};
|
|
116
|
+
const handlers = {
|
|
117
|
+
set: (action) => {
|
|
118
|
+
setState(runAction(action, getState()));
|
|
119
|
+
},
|
|
120
|
+
reset: () => {
|
|
121
|
+
setState(defaultStates[key]);
|
|
122
|
+
},
|
|
123
|
+
...Array.isArray(val) ? arrayHandlers(getState, setState) : typeof val === "object" ? objectHandlers(getState, setState) : typeof val === "boolean" ? boolHandlers(getState, setState) : {}
|
|
124
|
+
};
|
|
125
|
+
return [key, handlers];
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/utils/functions/mapObject.ts
|
|
131
|
+
function mapObject(obj, cb) {
|
|
132
|
+
return Object.fromEntries(
|
|
133
|
+
Object.entries(obj).map(([key, val]) => [key, cb(val)])
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/utils/functions/shallowEqual.ts
|
|
138
|
+
function shallowEqual(a, b) {
|
|
139
|
+
if (a === b) return true;
|
|
140
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
141
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
142
|
+
const key1 = Object.keys(a);
|
|
143
|
+
const key2 = Object.keys(b);
|
|
144
|
+
if (key1.length !== key2.length) return false;
|
|
145
|
+
for (let key of key1) {
|
|
146
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
147
|
+
if (!Object.is(a[key], b[key])) return false;
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/core/configStore/index.ts
|
|
153
|
+
function configStore({
|
|
154
|
+
states,
|
|
155
|
+
syncHandlers,
|
|
156
|
+
asyncHandlers
|
|
157
|
+
}) {
|
|
158
|
+
const handlers = Object.freeze({
|
|
159
|
+
...mapObject(syncHandlers != null ? syncHandlers : {}, (handler) => (...args) => {
|
|
160
|
+
handler(states, ...args);
|
|
161
|
+
notify();
|
|
162
|
+
}),
|
|
163
|
+
...mapObject(asyncHandlers != null ? asyncHandlers : {}, (handler) => async (...args) => {
|
|
164
|
+
await handler(states, ...args);
|
|
165
|
+
notify();
|
|
166
|
+
}),
|
|
167
|
+
...cookAutoBuildHandlers(states, notify)
|
|
168
|
+
});
|
|
169
|
+
const consumers = /* @__PURE__ */ new Set();
|
|
170
|
+
function consume(consumer) {
|
|
171
|
+
consumers.add(consumer);
|
|
172
|
+
return () => consumers.delete(consumer);
|
|
173
|
+
}
|
|
174
|
+
function notify() {
|
|
175
|
+
consumers.forEach((con) => con());
|
|
176
|
+
}
|
|
177
|
+
const snapshotCache = /* @__PURE__ */ new WeakMap();
|
|
178
|
+
function getSnapshot(selector) {
|
|
179
|
+
const newSnapshot = selector(states);
|
|
180
|
+
const cachedSnapshot = snapshotCache.get(selector);
|
|
181
|
+
if (cachedSnapshot && shallowEqual(newSnapshot, cachedSnapshot)) {
|
|
182
|
+
return cachedSnapshot;
|
|
183
|
+
}
|
|
184
|
+
snapshotCache.set(selector, newSnapshot);
|
|
185
|
+
return Object.freeze(newSnapshot);
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
handlers,
|
|
189
|
+
consume,
|
|
190
|
+
getSnapshot
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/react/createStore.ts
|
|
195
|
+
function createStore(option) {
|
|
196
|
+
const { handlers, consume, getSnapshot } = configStore(option);
|
|
197
|
+
function useStore(selector) {
|
|
198
|
+
return useSyncExternalStore(
|
|
199
|
+
consume,
|
|
200
|
+
() => getSnapshot(selector),
|
|
201
|
+
() => getSnapshot(selector)
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const useHandlers = () => handlers;
|
|
205
|
+
return {
|
|
206
|
+
useStore,
|
|
207
|
+
useHandlers
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/react/createStoreProvider.tsx
|
|
212
|
+
import { createContext, useContext, useRef } from "react";
|
|
213
|
+
import { jsx } from "react/jsx-runtime";
|
|
214
|
+
function createStoreProvider(props) {
|
|
215
|
+
const Context = createContext(null);
|
|
216
|
+
function Provider({ children }) {
|
|
217
|
+
const store = useRef(null);
|
|
218
|
+
if (!store.current) {
|
|
219
|
+
store.current = createStore(props);
|
|
220
|
+
}
|
|
221
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value: store.current, children });
|
|
222
|
+
}
|
|
223
|
+
function useStore(selector) {
|
|
224
|
+
const store = useContext(Context);
|
|
225
|
+
if (!store) throw Error("Store Provider is missing !!");
|
|
226
|
+
return store.useStore(selector);
|
|
227
|
+
}
|
|
228
|
+
function useHandlers() {
|
|
229
|
+
const store = useContext(Context);
|
|
230
|
+
if (!store) throw Error("Store Provider is missing !!");
|
|
231
|
+
return store.useHandlers();
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
Provider,
|
|
235
|
+
useStore,
|
|
236
|
+
useHandlers
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export {
|
|
241
|
+
configStore,
|
|
242
|
+
createStore,
|
|
243
|
+
createStoreProvider
|
|
244
|
+
};
|
|
245
|
+
//# sourceMappingURL=chunk-BEP626V3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/createStore.ts","../src/utils/functions/runAction.ts","../src/core/configStore/cookAutoBuildHandlers/Handlers/array.handlers.ts","../src/core/configStore/cookAutoBuildHandlers/Handlers/bool.handlers.ts","../src/core/configStore/cookAutoBuildHandlers/Handlers/object.handler.ts","../src/core/configStore/cookAutoBuildHandlers/index.ts","../src/utils/functions/mapObject.ts","../src/utils/functions/shallowEqual.ts","../src/core/configStore/index.ts","../src/react/createStoreProvider.tsx"],"sourcesContent":["import { useSyncExternalStore } from \"react\";\r\nimport configStore from \"../core/configStore\";\r\nimport { ConfigStoreProps, GSH, GAH, States, UseHandlers } from \"../core/configStore/types\";\r\n\r\nexport default function createStore<\r\n S extends States, \r\n SH extends GSH<S> = GSH<S>, \r\n AH extends GAH<S> = GAH<S>\r\n>(option: ConfigStoreProps<S, SH, AH>) {\r\n const {handlers, consume, getSnapshot} = configStore<S, SH, AH>(option);\r\n\r\n function useStore<T>(selector: (state: S) => T): T {\r\n return useSyncExternalStore(\r\n consume,\r\n () => getSnapshot(selector),\r\n () => getSnapshot(selector)\r\n )\r\n }\r\n\r\n const useHandlers = (): UseHandlers<S, SH, AH> => handlers;\r\n\r\n return {\r\n useStore,\r\n useHandlers\r\n }\r\n}\r\n\r\nexport type CreateStore<S extends States, SH extends GSH<S> = GSH<S>, AH extends GAH<S> = GAH<S>> = ReturnType<typeof createStore<S, SH, AH>>","export type Action<T> = ((val: T) => T) | T;\r\n\r\nexport default function runAction<T>(action: Action<T>, val: T): T {\r\n if(typeof action === 'function') {\r\n return (action as (val: T) => T)(val);\r\n }\r\n\r\n return action;\r\n}","import runAction, { Action } from \"@/utils/functions/runAction\";\r\n\r\n\r\nexport type ArrayHandlers<S extends Array<any>, V = S extends Array<infer T> ? T : never> = S extends Array<V> ? {\r\n push: (val: V) => V;\r\n pop: () => V;\r\n shift: () => V;\r\n unShift: (val: V) => V;\r\n update: (index: number, val: Action<V>) => V;\r\n remove: (index: number) => V;\r\n} : {}\r\n\r\n\r\nexport default function arrayHandlers<S extends Array<any>, V = S extends Array<infer T> ? T : never>(\r\n getState: () => S, setState: (value: S) => void\r\n): ArrayHandlers<S, V> {\r\n\r\n if(!Array.isArray(getState())) return {} as ArrayHandlers<S, V>;\r\n\r\n return {\r\n push: (val: V) => {\r\n setState([...getState(), val] as S);\r\n return val;\r\n },\r\n\r\n pop: () => {\r\n const state = getState();\r\n setState([...state.slice(0, -1)] as S);\r\n return state[state.length - 1];\r\n },\r\n\r\n shift: () => {\r\n const state = getState();\r\n setState([...state.slice(1)] as S);\r\n return state[0];\r\n },\r\n\r\n unShift: (val: V) => {\r\n const state = getState();\r\n setState([val, ...state] as S);\r\n return val;\r\n },\r\n\r\n update: (index: number, val: Action<V>) => {\r\n const state = getState();\r\n const newState = [...state];\r\n newState[index] = runAction(val, state[index]);\r\n setState(newState as S);\r\n return newState[index];\r\n },\r\n\r\n remove: (index: number) => {\r\n const state = getState();\r\n const removed = state[index];\r\n const newState = state.filter((_, i) => i !== index);\r\n setState([...newState] as S);\r\n return removed;\r\n }\r\n }\r\n}","\r\n\r\nexport type BoolHandlers<S> = S extends boolean ? {\r\n toggle: () => boolean;\r\n} : {};\r\n\r\nexport default function boolHandlers<S extends boolean>(getState: () => S, setState: (value: S) => void): BoolHandlers<S> {\r\n\r\n if(typeof getState() !== 'boolean') return {} as BoolHandlers<S>;\r\n\r\n return {\r\n toggle: () => {\r\n const state = getState();\r\n setState(!state as S);\r\n\r\n return state;\r\n }\r\n }\r\n}\r\n","import { OBJECT_KEYS, OBJECT_VALUE, SUB_OBJECT } from \"@/utils/types/object.type\";\r\nimport runAction, { Action } from \"@/utils/functions/runAction\";\r\n\r\n\r\nexport type ObjectHandlers<S> = S extends object ? {\r\n update: <K extends OBJECT_KEYS<S>>(_path: K, val: Action<OBJECT_VALUE<S, K>>) => S;\r\n updateMany: (val: SUB_OBJECT<S>) => S;\r\n} : {};\r\n\r\nexport default function objectHandlers<S extends object>(getState: () => S, setState: (value: S) => void): ObjectHandlers<S> {\r\n\r\n if(typeof getState() !== 'object') return {} as ObjectHandlers<S>;\r\n\r\n return {\r\n update: <K extends OBJECT_KEYS<S>>(_path: K, val: Action<OBJECT_VALUE<S, K>>): S => {\r\n const state = getState();\r\n\r\n const path = _path.toString().split('.');\r\n\r\n const fn = (obj: any, index = 0): S | OBJECT_VALUE<S, K> => {\r\n if (path.length === index) {\r\n return runAction(val, obj);\r\n }\r\n const key = path[index];\r\n\r\n return {\r\n ...obj,\r\n [key]: fn(obj?.[key] ?? {}, index + 1)\r\n };\r\n }\r\n\r\n const newState = fn(state) as S;\r\n setState(newState);\r\n\r\n return newState\r\n },\r\n\r\n updateMany: (val: SUB_OBJECT<S>): S => {\r\n const state = getState();\r\n \r\n const fn = (target: any, source: any) => {\r\n if (typeof source !== \"object\" || source === null) return source;\r\n if (Array.isArray(source)) return source;\r\n\r\n const result = { ...target };\r\n\r\n for (const key in source) {\r\n if (Object.prototype.hasOwnProperty.call(target, key)) {\r\n result[key] = fn(target[key], source[key]);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n const newState = fn(state, val) as S;\r\n setState(newState);\r\n\r\n return newState;\r\n }\r\n } as ObjectHandlers<S>\r\n}","import runAction, { Action } from \"@/utils/functions/runAction\";\r\nimport arrayHandlers from \"./Handlers/array.handlers\";\r\nimport boolHandlers from \"./Handlers/bool.handlers\";\r\nimport objectHandlers from \"./Handlers/object.handler\";\r\n\r\nfunction cookAutoBuildHandlers<S extends Record<string, any>>(states: S, notify: () => void) {\r\n\r\n const defaultStates: S = JSON.parse(JSON.stringify(states));\r\n \r\n return Object.fromEntries(\r\n Object.entries(states).map(([key, val]: [keyof S, S[keyof S]]) => {\r\n\r\n const getState = () => states[key];\r\n\r\n const setState = (newStates: S[keyof S]) => {\r\n states[key] = newStates;\r\n notify();\r\n }\r\n\r\n const handlers = {\r\n set: (action: Action<typeof val>) => {\r\n setState(runAction(action, getState()));\r\n },\r\n\r\n reset: () => {\r\n setState(defaultStates[key]);\r\n },\r\n \r\n ...(\r\n Array.isArray(val) ? arrayHandlers(getState, setState)\r\n : typeof val === \"object\" ? objectHandlers(getState, setState)\r\n : typeof val === 'boolean' ? boolHandlers(getState, setState)\r\n : {}\r\n )\r\n }\r\n \r\n return [key, handlers]\r\n })\r\n )\r\n}\r\n\r\n\r\ntype CookAutoBuildHandlers<S extends Record<string, any>> = ReturnType<typeof cookAutoBuildHandlers<S>>\r\n\r\nexport {\r\n CookAutoBuildHandlers,\r\n cookAutoBuildHandlers as default\r\n}","\r\nexport default function mapObject<O extends object, R>(obj: O, cb: (val: any) => R) {\r\n return Object.fromEntries(\r\n Object.entries(obj).map(([key, val]) => (\r\n [key, cb(val)]\r\n ))\r\n ) as { [K in keyof O]: R };\r\n}","export default function shallowEqual(a: any, b: any) {\r\n if(a === b) return true;\r\n \r\n if(typeof a !== 'object' || typeof b !== 'object') return false;\r\n\r\n if(Array.isArray(a) !== Array.isArray(b)) return false;\r\n\r\n const key1 = Object.keys(a);\r\n const key2 = Object.keys(b);\r\n\r\n if(key1.length !== key2.length) return false;\r\n\r\n for(let key of key1) {\r\n if (!Object.prototype.hasOwnProperty.call(b, key)) return false;\r\n if (!Object.is(a[key], b[key])) return false;\r\n }\r\n\r\n return true;\r\n}","import cookAutoBuildHandlers from \"./cookAutoBuildHandlers\";\r\nimport mapObject from \"@/utils/functions/mapObject\";\r\nimport shallowEqual from \"@/utils/functions/shallowEqual\";\r\nimport { \r\n ConfigStoreProps, GAH, GSH, States,\r\n UseHandlers, \r\n} from \"./types\";\r\n\r\n\r\n\r\nexport default function configStore<\r\n S extends States, \r\n SH extends GSH<S> = GSH<S>,\r\n AH extends GAH<S> = GAH<S>\r\n>({\r\n states, syncHandlers, asyncHandlers\r\n}: ConfigStoreProps<S, SH, AH>) {\r\n\r\n \r\n const handlers = Object.freeze({\r\n ...mapObject(syncHandlers ?? {}, (handler: any) => (...args: any[]) => { handler(states, ...args); notify(); }),\r\n ...mapObject(asyncHandlers ?? {}, (handler: any) => async (...args: any[]) => { await handler(states, ...args); notify(); }),\r\n ...cookAutoBuildHandlers(states, notify),\r\n }) as UseHandlers<S, SH, AH>;\r\n\r\n\r\n const consumers = new Set<() => void>();\r\n\r\n \r\n function consume(consumer: () => void) {\r\n consumers.add(consumer);\r\n return () => consumers.delete(consumer);\r\n }\r\n\r\n\r\n function notify() {\r\n consumers.forEach(con => con());\r\n }\r\n\r\n\r\n const snapshotCache = new WeakMap<(state: S) => any, any>();\r\n\r\n\r\n function getSnapshot<T>(selector: (state: S) => T): T {\r\n const newSnapshot = selector(states);\r\n const cachedSnapshot = snapshotCache.get(selector);\r\n\r\n if(cachedSnapshot && shallowEqual(newSnapshot, cachedSnapshot)) {\r\n return cachedSnapshot as T;\r\n }\r\n \r\n snapshotCache.set(selector, newSnapshot);\r\n return Object.freeze(newSnapshot);\r\n }\r\n\r\n\r\n return {\r\n handlers,\r\n consume,\r\n getSnapshot\r\n }\r\n}","import React, { createContext, ReactNode, useContext, useRef } from \"react\";\r\nimport { ConfigStoreProps, GSH, GAH, UseHandlers } from \"../core/configStore/types\";\r\nimport createStore, { CreateStore } from \"./createStore\";\r\n\r\n\r\n\r\nexport default function createStoreProvider<\r\n S extends Record<string, any>, \r\n SH extends GSH<S> = GSH<S>, \r\n AH extends GAH<S> = GAH<S>\r\n>(props: ConfigStoreProps<S, SH, AH>) { \r\n\r\n const Context = createContext<CreateStore<S, SH, AH> | null>(null);\r\n \r\n function Provider({children}: {children: ReactNode}): React.JSX.Element {\r\n const store = useRef<CreateStore<S, SH, AH> | null>(null);\r\n\r\n if(!store.current) {\r\n store.current = createStore(props);\r\n }\r\n\r\n return (\r\n <Context.Provider value={store.current}>\r\n {children}\r\n </Context.Provider>\r\n )\r\n }\r\n\r\n \r\n function useStore<T>(selector: (states: S) => T): T {\r\n const store = useContext(Context);\r\n if(!store) throw Error('Store Provider is missing !!');\r\n return store.useStore(selector);\r\n }\r\n\r\n\r\n function useHandlers(): UseHandlers<S, SH, AH> {\r\n const store = useContext(Context);\r\n if(!store) throw Error('Store Provider is missing !!');\r\n return store.useHandlers();\r\n }\r\n\r\n\r\n return {\r\n Provider,\r\n useStore,\r\n useHandlers\r\n } \r\n}\r\n\r\n\r\nexport type CreateStoreProvider<S extends Record<string, any>> = ReturnType<typeof createStoreProvider<S>>"],"mappings":";AAAA,SAAS,4BAA4B;;;ACEtB,SAAR,UAA8B,QAAmB,KAAW;AAC/D,MAAG,OAAO,WAAW,YAAY;AAC7B,WAAQ,OAAyB,GAAG;AAAA,EACxC;AAEA,SAAO;AACX;;;ACKe,SAAR,cACH,UAAmB,UACA;AAEnB,MAAG,CAAC,MAAM,QAAQ,SAAS,CAAC,EAAG,QAAO,CAAC;AAEvC,SAAO;AAAA,IACH,MAAM,CAAC,QAAW;AACd,eAAS,CAAC,GAAG,SAAS,GAAG,GAAG,CAAM;AAClC,aAAO;AAAA,IACX;AAAA,IAEA,KAAK,MAAM;AACP,YAAM,QAAQ,SAAS;AACvB,eAAS,CAAC,GAAG,MAAM,MAAM,GAAG,EAAE,CAAC,CAAM;AACrC,aAAO,MAAM,MAAM,SAAS,CAAC;AAAA,IACjC;AAAA,IAEA,OAAO,MAAM;AACT,YAAM,QAAQ,SAAS;AACvB,eAAS,CAAC,GAAG,MAAM,MAAM,CAAC,CAAC,CAAM;AACjC,aAAO,MAAM,CAAC;AAAA,IAClB;AAA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AW,OAAO;AAChC,QAAG,CAAC,MAAO,OAAM,MAAM,8BAA8B;AACrD,WAAO,MAAM,SAAS,QAAQ;AAAA,EAClC;AAGA,WAAS,cAAsC;AAC3C,UAAM,QAAQ,WAAW,OAAO;AAChC,QAAG,CAAC,MAAO,OAAM,MAAM,8BAA8B;AACrD,WAAO,MAAM,YAAY;AAAA,EAC7B;AAGA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;","names":[]}
|
|
@@ -0,0 +1,273 @@
|
|
|
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 src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
configStore: () => configStore,
|
|
24
|
+
createStore: () => createStore,
|
|
25
|
+
createStoreProvider: () => createStoreProvider
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
|
|
29
|
+
// src/react/createStore.ts
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
|
|
32
|
+
// src/utils/functions/runAction.ts
|
|
33
|
+
function runAction(action, val) {
|
|
34
|
+
if (typeof action === "function") {
|
|
35
|
+
return action(val);
|
|
36
|
+
}
|
|
37
|
+
return action;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/core/configStore/cookAutoBuildHandlers/Handlers/array.handlers.ts
|
|
41
|
+
function arrayHandlers(getState, setState) {
|
|
42
|
+
if (!Array.isArray(getState())) return {};
|
|
43
|
+
return {
|
|
44
|
+
push: (val) => {
|
|
45
|
+
setState([...getState(), val]);
|
|
46
|
+
return val;
|
|
47
|
+
},
|
|
48
|
+
pop: () => {
|
|
49
|
+
const state = getState();
|
|
50
|
+
setState([...state.slice(0, -1)]);
|
|
51
|
+
return state[state.length - 1];
|
|
52
|
+
},
|
|
53
|
+
shift: () => {
|
|
54
|
+
const state = getState();
|
|
55
|
+
setState([...state.slice(1)]);
|
|
56
|
+
return state[0];
|
|
57
|
+
},
|
|
58
|
+
unShift: (val) => {
|
|
59
|
+
const state = getState();
|
|
60
|
+
setState([val, ...state]);
|
|
61
|
+
return val;
|
|
62
|
+
},
|
|
63
|
+
update: (index, val) => {
|
|
64
|
+
const state = getState();
|
|
65
|
+
const newState = [...state];
|
|
66
|
+
newState[index] = runAction(val, state[index]);
|
|
67
|
+
setState(newState);
|
|
68
|
+
return newState[index];
|
|
69
|
+
},
|
|
70
|
+
remove: (index) => {
|
|
71
|
+
const state = getState();
|
|
72
|
+
const removed = state[index];
|
|
73
|
+
const newState = state.filter((_, i) => i !== index);
|
|
74
|
+
setState([...newState]);
|
|
75
|
+
return removed;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/core/configStore/cookAutoBuildHandlers/Handlers/bool.handlers.ts
|
|
81
|
+
function boolHandlers(getState, setState) {
|
|
82
|
+
if (typeof getState() !== "boolean") return {};
|
|
83
|
+
return {
|
|
84
|
+
toggle: () => {
|
|
85
|
+
const state = getState();
|
|
86
|
+
setState(!state);
|
|
87
|
+
return state;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/core/configStore/cookAutoBuildHandlers/Handlers/object.handler.ts
|
|
93
|
+
function objectHandlers(getState, setState) {
|
|
94
|
+
if (typeof getState() !== "object") return {};
|
|
95
|
+
return {
|
|
96
|
+
update: (_path, val) => {
|
|
97
|
+
const state = getState();
|
|
98
|
+
const path = _path.toString().split(".");
|
|
99
|
+
const fn = (obj, index = 0) => {
|
|
100
|
+
var _a;
|
|
101
|
+
if (path.length === index) {
|
|
102
|
+
return runAction(val, obj);
|
|
103
|
+
}
|
|
104
|
+
const key = path[index];
|
|
105
|
+
return {
|
|
106
|
+
...obj,
|
|
107
|
+
[key]: fn((_a = obj == null ? void 0 : obj[key]) != null ? _a : {}, index + 1)
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const newState = fn(state);
|
|
111
|
+
setState(newState);
|
|
112
|
+
return newState;
|
|
113
|
+
},
|
|
114
|
+
updateMany: (val) => {
|
|
115
|
+
const state = getState();
|
|
116
|
+
const fn = (target, source) => {
|
|
117
|
+
if (typeof source !== "object" || source === null) return source;
|
|
118
|
+
if (Array.isArray(source)) return source;
|
|
119
|
+
const result = { ...target };
|
|
120
|
+
for (const key in source) {
|
|
121
|
+
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
122
|
+
result[key] = fn(target[key], source[key]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
const newState = fn(state, val);
|
|
128
|
+
setState(newState);
|
|
129
|
+
return newState;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/core/configStore/cookAutoBuildHandlers/index.ts
|
|
135
|
+
function cookAutoBuildHandlers(states, notify) {
|
|
136
|
+
const defaultStates = JSON.parse(JSON.stringify(states));
|
|
137
|
+
return Object.fromEntries(
|
|
138
|
+
Object.entries(states).map(([key, val]) => {
|
|
139
|
+
const getState = () => states[key];
|
|
140
|
+
const setState = (newStates) => {
|
|
141
|
+
states[key] = newStates;
|
|
142
|
+
notify();
|
|
143
|
+
};
|
|
144
|
+
const handlers = {
|
|
145
|
+
set: (action) => {
|
|
146
|
+
setState(runAction(action, getState()));
|
|
147
|
+
},
|
|
148
|
+
reset: () => {
|
|
149
|
+
setState(defaultStates[key]);
|
|
150
|
+
},
|
|
151
|
+
...Array.isArray(val) ? arrayHandlers(getState, setState) : typeof val === "object" ? objectHandlers(getState, setState) : typeof val === "boolean" ? boolHandlers(getState, setState) : {}
|
|
152
|
+
};
|
|
153
|
+
return [key, handlers];
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/utils/functions/mapObject.ts
|
|
159
|
+
function mapObject(obj, cb) {
|
|
160
|
+
return Object.fromEntries(
|
|
161
|
+
Object.entries(obj).map(([key, val]) => [key, cb(val)])
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/utils/functions/shallowEqual.ts
|
|
166
|
+
function shallowEqual(a, b) {
|
|
167
|
+
if (a === b) return true;
|
|
168
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
169
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
170
|
+
const key1 = Object.keys(a);
|
|
171
|
+
const key2 = Object.keys(b);
|
|
172
|
+
if (key1.length !== key2.length) return false;
|
|
173
|
+
for (let key of key1) {
|
|
174
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
175
|
+
if (!Object.is(a[key], b[key])) return false;
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/core/configStore/index.ts
|
|
181
|
+
function configStore({
|
|
182
|
+
states,
|
|
183
|
+
syncHandlers,
|
|
184
|
+
asyncHandlers
|
|
185
|
+
}) {
|
|
186
|
+
const handlers = Object.freeze({
|
|
187
|
+
...mapObject(syncHandlers != null ? syncHandlers : {}, (handler) => (...args) => {
|
|
188
|
+
handler(states, ...args);
|
|
189
|
+
notify();
|
|
190
|
+
}),
|
|
191
|
+
...mapObject(asyncHandlers != null ? asyncHandlers : {}, (handler) => async (...args) => {
|
|
192
|
+
await handler(states, ...args);
|
|
193
|
+
notify();
|
|
194
|
+
}),
|
|
195
|
+
...cookAutoBuildHandlers(states, notify)
|
|
196
|
+
});
|
|
197
|
+
const consumers = /* @__PURE__ */ new Set();
|
|
198
|
+
function consume(consumer) {
|
|
199
|
+
consumers.add(consumer);
|
|
200
|
+
return () => consumers.delete(consumer);
|
|
201
|
+
}
|
|
202
|
+
function notify() {
|
|
203
|
+
consumers.forEach((con) => con());
|
|
204
|
+
}
|
|
205
|
+
const snapshotCache = /* @__PURE__ */ new WeakMap();
|
|
206
|
+
function getSnapshot(selector) {
|
|
207
|
+
const newSnapshot = selector(states);
|
|
208
|
+
const cachedSnapshot = snapshotCache.get(selector);
|
|
209
|
+
if (cachedSnapshot && shallowEqual(newSnapshot, cachedSnapshot)) {
|
|
210
|
+
return cachedSnapshot;
|
|
211
|
+
}
|
|
212
|
+
snapshotCache.set(selector, newSnapshot);
|
|
213
|
+
return Object.freeze(newSnapshot);
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
handlers,
|
|
217
|
+
consume,
|
|
218
|
+
getSnapshot
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/react/createStore.ts
|
|
223
|
+
function createStore(option) {
|
|
224
|
+
const { handlers, consume, getSnapshot } = configStore(option);
|
|
225
|
+
function useStore(selector) {
|
|
226
|
+
return (0, import_react.useSyncExternalStore)(
|
|
227
|
+
consume,
|
|
228
|
+
() => getSnapshot(selector),
|
|
229
|
+
() => getSnapshot(selector)
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
const useHandlers = () => handlers;
|
|
233
|
+
return {
|
|
234
|
+
useStore,
|
|
235
|
+
useHandlers
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/react/createStoreProvider.tsx
|
|
240
|
+
var import_react2 = require("react");
|
|
241
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
242
|
+
function createStoreProvider(props) {
|
|
243
|
+
const Context = (0, import_react2.createContext)(null);
|
|
244
|
+
function Provider({ children }) {
|
|
245
|
+
const store = (0, import_react2.useRef)(null);
|
|
246
|
+
if (!store.current) {
|
|
247
|
+
store.current = createStore(props);
|
|
248
|
+
}
|
|
249
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, { value: store.current, children });
|
|
250
|
+
}
|
|
251
|
+
function useStore(selector) {
|
|
252
|
+
const store = (0, import_react2.useContext)(Context);
|
|
253
|
+
if (!store) throw Error("Store Provider is missing !!");
|
|
254
|
+
return store.useStore(selector);
|
|
255
|
+
}
|
|
256
|
+
function useHandlers() {
|
|
257
|
+
const store = (0, import_react2.useContext)(Context);
|
|
258
|
+
if (!store) throw Error("Store Provider is missing !!");
|
|
259
|
+
return store.useHandlers();
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
Provider,
|
|
263
|
+
useStore,
|
|
264
|
+
useHandlers
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
268
|
+
0 && (module.exports = {
|
|
269
|
+
configStore,
|
|
270
|
+
createStore,
|
|
271
|
+
createStoreProvider
|
|
272
|
+
});
|
|
273
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/react/createStore.ts","../../src/utils/functions/runAction.ts","../../src/core/configStore/cookAutoBuildHandlers/Handlers/array.handlers.ts","../../src/core/configStore/cookAutoBuildHandlers/Handlers/bool.handlers.ts","../../src/core/configStore/cookAutoBuildHandlers/Handlers/object.handler.ts","../../src/core/configStore/cookAutoBuildHandlers/index.ts","../../src/utils/functions/mapObject.ts","../../src/utils/functions/shallowEqual.ts","../../src/core/configStore/index.ts","../../src/react/createStoreProvider.tsx"],"sourcesContent":["export * from './react';\r\nexport * from './core';","import { useSyncExternalStore } from \"react\";\r\nimport configStore from \"../core/configStore\";\r\nimport { ConfigStoreProps, GSH, GAH, States, UseHandlers } from \"../core/configStore/types\";\r\n\r\nexport default function createStore<\r\n S extends States, \r\n SH extends GSH<S> = GSH<S>, \r\n AH extends GAH<S> = GAH<S>\r\n>(option: ConfigStoreProps<S, SH, AH>) {\r\n const {handlers, consume, getSnapshot} = configStore<S, SH, AH>(option);\r\n\r\n function useStore<T>(selector: (state: S) => T): T {\r\n return useSyncExternalStore(\r\n consume,\r\n () => getSnapshot(selector),\r\n () => getSnapshot(selector)\r\n )\r\n }\r\n\r\n const useHandlers = (): UseHandlers<S, SH, AH> => handlers;\r\n\r\n return {\r\n useStore,\r\n useHandlers\r\n }\r\n}\r\n\r\nexport type CreateStore<S extends States, SH extends GSH<S> = GSH<S>, AH extends GAH<S> = GAH<S>> = ReturnType<typeof createStore<S, SH, AH>>","export type Action<T> = ((val: T) => T) | T;\r\n\r\nexport default function runAction<T>(action: Action<T>, val: T): T {\r\n if(typeof action === 'function') {\r\n return (action as (val: T) => T)(val);\r\n }\r\n\r\n return action;\r\n}","import runAction, { Action } from \"@/utils/functions/runAction\";\r\n\r\n\r\nexport type ArrayHandlers<S extends Array<any>, V = S extends Array<infer T> ? T : never> = S extends Array<V> ? {\r\n push: (val: V) => V;\r\n pop: () => V;\r\n shift: () => V;\r\n unShift: (val: V) => V;\r\n update: (index: number, val: Action<V>) => V;\r\n remove: (index: number) => V;\r\n} : {}\r\n\r\n\r\nexport default function arrayHandlers<S extends Array<any>, V = S extends Array<infer T> ? T : never>(\r\n getState: () => S, setState: (value: S) => void\r\n): ArrayHandlers<S, V> {\r\n\r\n if(!Array.isArray(getState())) return {} as ArrayHandlers<S, V>;\r\n\r\n return {\r\n push: (val: V) => {\r\n setState([...getState(), val] as S);\r\n return val;\r\n },\r\n\r\n pop: () => {\r\n const state = getState();\r\n setState([...state.slice(0, -1)] as S);\r\n return state[state.length - 1];\r\n },\r\n\r\n shift: () => {\r\n const state = getState();\r\n setState([...state.slice(1)] as S);\r\n return state[0];\r\n },\r\n\r\n unShift: (val: V) => {\r\n const state = getState();\r\n setState([val, ...state] as S);\r\n return val;\r\n },\r\n\r\n update: (index: number, val: Action<V>) => {\r\n const state = getState();\r\n const newState = [...state];\r\n newState[index] = runAction(val, state[index]);\r\n setState(newState as S);\r\n return newState[index];\r\n },\r\n\r\n remove: (index: number) => {\r\n const state = getState();\r\n const removed = state[index];\r\n const newState = state.filter((_, i) => i !== index);\r\n setState([...newState] as S);\r\n return removed;\r\n }\r\n }\r\n}","\r\n\r\nexport type BoolHandlers<S> = S extends boolean ? {\r\n toggle: () => boolean;\r\n} : {};\r\n\r\nexport default function boolHandlers<S extends boolean>(getState: () => S, setState: (value: S) => void): BoolHandlers<S> {\r\n\r\n if(typeof getState() !== 'boolean') return {} as BoolHandlers<S>;\r\n\r\n return {\r\n toggle: () => {\r\n const state = getState();\r\n setState(!state as S);\r\n\r\n return state;\r\n }\r\n }\r\n}\r\n","import { OBJECT_KEYS, OBJECT_VALUE, SUB_OBJECT } from \"@/utils/types/object.type\";\r\nimport runAction, { Action } from \"@/utils/functions/runAction\";\r\n\r\n\r\nexport type ObjectHandlers<S> = S extends object ? {\r\n update: <K extends OBJECT_KEYS<S>>(_path: K, val: Action<OBJECT_VALUE<S, K>>) => S;\r\n updateMany: (val: SUB_OBJECT<S>) => S;\r\n} : {};\r\n\r\nexport default function objectHandlers<S extends object>(getState: () => S, setState: (value: S) => void): ObjectHandlers<S> {\r\n\r\n if(typeof getState() !== 'object') return {} as ObjectHandlers<S>;\r\n\r\n return {\r\n update: <K extends OBJECT_KEYS<S>>(_path: K, val: Action<OBJECT_VALUE<S, K>>): S => {\r\n const state = getState();\r\n\r\n const path = _path.toString().split('.');\r\n\r\n const fn = (obj: any, index = 0): S | OBJECT_VALUE<S, K> => {\r\n if (path.length === index) {\r\n return runAction(val, obj);\r\n }\r\n const key = path[index];\r\n\r\n return {\r\n ...obj,\r\n [key]: fn(obj?.[key] ?? {}, index + 1)\r\n };\r\n }\r\n\r\n const newState = fn(state) as S;\r\n setState(newState);\r\n\r\n return newState\r\n },\r\n\r\n updateMany: (val: SUB_OBJECT<S>): S => {\r\n const state = getState();\r\n \r\n const fn = (target: any, source: any) => {\r\n if (typeof source !== \"object\" || source === null) return source;\r\n if (Array.isArray(source)) return source;\r\n\r\n const result = { ...target };\r\n\r\n for (const key in source) {\r\n if (Object.prototype.hasOwnProperty.call(target, key)) {\r\n result[key] = fn(target[key], source[key]);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n const newState = fn(state, val) as S;\r\n setState(newState);\r\n\r\n return newState;\r\n }\r\n } as ObjectHandlers<S>\r\n}","import runAction, { Action } from \"@/utils/functions/runAction\";\r\nimport arrayHandlers from \"./Handlers/array.handlers\";\r\nimport boolHandlers from \"./Handlers/bool.handlers\";\r\nimport objectHandlers from \"./Handlers/object.handler\";\r\n\r\nfunction cookAutoBuildHandlers<S extends Record<string, any>>(states: S, notify: () => void) {\r\n\r\n const defaultStates: S = JSON.parse(JSON.stringify(states));\r\n \r\n return Object.fromEntries(\r\n Object.entries(states).map(([key, val]: [keyof S, S[keyof S]]) => {\r\n\r\n const getState = () => states[key];\r\n\r\n const setState = (newStates: S[keyof S]) => {\r\n states[key] = newStates;\r\n notify();\r\n }\r\n\r\n const handlers = {\r\n set: (action: Action<typeof val>) => {\r\n setState(runAction(action, getState()));\r\n },\r\n\r\n reset: () => {\r\n setState(defaultStates[key]);\r\n },\r\n \r\n ...(\r\n Array.isArray(val) ? arrayHandlers(getState, setState)\r\n : typeof val === \"object\" ? objectHandlers(getState, setState)\r\n : typeof val === 'boolean' ? boolHandlers(getState, setState)\r\n : {}\r\n )\r\n }\r\n \r\n return [key, handlers]\r\n })\r\n )\r\n}\r\n\r\n\r\ntype CookAutoBuildHandlers<S extends Record<string, any>> = ReturnType<typeof cookAutoBuildHandlers<S>>\r\n\r\nexport {\r\n CookAutoBuildHandlers,\r\n cookAutoBuildHandlers as default\r\n}","\r\nexport default function mapObject<O extends object, R>(obj: O, cb: (val: any) => R) {\r\n return Object.fromEntries(\r\n Object.entries(obj).map(([key, val]) => (\r\n [key, cb(val)]\r\n ))\r\n ) as { [K in keyof O]: R };\r\n}","export default function shallowEqual(a: any, b: any) {\r\n if(a === b) return true;\r\n \r\n if(typeof a !== 'object' || typeof b !== 'object') return false;\r\n\r\n if(Array.isArray(a) !== Array.isArray(b)) return false;\r\n\r\n const key1 = Object.keys(a);\r\n const key2 = Object.keys(b);\r\n\r\n if(key1.length !== key2.length) return false;\r\n\r\n for(let key of key1) {\r\n if (!Object.prototype.hasOwnProperty.call(b, key)) return false;\r\n if (!Object.is(a[key], b[key])) return false;\r\n }\r\n\r\n return true;\r\n}","import cookAutoBuildHandlers from \"./cookAutoBuildHandlers\";\r\nimport mapObject from \"@/utils/functions/mapObject\";\r\nimport shallowEqual from \"@/utils/functions/shallowEqual\";\r\nimport { \r\n ConfigStoreProps, GAH, GSH, States,\r\n UseHandlers, \r\n} from \"./types\";\r\n\r\n\r\n\r\nexport default function configStore<\r\n S extends States, \r\n SH extends GSH<S> = GSH<S>,\r\n AH extends GAH<S> = GAH<S>\r\n>({\r\n states, syncHandlers, asyncHandlers\r\n}: ConfigStoreProps<S, SH, AH>) {\r\n\r\n \r\n const handlers = Object.freeze({\r\n ...mapObject(syncHandlers ?? {}, (handler: any) => (...args: any[]) => { handler(states, ...args); notify(); }),\r\n ...mapObject(asyncHandlers ?? {}, (handler: any) => async (...args: any[]) => { await handler(states, ...args); notify(); }),\r\n ...cookAutoBuildHandlers(states, notify),\r\n }) as UseHandlers<S, SH, AH>;\r\n\r\n\r\n const consumers = new Set<() => void>();\r\n\r\n \r\n function consume(consumer: () => void) {\r\n consumers.add(consumer);\r\n return () => consumers.delete(consumer);\r\n }\r\n\r\n\r\n function notify() {\r\n consumers.forEach(con => con());\r\n }\r\n\r\n\r\n const snapshotCache = new WeakMap<(state: S) => any, any>();\r\n\r\n\r\n function getSnapshot<T>(selector: (state: S) => T): T {\r\n const newSnapshot = selector(states);\r\n const cachedSnapshot = snapshotCache.get(selector);\r\n\r\n if(cachedSnapshot && shallowEqual(newSnapshot, cachedSnapshot)) {\r\n return cachedSnapshot as T;\r\n }\r\n \r\n snapshotCache.set(selector, newSnapshot);\r\n return Object.freeze(newSnapshot);\r\n }\r\n\r\n\r\n return {\r\n handlers,\r\n consume,\r\n getSnapshot\r\n }\r\n}","import React, { createContext, ReactNode, useContext, useRef } from \"react\";\r\nimport { ConfigStoreProps, GSH, GAH, UseHandlers } from \"../core/configStore/types\";\r\nimport createStore, { CreateStore } from \"./createStore\";\r\n\r\n\r\n\r\nexport default function createStoreProvider<\r\n S extends Record<string, any>, \r\n SH extends GSH<S> = GSH<S>, \r\n AH extends GAH<S> = GAH<S>\r\n>(props: ConfigStoreProps<S, SH, AH>) { \r\n\r\n const Context = createContext<CreateStore<S, SH, AH> | null>(null);\r\n \r\n function Provider({children}: {children: ReactNode}): React.JSX.Element {\r\n const store = useRef<CreateStore<S, SH, AH> | null>(null);\r\n\r\n if(!store.current) {\r\n store.current = createStore(props);\r\n }\r\n\r\n return (\r\n <Context.Provider value={store.current}>\r\n {children}\r\n </Context.Provider>\r\n )\r\n }\r\n\r\n \r\n function useStore<T>(selector: (states: S) => T): T {\r\n const store = useContext(Context);\r\n if(!store) throw Error('Store Provider is missing !!');\r\n return store.useStore(selector);\r\n }\r\n\r\n\r\n function useHandlers(): UseHandlers<S, SH, AH> {\r\n const store = useContext(Context);\r\n if(!store) throw Error('Store Provider is missing !!');\r\n return store.useHandlers();\r\n }\r\n\r\n\r\n return {\r\n Provider,\r\n useStore,\r\n useHandlers\r\n } \r\n}\r\n\r\n\r\nexport type CreateStoreProvider<S extends Record<string, any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