@oxog/state 1.2.0 → 1.3.1
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 +273 -151
- package/dist/chunk-IWT3T2PM.cjs +3222 -0
- package/dist/chunk-IWT3T2PM.cjs.map +1 -0
- package/dist/chunk-R6MFYVYQ.js +3156 -0
- package/dist/chunk-R6MFYVYQ.js.map +1 -0
- package/dist/iife/index.global.js +1 -47
- package/dist/index.cjs +313 -3015
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2534
- package/dist/index.d.ts +6 -2534
- package/dist/index.js +53 -2951
- package/dist/index.js.map +1 -1
- package/dist/vanilla.cjs +268 -0
- package/dist/vanilla.cjs.map +1 -0
- package/dist/vanilla.d.cts +2617 -0
- package/dist/vanilla.d.ts +2617 -0
- package/dist/vanilla.js +3 -0
- package/dist/vanilla.js.map +1 -0
- package/package.json +23 -8
package/dist/index.cjs
CHANGED
|
@@ -1,957 +1,57 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkIWT3T2PM_cjs = require('./chunk-IWT3T2PM.cjs');
|
|
3
4
|
var react = require('react');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __esm = (fn, res) => function __init() {
|
|
10
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
-
};
|
|
12
|
-
var __export = (target, all) => {
|
|
13
|
-
for (var name in all)
|
|
14
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
-
};
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
-
for (let key of __getOwnPropNames(from))
|
|
19
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
|
|
26
|
-
// src/utils/deep-clone.ts
|
|
27
|
-
function deepClone(value, seen) {
|
|
28
|
-
if (value === null || typeof value !== "object") {
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
if (value instanceof Date) {
|
|
32
|
-
return new Date(value.getTime());
|
|
33
|
-
}
|
|
34
|
-
if (!seen) {
|
|
35
|
-
seen = /* @__PURE__ */ new WeakMap();
|
|
36
|
-
}
|
|
37
|
-
if (seen.has(value)) {
|
|
38
|
-
return seen.get(value);
|
|
39
|
-
}
|
|
40
|
-
seen.set(value, value);
|
|
41
|
-
if (Array.isArray(value)) {
|
|
42
|
-
const cloned = [];
|
|
43
|
-
seen.set(value, cloned);
|
|
44
|
-
value.forEach((item, index) => {
|
|
45
|
-
cloned[index] = deepClone(item, seen);
|
|
46
|
-
});
|
|
47
|
-
return cloned;
|
|
48
|
-
}
|
|
49
|
-
if (value.constructor === Object) {
|
|
50
|
-
const cloned = {};
|
|
51
|
-
seen.set(value, cloned);
|
|
52
|
-
for (const key in value) {
|
|
53
|
-
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
54
|
-
cloned[key] = deepClone(value[key], seen);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return cloned;
|
|
58
|
-
}
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
var init_deep_clone = __esm({
|
|
62
|
-
"src/utils/deep-clone.ts"() {
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// src/utils/deep-equal.ts
|
|
67
|
-
function deepEqual(a, b) {
|
|
68
|
-
if (Object.is(a, b)) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
if (Array.isArray(a)) {
|
|
78
|
-
const arrB = b;
|
|
79
|
-
if (a.length !== arrB.length) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
for (let i = 0; i < a.length; i++) {
|
|
83
|
-
if (!deepEqual(a[i], arrB[i])) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
const keysA = Object.keys(a);
|
|
90
|
-
const keysB = Object.keys(b);
|
|
91
|
-
if (keysA.length !== keysB.length) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
for (const key of keysA) {
|
|
95
|
-
if (!Object.prototype.hasOwnProperty.call(b, key) || !deepEqual(a[key], b[key])) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
var init_deep_equal = __esm({
|
|
102
|
-
"src/utils/deep-equal.ts"() {
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// src/utils/shallow-equal.ts
|
|
107
|
-
function shallowEqual(a, b) {
|
|
108
|
-
if (Object.is(a, b)) {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
const keysA = Object.keys(a);
|
|
115
|
-
const keysB = Object.keys(b);
|
|
116
|
-
if (keysA.length !== keysB.length) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
for (const key of keysA) {
|
|
120
|
-
if (!keysB.includes(key) || !Object.is(a[key], b[key])) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
var init_shallow_equal = __esm({
|
|
127
|
-
"src/utils/shallow-equal.ts"() {
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// src/utils/deep-merge.ts
|
|
132
|
-
function deepMerge(target, source) {
|
|
133
|
-
if (source === null) {
|
|
134
|
-
return target;
|
|
135
|
-
}
|
|
136
|
-
if (typeof source !== "object") {
|
|
137
|
-
return source;
|
|
138
|
-
}
|
|
139
|
-
const output = deepClone(target);
|
|
140
|
-
for (const key in source) {
|
|
141
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
142
|
-
const sourceValue = source[key];
|
|
143
|
-
const targetValue = output[key];
|
|
144
|
-
if (sourceValue instanceof Date) {
|
|
145
|
-
output[key] = new Date(sourceValue.getTime());
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (sourceValue !== null && typeof sourceValue === "object" && !Array.isArray(sourceValue) && !(sourceValue instanceof Date) && targetValue !== null && typeof targetValue === "object" && !Array.isArray(targetValue) && !(targetValue instanceof Date)) {
|
|
149
|
-
output[key] = deepMerge(targetValue, sourceValue);
|
|
150
|
-
} else {
|
|
151
|
-
output[key] = cloneValue(sourceValue);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return output;
|
|
156
|
-
}
|
|
157
|
-
function cloneValue(value) {
|
|
158
|
-
if (value === null || typeof value !== "object") {
|
|
159
|
-
return value;
|
|
160
|
-
}
|
|
161
|
-
if (value instanceof Date) {
|
|
162
|
-
return new Date(value.getTime());
|
|
163
|
-
}
|
|
164
|
-
if (Array.isArray(value)) {
|
|
165
|
-
return value.map((v) => cloneValue(v));
|
|
166
|
-
}
|
|
167
|
-
if (value.constructor === Object) {
|
|
168
|
-
const cloned = {};
|
|
169
|
-
for (const key in value) {
|
|
170
|
-
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
171
|
-
cloned[key] = cloneValue(value[key]);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return cloned;
|
|
175
|
-
}
|
|
176
|
-
return value;
|
|
177
|
-
}
|
|
178
|
-
var init_deep_merge = __esm({
|
|
179
|
-
"src/utils/deep-merge.ts"() {
|
|
180
|
-
init_deep_clone();
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// src/utils/is-function.ts
|
|
185
|
-
function isFunction(value) {
|
|
186
|
-
return typeof value === "function";
|
|
187
|
-
}
|
|
188
|
-
var init_is_function = __esm({
|
|
189
|
-
"src/utils/is-function.ts"() {
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
// src/utils/pick.ts
|
|
194
|
-
function pick(obj, keys) {
|
|
195
|
-
const result = {};
|
|
196
|
-
for (const key of keys) {
|
|
197
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
198
|
-
result[key] = obj[key];
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return result;
|
|
202
|
-
}
|
|
203
|
-
var init_pick = __esm({
|
|
204
|
-
"src/utils/pick.ts"() {
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
// src/utils/omit.ts
|
|
209
|
-
function omit(obj, keys) {
|
|
210
|
-
const result = { ...obj };
|
|
211
|
-
for (const key of keys) {
|
|
212
|
-
delete result[key];
|
|
213
|
-
}
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
|
-
var init_omit = __esm({
|
|
217
|
-
"src/utils/omit.ts"() {
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
// src/utils/identity.ts
|
|
222
|
-
function identity(value) {
|
|
223
|
-
return value;
|
|
224
|
-
}
|
|
225
|
-
var init_identity = __esm({
|
|
226
|
-
"src/utils/identity.ts"() {
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
// src/utils/index.ts
|
|
231
|
-
var init_utils = __esm({
|
|
232
|
-
"src/utils/index.ts"() {
|
|
233
|
-
init_deep_clone();
|
|
234
|
-
init_deep_equal();
|
|
235
|
-
init_shallow_equal();
|
|
236
|
-
init_deep_merge();
|
|
237
|
-
init_is_function();
|
|
238
|
-
init_pick();
|
|
239
|
-
init_omit();
|
|
240
|
-
init_identity();
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// src/kernel.ts
|
|
245
|
-
function createKernel(config) {
|
|
246
|
-
return new Kernel(config);
|
|
247
|
-
}
|
|
248
|
-
var EventBus, Kernel;
|
|
249
|
-
var init_kernel = __esm({
|
|
250
|
-
"src/kernel.ts"() {
|
|
251
|
-
EventBus = class {
|
|
252
|
-
listeners = /* @__PURE__ */ new Map();
|
|
253
|
-
/**
|
|
254
|
-
* Subscribe to an event.
|
|
255
|
-
*
|
|
256
|
-
* @param event - Event name
|
|
257
|
-
* @param handler - Event handler
|
|
258
|
-
* @returns Unsubscribe function
|
|
259
|
-
*/
|
|
260
|
-
on(event, handler) {
|
|
261
|
-
if (!this.listeners.has(event)) {
|
|
262
|
-
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
263
|
-
}
|
|
264
|
-
this.listeners.get(event).add(handler);
|
|
265
|
-
return () => {
|
|
266
|
-
this.listeners.get(event)?.delete(handler);
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Emit an event to all subscribers.
|
|
271
|
-
*
|
|
272
|
-
* @param event - Event name
|
|
273
|
-
* @param data - Event data
|
|
274
|
-
*/
|
|
275
|
-
emit(event, data) {
|
|
276
|
-
const handlers = this.listeners.get(event);
|
|
277
|
-
if (handlers) {
|
|
278
|
-
for (const handler of handlers) {
|
|
279
|
-
try {
|
|
280
|
-
handler(data);
|
|
281
|
-
} catch (error) {
|
|
282
|
-
console.error(`Error in ${event} handler:`, error);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/** Clear all listeners. */
|
|
288
|
-
destroy() {
|
|
289
|
-
this.listeners.clear();
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
Kernel = class {
|
|
293
|
-
plugins = /* @__PURE__ */ new Map();
|
|
294
|
-
eventBus = new EventBus();
|
|
295
|
-
config;
|
|
296
|
-
errorHandlers = /* @__PURE__ */ new Set();
|
|
297
|
-
initializing = false;
|
|
298
|
-
constructor(config) {
|
|
299
|
-
this.config = config || {};
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Register a plugin.
|
|
303
|
-
*
|
|
304
|
-
* @param plugin - The plugin to register
|
|
305
|
-
* @param options - Plugin options
|
|
306
|
-
* @param store - The store instance
|
|
307
|
-
* @throws {Error} If plugin already registered or dependencies missing
|
|
308
|
-
*/
|
|
309
|
-
register(plugin, options, store) {
|
|
310
|
-
if (!plugin.name || !plugin.version || typeof plugin.install !== "function") {
|
|
311
|
-
throw new Error("Invalid plugin: must have name, version, and install function");
|
|
312
|
-
}
|
|
313
|
-
if (this.plugins.has(plugin.name)) {
|
|
314
|
-
throw new Error(`Plugin '${plugin.name}' is already registered`);
|
|
315
|
-
}
|
|
316
|
-
if (plugin.dependencies) {
|
|
317
|
-
for (const dep of plugin.dependencies) {
|
|
318
|
-
if (!this.plugins.has(dep)) {
|
|
319
|
-
throw new Error(
|
|
320
|
-
`Plugin '${plugin.name}' requires '${dep}' to be registered first`
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
const instance = {
|
|
326
|
-
plugin,
|
|
327
|
-
options
|
|
328
|
-
};
|
|
329
|
-
try {
|
|
330
|
-
plugin.install(store, options);
|
|
331
|
-
} catch (error) {
|
|
332
|
-
throw new Error(`Failed to install plugin '${plugin.name}': ${error}`);
|
|
333
|
-
}
|
|
334
|
-
this.plugins.set(plugin.name, instance);
|
|
335
|
-
if (!this.initializing && plugin.onInit) {
|
|
336
|
-
this.runOnInit(plugin, store);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Initialize all plugins.
|
|
341
|
-
*
|
|
342
|
-
* @param store - The store instance
|
|
343
|
-
*/
|
|
344
|
-
async initializeAll(store) {
|
|
345
|
-
this.initializing = true;
|
|
346
|
-
const plugins = Array.from(this.plugins.values());
|
|
347
|
-
for (const { plugin } of plugins) {
|
|
348
|
-
if (plugin.onInit) {
|
|
349
|
-
await this.runOnInit(plugin, store);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
this.initializing = false;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Run plugin's onInit safely.
|
|
356
|
-
*/
|
|
357
|
-
async runOnInit(plugin, store) {
|
|
358
|
-
try {
|
|
359
|
-
await plugin.onInit(store);
|
|
360
|
-
} catch (error) {
|
|
361
|
-
console.error(`Error in ${plugin.name} onInit:`, error);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Unregister a plugin.
|
|
366
|
-
*
|
|
367
|
-
* @param name - Plugin name
|
|
368
|
-
*/
|
|
369
|
-
async unregister(name) {
|
|
370
|
-
const instance = this.plugins.get(name);
|
|
371
|
-
if (!instance) {
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
if (instance.plugin.onDestroy) {
|
|
375
|
-
try {
|
|
376
|
-
await instance.plugin.onDestroy();
|
|
377
|
-
} catch (error) {
|
|
378
|
-
console.error(`Error in ${name} onDestroy:`, error);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
this.plugins.delete(name);
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Emit a state change event.
|
|
385
|
-
*
|
|
386
|
-
* @param state - New state
|
|
387
|
-
* @param prevState - Previous state
|
|
388
|
-
*/
|
|
389
|
-
emitStateChange(state, prevState) {
|
|
390
|
-
this.eventBus.emit("stateChange", { state, prevState });
|
|
391
|
-
for (const { plugin } of this.plugins.values()) {
|
|
392
|
-
if (plugin.onStateChange) {
|
|
393
|
-
try {
|
|
394
|
-
plugin.onStateChange(state, prevState);
|
|
395
|
-
} catch (error) {
|
|
396
|
-
console.error(`Error in ${plugin.name} onStateChange:`, error);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Emit an error event.
|
|
403
|
-
*
|
|
404
|
-
* @param error - The error
|
|
405
|
-
*/
|
|
406
|
-
emitError(error) {
|
|
407
|
-
this.eventBus.emit("error", error);
|
|
408
|
-
for (const { plugin } of this.plugins.values()) {
|
|
409
|
-
if (plugin.onError) {
|
|
410
|
-
try {
|
|
411
|
-
plugin.onError(error);
|
|
412
|
-
} catch (err) {
|
|
413
|
-
console.error(`Error in ${plugin.name} onError:`, err);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
for (const handler of this.errorHandlers) {
|
|
418
|
-
try {
|
|
419
|
-
handler(error);
|
|
420
|
-
} catch (err) {
|
|
421
|
-
console.error("Error in error handler:", err);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Add an error handler.
|
|
427
|
-
*
|
|
428
|
-
* @param handler - Error handler function
|
|
429
|
-
* @returns Unsubscribe function
|
|
430
|
-
*/
|
|
431
|
-
onError(handler) {
|
|
432
|
-
this.errorHandlers.add(handler);
|
|
433
|
-
return () => {
|
|
434
|
-
this.errorHandlers.delete(handler);
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Subscribe to an event.
|
|
439
|
-
*
|
|
440
|
-
* @param event - Event name
|
|
441
|
-
* @param handler - Event handler
|
|
442
|
-
* @returns Unsubscribe function
|
|
443
|
-
*/
|
|
444
|
-
on(event, handler) {
|
|
445
|
-
return this.eventBus.on(event, handler);
|
|
446
|
-
}
|
|
447
|
-
/** Destroy the kernel and cleanup. */
|
|
448
|
-
async destroy() {
|
|
449
|
-
const pluginNames = Array.from(this.plugins.keys());
|
|
450
|
-
for (const name of pluginNames) {
|
|
451
|
-
await this.unregister(name);
|
|
452
|
-
}
|
|
453
|
-
this.eventBus.destroy();
|
|
454
|
-
this.errorHandlers.clear();
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
// src/batch-context.ts
|
|
461
|
-
function isBatching() {
|
|
462
|
-
return batchDepth > 0;
|
|
463
|
-
}
|
|
464
|
-
function getBatchDepth() {
|
|
465
|
-
return batchDepth;
|
|
466
|
-
}
|
|
467
|
-
function incrementBatchDepth() {
|
|
468
|
-
return ++batchDepth;
|
|
469
|
-
}
|
|
470
|
-
function decrementBatchDepth() {
|
|
471
|
-
return --batchDepth;
|
|
472
|
-
}
|
|
473
|
-
function getBatchManagedStores() {
|
|
474
|
-
return batchManagedStores;
|
|
475
|
-
}
|
|
476
|
-
function clearBatchStores() {
|
|
477
|
-
batchStores.clear();
|
|
478
|
-
batchManagedStores.clear();
|
|
479
|
-
}
|
|
480
|
-
function addBatchStore(store) {
|
|
481
|
-
batchStores.add(store);
|
|
482
|
-
}
|
|
483
|
-
function addManagedStore(store) {
|
|
484
|
-
batchManagedStores.add(store);
|
|
485
|
-
}
|
|
486
|
-
function isStoreManaged(store) {
|
|
487
|
-
return batchManagedStores.has(store);
|
|
488
|
-
}
|
|
489
|
-
var batchDepth, batchStores, batchManagedStores, sharedBatchContext;
|
|
490
|
-
var init_batch_context = __esm({
|
|
491
|
-
"src/batch-context.ts"() {
|
|
492
|
-
batchDepth = 0;
|
|
493
|
-
batchStores = /* @__PURE__ */ new Set();
|
|
494
|
-
batchManagedStores = /* @__PURE__ */ new Set();
|
|
495
|
-
sharedBatchContext = {
|
|
496
|
-
get depth() {
|
|
497
|
-
return batchDepth;
|
|
498
|
-
},
|
|
499
|
-
get stores() {
|
|
500
|
-
return batchStores;
|
|
501
|
-
},
|
|
502
|
-
get managedStores() {
|
|
503
|
-
return batchManagedStores;
|
|
504
|
-
},
|
|
505
|
-
isBatching,
|
|
506
|
-
batch(store, fn) {
|
|
507
|
-
const wasAlreadyBatching = isStoreManaged(store);
|
|
508
|
-
incrementBatchDepth();
|
|
509
|
-
addBatchStore(store);
|
|
510
|
-
if (!wasAlreadyBatching && "beginBatch" in store) {
|
|
511
|
-
store.beginBatch();
|
|
512
|
-
addManagedStore(store);
|
|
513
|
-
}
|
|
514
|
-
try {
|
|
515
|
-
const result = fn();
|
|
516
|
-
decrementBatchDepth();
|
|
517
|
-
if (getBatchDepth() === 0) {
|
|
518
|
-
for (const s of getBatchManagedStores()) {
|
|
519
|
-
if ("flushNotifications" in s) {
|
|
520
|
-
s.flushNotifications();
|
|
521
|
-
}
|
|
522
|
-
if ("endBatch" in s) {
|
|
523
|
-
s.endBatch();
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
clearBatchStores();
|
|
527
|
-
}
|
|
528
|
-
return result;
|
|
529
|
-
} catch (error) {
|
|
530
|
-
decrementBatchDepth();
|
|
531
|
-
if (getBatchDepth() === 0) {
|
|
532
|
-
for (const s of getBatchManagedStores()) {
|
|
533
|
-
if ("endBatch" in s) {
|
|
534
|
-
s.endBatch();
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
clearBatchStores();
|
|
538
|
-
}
|
|
539
|
-
throw error;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
// src/types.ts
|
|
547
|
-
exports.StoreErrorCode = void 0; exports.StoreError = void 0;
|
|
548
|
-
var init_types = __esm({
|
|
549
|
-
"src/types.ts"() {
|
|
550
|
-
exports.StoreErrorCode = /* @__PURE__ */ ((StoreErrorCode2) => {
|
|
551
|
-
StoreErrorCode2["STORE_DESTROYED"] = "STORE_DESTROYED";
|
|
552
|
-
StoreErrorCode2["PLUGIN_EXISTS"] = "PLUGIN_EXISTS";
|
|
553
|
-
StoreErrorCode2["PLUGIN_DEPENDENCY_MISSING"] = "PLUGIN_DEPENDENCY_MISSING";
|
|
554
|
-
StoreErrorCode2["INVALID_STATE_UPDATE"] = "INVALID_STATE_UPDATE";
|
|
555
|
-
StoreErrorCode2["ACTION_ERROR"] = "ACTION_ERROR";
|
|
556
|
-
return StoreErrorCode2;
|
|
557
|
-
})(exports.StoreErrorCode || {});
|
|
558
|
-
exports.StoreError = class extends Error {
|
|
559
|
-
constructor(code, message) {
|
|
560
|
-
super(message);
|
|
561
|
-
this.code = code;
|
|
562
|
-
this.name = "StoreError";
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
// src/store.ts
|
|
569
|
-
var store_exports = {};
|
|
570
|
-
__export(store_exports, {
|
|
571
|
-
StoreError: () => exports.StoreError,
|
|
572
|
-
StoreErrorCode: () => exports.StoreErrorCode,
|
|
573
|
-
StoreImpl: () => StoreImpl,
|
|
574
|
-
batch: () => batch,
|
|
575
|
-
createStore: () => createStore
|
|
576
|
-
});
|
|
577
|
-
function createStore(initialState, actions) {
|
|
578
|
-
const kernel = createKernel({ name: "store" });
|
|
579
|
-
const state = { ...initialState };
|
|
580
|
-
const extractedActions = {};
|
|
581
|
-
for (const key in state) {
|
|
582
|
-
if (isFunction(state[key]) && key.startsWith("$")) {
|
|
583
|
-
extractedActions[key.substring(1)] = state[key];
|
|
584
|
-
delete state[key];
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
const allActions = { ...extractedActions, ...actions };
|
|
588
|
-
const builder = new StoreBuilderImpl(state, kernel);
|
|
589
|
-
if (allActions) {
|
|
590
|
-
for (const [name, fn] of Object.entries(allActions)) {
|
|
591
|
-
builder.addAction(name, fn);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
const actionList = builder.getActions();
|
|
595
|
-
for (const [name, fn] of Object.entries(actionList)) {
|
|
596
|
-
builder[name] = (...args) => {
|
|
597
|
-
const currentState = builder.getState();
|
|
598
|
-
const result = fn(currentState, ...args);
|
|
599
|
-
if (result instanceof Promise) {
|
|
600
|
-
return result.then((partial) => {
|
|
601
|
-
builder.setState(partial);
|
|
602
|
-
return partial;
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
builder.setState(result);
|
|
606
|
-
return result;
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
kernel.initializeAll(builder).catch((error) => {
|
|
610
|
-
console.error("Error initializing plugins:", error);
|
|
611
|
-
});
|
|
612
|
-
return new Proxy(builder, {
|
|
613
|
-
get(target, prop) {
|
|
614
|
-
if (prop in target) {
|
|
615
|
-
return target[prop];
|
|
616
|
-
}
|
|
617
|
-
const store = target.store;
|
|
618
|
-
if (store && typeof store[prop] === "function") {
|
|
619
|
-
return store[prop].bind(store);
|
|
620
|
-
}
|
|
621
|
-
if (store && prop in store) {
|
|
622
|
-
return store[prop];
|
|
623
|
-
}
|
|
624
|
-
return void 0;
|
|
625
|
-
},
|
|
626
|
-
set(target, prop, value) {
|
|
627
|
-
if (prop in target || typeof value === "function") {
|
|
628
|
-
target[prop] = value;
|
|
629
|
-
return true;
|
|
630
|
-
}
|
|
631
|
-
const store = target.store;
|
|
632
|
-
if (store) {
|
|
633
|
-
store[prop] = value;
|
|
634
|
-
return true;
|
|
635
|
-
}
|
|
636
|
-
return false;
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
function batch(fn) {
|
|
641
|
-
return fn();
|
|
642
|
-
}
|
|
643
|
-
var StoreImpl, StoreBuilderImpl;
|
|
644
|
-
var init_store = __esm({
|
|
645
|
-
"src/store.ts"() {
|
|
646
|
-
init_utils();
|
|
647
|
-
init_kernel();
|
|
648
|
-
init_batch_context();
|
|
649
|
-
init_types();
|
|
650
|
-
StoreImpl = class {
|
|
651
|
-
state;
|
|
652
|
-
initialState;
|
|
653
|
-
listeners = /* @__PURE__ */ new Set();
|
|
654
|
-
selectorSubscriptions = /* @__PURE__ */ new Map();
|
|
655
|
-
kernel;
|
|
656
|
-
destroyed = false;
|
|
657
|
-
batchDepth = 0;
|
|
658
|
-
pendingNotify = false;
|
|
659
|
-
queuedState = null;
|
|
660
|
-
queuedPrevState = null;
|
|
661
|
-
actions = {};
|
|
662
|
-
constructor(initialState, kernel) {
|
|
663
|
-
this.state = deepClone(initialState);
|
|
664
|
-
this.initialState = deepClone(initialState);
|
|
665
|
-
this.kernel = kernel;
|
|
666
|
-
this.kernel.onError((error) => {
|
|
667
|
-
console.error("Store error:", error);
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
/** Get current state snapshot. */
|
|
671
|
-
getState() {
|
|
672
|
-
this.checkNotDestroyed();
|
|
673
|
-
return this.state;
|
|
674
|
-
}
|
|
675
|
-
/** Update state with partial object or function. */
|
|
676
|
-
setState(partial) {
|
|
677
|
-
this.checkNotDestroyed();
|
|
678
|
-
const prevState = this.state;
|
|
679
|
-
const update = typeof partial === "function" ? partial(this.state) : partial;
|
|
680
|
-
this.state = { ...this.state, ...update };
|
|
681
|
-
this.notifyOrQueue(this.state, prevState);
|
|
682
|
-
}
|
|
683
|
-
/** Deep merge state. */
|
|
684
|
-
merge(partial) {
|
|
685
|
-
this.checkNotDestroyed();
|
|
686
|
-
const prevState = this.state;
|
|
687
|
-
this.state = deepMerge(this.state, partial);
|
|
688
|
-
this.notifyOrQueue(this.state, prevState);
|
|
689
|
-
}
|
|
690
|
-
/** Reset to initial state. */
|
|
691
|
-
reset() {
|
|
692
|
-
this.checkNotDestroyed();
|
|
693
|
-
const prevState = this.state;
|
|
694
|
-
this.state = deepClone(this.initialState);
|
|
695
|
-
this.notifyOrQueue(this.state, prevState);
|
|
696
|
-
}
|
|
697
|
-
subscribe(arg1, arg2, arg3) {
|
|
698
|
-
this.checkNotDestroyed();
|
|
699
|
-
if (arg2 === void 0 && typeof arg1 === "function") {
|
|
700
|
-
const listener2 = arg1;
|
|
701
|
-
this.listeners.add(listener2);
|
|
702
|
-
return () => {
|
|
703
|
-
this.listeners.delete(listener2);
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
const selector2 = arg1;
|
|
707
|
-
const listener = arg2;
|
|
708
|
-
const equalityFn = arg3 || shallowEqual;
|
|
709
|
-
let subscription = this.selectorSubscriptions.get(selector2);
|
|
710
|
-
if (!subscription) {
|
|
711
|
-
const initialValue = selector2(this.state);
|
|
712
|
-
subscription = {
|
|
713
|
-
value: initialValue,
|
|
714
|
-
listeners: /* @__PURE__ */ new Set(),
|
|
715
|
-
selector: selector2,
|
|
716
|
-
equalityFn
|
|
717
|
-
};
|
|
718
|
-
this.selectorSubscriptions.set(selector2, subscription);
|
|
719
|
-
}
|
|
720
|
-
subscription.listeners.add(listener);
|
|
721
|
-
return () => {
|
|
722
|
-
const sub = this.selectorSubscriptions.get(selector2);
|
|
723
|
-
if (sub) {
|
|
724
|
-
sub.listeners.delete(listener);
|
|
725
|
-
if (sub.listeners.size === 0) {
|
|
726
|
-
this.selectorSubscriptions.delete(selector2);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
/** Register a plugin. */
|
|
732
|
-
use(plugin, options) {
|
|
733
|
-
this.checkNotDestroyed();
|
|
734
|
-
this.kernel.register(plugin, options, this);
|
|
735
|
-
return this;
|
|
736
|
-
}
|
|
737
|
-
/** Destroy store and cleanup. */
|
|
738
|
-
destroy() {
|
|
739
|
-
if (this.destroyed) {
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
this.destroyed = true;
|
|
743
|
-
this.kernel.destroy();
|
|
744
|
-
this.listeners.clear();
|
|
745
|
-
this.selectorSubscriptions.clear();
|
|
746
|
-
this.actions = {};
|
|
747
|
-
}
|
|
748
|
-
/** Add an action (for fluent builder pattern). */
|
|
749
|
-
addAction(name, fn) {
|
|
750
|
-
this.actions[name] = fn;
|
|
751
|
-
return this;
|
|
752
|
-
}
|
|
753
|
-
/** Get all actions. */
|
|
754
|
-
getActions() {
|
|
755
|
-
return this.actions;
|
|
756
|
-
}
|
|
757
|
-
/** Check if store is destroyed. */
|
|
758
|
-
checkNotDestroyed() {
|
|
759
|
-
if (this.destroyed) {
|
|
760
|
-
throw new Error("Cannot use destroyed store");
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
/** Notify listeners or queue if batching. */
|
|
764
|
-
notifyOrQueue(state, prevState) {
|
|
765
|
-
const inGlobalBatch = sharedBatchContext.isBatching();
|
|
766
|
-
if (inGlobalBatch) {
|
|
767
|
-
const managedStores = sharedBatchContext.managedStores;
|
|
768
|
-
if (!managedStores.has(this)) {
|
|
769
|
-
managedStores.add(this);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
if (this.batchDepth > 0 || inGlobalBatch) {
|
|
773
|
-
this.queuedState = state;
|
|
774
|
-
if (!this.pendingNotify) {
|
|
775
|
-
this.queuedPrevState = prevState;
|
|
776
|
-
}
|
|
777
|
-
this.pendingNotify = true;
|
|
778
|
-
} else {
|
|
779
|
-
this.notify(state, prevState);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
/** Notify all listeners. */
|
|
783
|
-
notify(state, prevState) {
|
|
784
|
-
this.kernel.emitStateChange(state, prevState);
|
|
785
|
-
for (const listener of this.listeners) {
|
|
786
|
-
try {
|
|
787
|
-
listener(state, prevState);
|
|
788
|
-
} catch (error) {
|
|
789
|
-
this.kernel.emitError(error);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
for (const subscription of this.selectorSubscriptions.values()) {
|
|
793
|
-
const newValue = subscription.selector(state);
|
|
794
|
-
if (!subscription.equalityFn(newValue, subscription.value)) {
|
|
795
|
-
const prevValue = subscription.value;
|
|
796
|
-
subscription.value = newValue;
|
|
797
|
-
for (const listener of subscription.listeners) {
|
|
798
|
-
try {
|
|
799
|
-
listener(newValue, prevValue);
|
|
800
|
-
} catch (error) {
|
|
801
|
-
this.kernel.emitError(error);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
/** Flush pending notifications (end of batch). */
|
|
808
|
-
flushNotifications() {
|
|
809
|
-
if (this.pendingNotify) {
|
|
810
|
-
this.notify(this.queuedState, this.queuedPrevState);
|
|
811
|
-
this.pendingNotify = false;
|
|
812
|
-
this.queuedState = null;
|
|
813
|
-
this.queuedPrevState = null;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
/** Start batching. */
|
|
817
|
-
beginBatch() {
|
|
818
|
-
this.batchDepth++;
|
|
819
|
-
}
|
|
820
|
-
/** End batching. */
|
|
821
|
-
endBatch() {
|
|
822
|
-
this.batchDepth--;
|
|
823
|
-
if (this.batchDepth === 0) {
|
|
824
|
-
this.flushNotifications();
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
};
|
|
828
|
-
StoreBuilderImpl = class {
|
|
829
|
-
store;
|
|
830
|
-
constructor(initialState, kernel) {
|
|
831
|
-
this.store = new StoreImpl(initialState, kernel);
|
|
832
|
-
}
|
|
833
|
-
getState() {
|
|
834
|
-
return this.store.getState();
|
|
835
|
-
}
|
|
836
|
-
setState(partial) {
|
|
837
|
-
this.store.setState(partial);
|
|
838
|
-
}
|
|
839
|
-
merge(partial) {
|
|
840
|
-
this.store.merge(partial);
|
|
841
|
-
}
|
|
842
|
-
reset() {
|
|
843
|
-
this.store.reset();
|
|
844
|
-
}
|
|
845
|
-
subscribe(arg1, arg2, arg3) {
|
|
846
|
-
if (arg2 === void 0) {
|
|
847
|
-
return this.store.subscribe(arg1);
|
|
848
|
-
} else {
|
|
849
|
-
return this.store.subscribe(arg1, arg2, arg3);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
use(plugin, options) {
|
|
853
|
-
this.store.use(plugin, options);
|
|
854
|
-
return this;
|
|
855
|
-
}
|
|
856
|
-
destroy() {
|
|
857
|
-
this.store.destroy();
|
|
858
|
-
}
|
|
859
|
-
action(name, fn) {
|
|
860
|
-
this.store.addAction(name, fn);
|
|
861
|
-
this[name] = (...args) => {
|
|
862
|
-
const currentState = this.getState();
|
|
863
|
-
const result = fn(currentState, ...args);
|
|
864
|
-
if (result instanceof Promise) {
|
|
865
|
-
return result.then((partial) => {
|
|
866
|
-
this.setState(partial);
|
|
867
|
-
return partial;
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
this.setState(result);
|
|
871
|
-
return result;
|
|
872
|
-
};
|
|
873
|
-
return this;
|
|
874
|
-
}
|
|
875
|
-
/** Add action (internal use). */
|
|
876
|
-
addAction(name, fn) {
|
|
877
|
-
this.store.addAction(name, fn);
|
|
878
|
-
return this;
|
|
879
|
-
}
|
|
880
|
-
/** Get actions (internal use). */
|
|
881
|
-
getActions() {
|
|
882
|
-
return this.store.getActions();
|
|
883
|
-
}
|
|
884
|
-
/** Start batching. */
|
|
885
|
-
beginBatch() {
|
|
886
|
-
this.store.beginBatch();
|
|
887
|
-
}
|
|
888
|
-
/** End batching. */
|
|
889
|
-
endBatch() {
|
|
890
|
-
this.store.endBatch();
|
|
891
|
-
}
|
|
892
|
-
/** Flush pending notifications. */
|
|
893
|
-
flushNotifications() {
|
|
894
|
-
this.store.flushNotifications();
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
}
|
|
898
|
-
});
|
|
899
|
-
|
|
900
|
-
// src/index.ts
|
|
901
|
-
init_store();
|
|
902
|
-
|
|
903
|
-
// src/react.ts
|
|
904
|
-
init_identity();
|
|
905
|
-
init_shallow_equal();
|
|
906
|
-
init_store();
|
|
907
|
-
function useStore(store, selector2 = identity, equalityFn = shallowEqual) {
|
|
6
|
+
function useStore(store, selector2 = chunkIWT3T2PM_cjs.identity, equalityFn = chunkIWT3T2PM_cjs.shallowEqual) {
|
|
908
7
|
const selectorRef = react.useRef(selector2);
|
|
909
8
|
const equalityFnRef = react.useRef(equalityFn);
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
callback();
|
|
931
|
-
}
|
|
932
|
-
},
|
|
933
|
-
equalityFnRef.current
|
|
934
|
-
);
|
|
935
|
-
return unsubscribe;
|
|
936
|
-
};
|
|
937
|
-
const selectedState = react.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
9
|
+
selectorRef.current = selector2;
|
|
10
|
+
equalityFnRef.current = equalityFn;
|
|
11
|
+
const cacheRef = react.useRef(null);
|
|
12
|
+
const getSnapshot = react.useCallback(() => {
|
|
13
|
+
const state = store.getState();
|
|
14
|
+
const currentSelector = selectorRef.current;
|
|
15
|
+
const cache = cacheRef.current;
|
|
16
|
+
if (cache && cache.store === store && cache.state === state && cache.selector === currentSelector) {
|
|
17
|
+
return cache.selected;
|
|
18
|
+
}
|
|
19
|
+
const next = currentSelector(state);
|
|
20
|
+
if (cache && cache.store === store && equalityFnRef.current(cache.selected, next)) {
|
|
21
|
+
cacheRef.current = { store, state, selector: currentSelector, selected: cache.selected };
|
|
22
|
+
return cache.selected;
|
|
23
|
+
}
|
|
24
|
+
cacheRef.current = { store, state, selector: currentSelector, selected: next };
|
|
25
|
+
return next;
|
|
26
|
+
}, [store]);
|
|
27
|
+
const subscribe = react.useCallback((callback) => store.subscribe(() => callback()), [store]);
|
|
28
|
+
const selectedState = react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
938
29
|
react.useDebugValue(selectedState);
|
|
939
30
|
return selectedState;
|
|
940
31
|
}
|
|
941
32
|
function useCreateStore(initialState) {
|
|
942
33
|
const storeRef = react.useRef();
|
|
34
|
+
const pendingDestroyRef = react.useRef(null);
|
|
943
35
|
if (storeRef.current === void 0) {
|
|
944
|
-
storeRef.current = createStore(initialState);
|
|
36
|
+
storeRef.current = chunkIWT3T2PM_cjs.createStore(initialState);
|
|
945
37
|
}
|
|
38
|
+
const store = storeRef.current;
|
|
946
39
|
react.useEffect(() => {
|
|
40
|
+
pendingDestroyRef.current = null;
|
|
947
41
|
return () => {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
42
|
+
const token = {};
|
|
43
|
+
pendingDestroyRef.current = token;
|
|
44
|
+
queueMicrotask(() => {
|
|
45
|
+
if (pendingDestroyRef.current === token) {
|
|
46
|
+
store.destroy();
|
|
47
|
+
if (storeRef.current === store) {
|
|
48
|
+
storeRef.current = void 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
952
52
|
};
|
|
953
|
-
}, []);
|
|
954
|
-
return
|
|
53
|
+
}, [store]);
|
|
54
|
+
return store;
|
|
955
55
|
}
|
|
956
56
|
function useAction(store, actionName) {
|
|
957
57
|
const storeRef = react.useRef(store);
|
|
@@ -1011,51 +111,49 @@ function useStoreActions(store, ...actionNames) {
|
|
|
1011
111
|
return result;
|
|
1012
112
|
}
|
|
1013
113
|
function useStoreSelector(store, selectors) {
|
|
1014
|
-
const selectorsRef = react.useRef(selectors);
|
|
1015
|
-
const keysRef = react.useRef(Object.keys(selectors));
|
|
1016
114
|
const prevResultRef = react.useRef(null);
|
|
1017
|
-
if (selectorsRef.current !== selectors) {
|
|
1018
|
-
selectorsRef.current = selectors;
|
|
1019
|
-
keysRef.current = Object.keys(selectors);
|
|
1020
|
-
}
|
|
1021
115
|
const combinedSelector = react.useCallback((state) => {
|
|
1022
|
-
const keys =
|
|
1023
|
-
const currentSelectors = selectorsRef.current;
|
|
116
|
+
const keys = Object.keys(selectors);
|
|
1024
117
|
const result = {};
|
|
1025
118
|
for (const key of keys) {
|
|
1026
|
-
const selector2 =
|
|
119
|
+
const selector2 = selectors[key];
|
|
1027
120
|
if (selector2) {
|
|
1028
121
|
result[key] = selector2(state);
|
|
1029
122
|
}
|
|
1030
123
|
}
|
|
1031
|
-
|
|
124
|
+
const prev = prevResultRef.current;
|
|
125
|
+
if (prev !== null && Object.keys(prev).length === keys.length) {
|
|
1032
126
|
let isEqual = true;
|
|
1033
127
|
for (const key of keys) {
|
|
1034
|
-
if (!shallowEqual(
|
|
128
|
+
if (!(key in prev) || !chunkIWT3T2PM_cjs.shallowEqual(prev[key], result[key])) {
|
|
1035
129
|
isEqual = false;
|
|
1036
130
|
break;
|
|
1037
131
|
}
|
|
1038
132
|
}
|
|
1039
133
|
if (isEqual) {
|
|
1040
|
-
return
|
|
134
|
+
return prev;
|
|
1041
135
|
}
|
|
1042
136
|
}
|
|
1043
137
|
prevResultRef.current = result;
|
|
1044
138
|
return result;
|
|
1045
|
-
}, []);
|
|
139
|
+
}, [selectors]);
|
|
1046
140
|
return useStore(store, combinedSelector);
|
|
1047
141
|
}
|
|
1048
|
-
function useTransientSubscribe(store, selector2, callback, equalityFn = shallowEqual) {
|
|
142
|
+
function useTransientSubscribe(store, selector2, callback, equalityFn = chunkIWT3T2PM_cjs.shallowEqual) {
|
|
1049
143
|
const callbackRef = react.useRef(callback);
|
|
144
|
+
const selectorRef = react.useRef(selector2);
|
|
145
|
+
const equalityFnRef = react.useRef(equalityFn);
|
|
1050
146
|
callbackRef.current = callback;
|
|
147
|
+
selectorRef.current = selector2;
|
|
148
|
+
equalityFnRef.current = equalityFn;
|
|
1051
149
|
react.useEffect(() => {
|
|
1052
150
|
const unsubscribe = store.subscribe(
|
|
1053
|
-
|
|
151
|
+
(state) => selectorRef.current(state),
|
|
1054
152
|
(value, prevValue) => callbackRef.current(value, prevValue),
|
|
1055
|
-
|
|
153
|
+
(a, b) => equalityFnRef.current(a, b)
|
|
1056
154
|
);
|
|
1057
155
|
return unsubscribe;
|
|
1058
|
-
}, [store
|
|
156
|
+
}, [store]);
|
|
1059
157
|
}
|
|
1060
158
|
function useSetState(store) {
|
|
1061
159
|
const storeRef = react.useRef(store);
|
|
@@ -1068,2064 +166,266 @@ function useSetState(store) {
|
|
|
1068
166
|
return setStateRef.current;
|
|
1069
167
|
}
|
|
1070
168
|
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
function
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
function
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
function
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
);
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
function
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
return computedFn;
|
|
1332
|
-
}
|
|
1333
|
-
function combineComputed(computeds, combiner, options = {}) {
|
|
1334
|
-
const { equals = shallowEqual, cacheSize = 1 } = options;
|
|
1335
|
-
let currentValue;
|
|
1336
|
-
let isDestroyed = false;
|
|
1337
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1338
|
-
const unsubscribes = [];
|
|
1339
|
-
const cache = [];
|
|
1340
|
-
const compute = () => {
|
|
1341
|
-
const values = computeds.map((c) => c());
|
|
1342
|
-
return combiner(values);
|
|
1343
|
-
};
|
|
1344
|
-
currentValue = compute();
|
|
1345
|
-
cache.push(currentValue);
|
|
1346
|
-
for (const computed2 of computeds) {
|
|
1347
|
-
const unsub = computed2.subscribe(() => {
|
|
1348
|
-
if (isDestroyed) return;
|
|
1349
|
-
const prevValue = currentValue;
|
|
1350
|
-
const newValue = compute();
|
|
1351
|
-
if (!equals(newValue, prevValue)) {
|
|
1352
|
-
currentValue = newValue;
|
|
1353
|
-
cache.unshift(newValue);
|
|
1354
|
-
while (cache.length > cacheSize) {
|
|
1355
|
-
cache.pop();
|
|
1356
|
-
}
|
|
1357
|
-
for (const listener of listeners) {
|
|
1358
|
-
try {
|
|
1359
|
-
listener(newValue, prevValue);
|
|
1360
|
-
} catch (error) {
|
|
1361
|
-
console.error("Combined computed listener error:", error);
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
});
|
|
1366
|
-
unsubscribes.push(unsub);
|
|
1367
|
-
}
|
|
1368
|
-
const get = () => {
|
|
1369
|
-
if (isDestroyed) {
|
|
1370
|
-
throw new Error("Cannot access destroyed computed value");
|
|
1371
|
-
}
|
|
1372
|
-
return currentValue;
|
|
1373
|
-
};
|
|
1374
|
-
const invalidate = () => {
|
|
1375
|
-
if (isDestroyed) return;
|
|
1376
|
-
for (const computed2 of computeds) {
|
|
1377
|
-
computed2.invalidate();
|
|
1378
|
-
}
|
|
1379
|
-
};
|
|
1380
|
-
const subscribe = (listener) => {
|
|
1381
|
-
if (isDestroyed) {
|
|
1382
|
-
throw new Error("Cannot subscribe to destroyed computed value");
|
|
1383
|
-
}
|
|
1384
|
-
listeners.add(listener);
|
|
1385
|
-
return () => listeners.delete(listener);
|
|
1386
|
-
};
|
|
1387
|
-
const getHistory = () => [...cache];
|
|
1388
|
-
const destroy = () => {
|
|
1389
|
-
if (isDestroyed) return;
|
|
1390
|
-
isDestroyed = true;
|
|
1391
|
-
for (const unsub of unsubscribes) {
|
|
1392
|
-
unsub();
|
|
1393
|
-
}
|
|
1394
|
-
listeners.clear();
|
|
1395
|
-
cache.length = 0;
|
|
1396
|
-
};
|
|
1397
|
-
const combinedFn = get;
|
|
1398
|
-
combinedFn.get = get;
|
|
1399
|
-
combinedFn.invalidate = invalidate;
|
|
1400
|
-
combinedFn.subscribe = subscribe;
|
|
1401
|
-
combinedFn.getHistory = getHistory;
|
|
1402
|
-
combinedFn.destroy = destroy;
|
|
1403
|
-
return combinedFn;
|
|
1404
|
-
}
|
|
1405
|
-
function memoizeSelector(selector2, equals = shallowEqual) {
|
|
1406
|
-
let lastState;
|
|
1407
|
-
let lastResult;
|
|
1408
|
-
let isInitialized = false;
|
|
1409
|
-
return (state) => {
|
|
1410
|
-
if (!isInitialized || lastState !== state) {
|
|
1411
|
-
const newResult = selector2(state);
|
|
1412
|
-
if (!isInitialized || !equals(newResult, lastResult)) {
|
|
1413
|
-
lastResult = newResult;
|
|
1414
|
-
}
|
|
1415
|
-
lastState = state;
|
|
1416
|
-
isInitialized = true;
|
|
1417
|
-
}
|
|
1418
|
-
return lastResult;
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
// src/slices.ts
|
|
1423
|
-
init_store();
|
|
1424
|
-
function createSlice(name, creator) {
|
|
1425
|
-
return { name, creator };
|
|
1426
|
-
}
|
|
1427
|
-
function combineSlices(...slices) {
|
|
1428
|
-
const initialState = {};
|
|
1429
|
-
const actions = {};
|
|
1430
|
-
let tempStore = null;
|
|
1431
|
-
const set = (partial) => {
|
|
1432
|
-
if (tempStore) {
|
|
1433
|
-
if (typeof partial === "function") {
|
|
1434
|
-
tempStore.setState(partial);
|
|
1435
|
-
} else {
|
|
1436
|
-
tempStore.setState(partial);
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
};
|
|
1440
|
-
const get = () => {
|
|
1441
|
-
return tempStore ? tempStore.getState() : initialState;
|
|
1442
|
-
};
|
|
1443
|
-
const placeholderStore = {
|
|
1444
|
-
getState: () => initialState,
|
|
1445
|
-
setState: () => {
|
|
1446
|
-
},
|
|
1447
|
-
subscribe: () => () => {
|
|
1448
|
-
},
|
|
1449
|
-
merge: () => {
|
|
1450
|
-
},
|
|
1451
|
-
reset: () => {
|
|
1452
|
-
},
|
|
1453
|
-
use: () => placeholderStore,
|
|
1454
|
-
destroy: () => {
|
|
1455
|
-
}
|
|
1456
|
-
};
|
|
1457
|
-
for (const slice of slices) {
|
|
1458
|
-
const sliceResult = slice.creator(set, get, placeholderStore);
|
|
1459
|
-
for (const [key, value] of Object.entries(sliceResult)) {
|
|
1460
|
-
if (typeof value === "function") {
|
|
1461
|
-
actions[key] = value;
|
|
1462
|
-
} else {
|
|
1463
|
-
initialState[key] = value;
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
tempStore = createStore(initialState);
|
|
1468
|
-
for (const slice of slices) {
|
|
1469
|
-
const sliceResult = slice.creator(
|
|
1470
|
-
(partial) => {
|
|
1471
|
-
if (typeof partial === "function") {
|
|
1472
|
-
tempStore.setState(partial);
|
|
1473
|
-
} else {
|
|
1474
|
-
tempStore.setState(partial);
|
|
1475
|
-
}
|
|
1476
|
-
},
|
|
1477
|
-
() => tempStore.getState(),
|
|
1478
|
-
tempStore
|
|
1479
|
-
);
|
|
1480
|
-
for (const [key, value] of Object.entries(sliceResult)) {
|
|
1481
|
-
if (typeof value === "function") {
|
|
1482
|
-
actions[key] = value;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
const store = tempStore;
|
|
1487
|
-
for (const [name, action] of Object.entries(actions)) {
|
|
1488
|
-
store[name] = action;
|
|
1489
|
-
}
|
|
1490
|
-
return store;
|
|
1491
|
-
}
|
|
1492
|
-
function createNamespacedSlice(namespace, creator) {
|
|
1493
|
-
return createSlice(namespace, (set, get, store) => {
|
|
1494
|
-
const namespacedSet = (partial) => {
|
|
1495
|
-
const current = get()[namespace] || {};
|
|
1496
|
-
const update = typeof partial === "function" ? partial(current) : partial;
|
|
1497
|
-
set({ [namespace]: { ...current, ...update } });
|
|
1498
|
-
};
|
|
1499
|
-
const namespacedGet = () => {
|
|
1500
|
-
return get()[namespace] || {};
|
|
1501
|
-
};
|
|
1502
|
-
const sliceResult = creator(namespacedSet, namespacedGet);
|
|
1503
|
-
const state = {};
|
|
1504
|
-
const actions = {};
|
|
1505
|
-
for (const [key, value] of Object.entries(sliceResult)) {
|
|
1506
|
-
if (typeof value === "function") {
|
|
1507
|
-
actions[key] = value;
|
|
1508
|
-
} else {
|
|
1509
|
-
state[key] = value;
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
return {
|
|
1513
|
-
[namespace]: state,
|
|
1514
|
-
...actions
|
|
1515
|
-
};
|
|
1516
|
-
});
|
|
1517
|
-
}
|
|
1518
|
-
function extendStore(store, ...slices) {
|
|
1519
|
-
const actions = {};
|
|
1520
|
-
const set = (partial) => {
|
|
1521
|
-
if (typeof partial === "function") {
|
|
1522
|
-
store.setState(partial);
|
|
1523
|
-
} else {
|
|
1524
|
-
store.setState(partial);
|
|
1525
|
-
}
|
|
1526
|
-
};
|
|
1527
|
-
const get = () => store.getState();
|
|
1528
|
-
for (const slice of slices) {
|
|
1529
|
-
const sliceResult = slice.creator(set, get, store);
|
|
1530
|
-
for (const [key, value] of Object.entries(sliceResult)) {
|
|
1531
|
-
if (typeof value === "function") {
|
|
1532
|
-
actions[key] = value;
|
|
1533
|
-
} else {
|
|
1534
|
-
store.setState({ [key]: value });
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
const extendedStore = store;
|
|
1539
|
-
for (const [name, action] of Object.entries(actions)) {
|
|
1540
|
-
extendedStore[name] = action;
|
|
1541
|
-
}
|
|
1542
|
-
return extendedStore;
|
|
1543
|
-
}
|
|
1544
|
-
function resetSlices(store, ...sliceNames) {
|
|
1545
|
-
console.warn("resetSlices: Use store.reset() to reset all state");
|
|
1546
|
-
store.reset();
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
// src/federation.ts
|
|
1550
|
-
function createFederation(stores, options = {}) {
|
|
1551
|
-
const { name = "federation", debug = false } = options;
|
|
1552
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1553
|
-
const unsubscribers = [];
|
|
1554
|
-
let isInTransaction = false;
|
|
1555
|
-
let transactionChanges = [];
|
|
1556
|
-
let previousStates = null;
|
|
1557
|
-
const getState = () => {
|
|
1558
|
-
const state = {};
|
|
1559
|
-
for (const key in stores) {
|
|
1560
|
-
const store = stores[key];
|
|
1561
|
-
if (store) {
|
|
1562
|
-
state[key] = store.getState();
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
return state;
|
|
1566
|
-
};
|
|
1567
|
-
const notify = (changedStore) => {
|
|
1568
|
-
if (isInTransaction) {
|
|
1569
|
-
if (!transactionChanges.includes(changedStore)) {
|
|
1570
|
-
transactionChanges.push(changedStore);
|
|
1571
|
-
}
|
|
1572
|
-
return;
|
|
1573
|
-
}
|
|
1574
|
-
const state = getState();
|
|
1575
|
-
const prevState = previousStates || state;
|
|
1576
|
-
for (const listener of listeners) {
|
|
1577
|
-
try {
|
|
1578
|
-
listener(state, prevState, changedStore);
|
|
1579
|
-
} catch (error) {
|
|
1580
|
-
console.error(`Federation listener error:`, error);
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
previousStates = state;
|
|
1584
|
-
};
|
|
1585
|
-
for (const key in stores) {
|
|
1586
|
-
const store = stores[key];
|
|
1587
|
-
if (store) {
|
|
1588
|
-
const unsubscribe = store.subscribe(() => {
|
|
1589
|
-
notify(key);
|
|
1590
|
-
});
|
|
1591
|
-
unsubscribers.push(unsubscribe);
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
previousStates = getState();
|
|
1595
|
-
const log = (message, ...args) => {
|
|
1596
|
-
if (debug) {
|
|
1597
|
-
console.log(`[${name}] ${message}`, ...args);
|
|
1598
|
-
}
|
|
1599
|
-
};
|
|
1600
|
-
return {
|
|
1601
|
-
stores,
|
|
1602
|
-
getState,
|
|
1603
|
-
subscribe(listener) {
|
|
1604
|
-
listeners.add(listener);
|
|
1605
|
-
return () => {
|
|
1606
|
-
listeners.delete(listener);
|
|
1607
|
-
};
|
|
1608
|
-
},
|
|
1609
|
-
transaction(fn) {
|
|
1610
|
-
if (isInTransaction) {
|
|
1611
|
-
fn(stores);
|
|
1612
|
-
return;
|
|
1613
|
-
}
|
|
1614
|
-
isInTransaction = true;
|
|
1615
|
-
transactionChanges = [];
|
|
1616
|
-
const snapshotStates = getState();
|
|
1617
|
-
log("Transaction started");
|
|
1618
|
-
try {
|
|
1619
|
-
const result = fn(stores);
|
|
1620
|
-
if (result instanceof Promise) {
|
|
1621
|
-
throw new Error(
|
|
1622
|
-
"Async operations in transaction() are not supported. Use transactionAsync() instead."
|
|
1623
|
-
);
|
|
1624
|
-
}
|
|
1625
|
-
isInTransaction = false;
|
|
1626
|
-
if (transactionChanges.length > 0) {
|
|
1627
|
-
log("Transaction committed, changed stores:", transactionChanges);
|
|
1628
|
-
const state = getState();
|
|
1629
|
-
for (const listener of listeners) {
|
|
1630
|
-
try {
|
|
1631
|
-
listener(state, snapshotStates, transactionChanges[0]);
|
|
1632
|
-
} catch (error) {
|
|
1633
|
-
console.error(`Federation listener error:`, error);
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
previousStates = state;
|
|
1637
|
-
}
|
|
1638
|
-
} catch (error) {
|
|
1639
|
-
isInTransaction = false;
|
|
1640
|
-
log("Transaction failed, rolling back");
|
|
1641
|
-
for (const key in stores) {
|
|
1642
|
-
const store = stores[key];
|
|
1643
|
-
if (store) {
|
|
1644
|
-
store.setState(snapshotStates[key]);
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
throw error;
|
|
1648
|
-
}
|
|
1649
|
-
},
|
|
1650
|
-
async transactionAsync(fn) {
|
|
1651
|
-
if (isInTransaction) {
|
|
1652
|
-
await fn(stores);
|
|
1653
|
-
return;
|
|
1654
|
-
}
|
|
1655
|
-
isInTransaction = true;
|
|
1656
|
-
transactionChanges = [];
|
|
1657
|
-
const snapshotStates = getState();
|
|
1658
|
-
log("Async transaction started");
|
|
1659
|
-
try {
|
|
1660
|
-
await fn(stores);
|
|
1661
|
-
isInTransaction = false;
|
|
1662
|
-
if (transactionChanges.length > 0) {
|
|
1663
|
-
log("Async transaction committed, changed stores:", transactionChanges);
|
|
1664
|
-
const state = getState();
|
|
1665
|
-
for (const listener of listeners) {
|
|
1666
|
-
try {
|
|
1667
|
-
listener(state, snapshotStates, transactionChanges[0]);
|
|
1668
|
-
} catch (error) {
|
|
1669
|
-
console.error(`Federation listener error:`, error);
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
previousStates = state;
|
|
1673
|
-
}
|
|
1674
|
-
} catch (error) {
|
|
1675
|
-
isInTransaction = false;
|
|
1676
|
-
log("Async transaction failed, rolling back");
|
|
1677
|
-
for (const key in stores) {
|
|
1678
|
-
const store = stores[key];
|
|
1679
|
-
if (store) {
|
|
1680
|
-
store.setState(snapshotStates[key]);
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
throw error;
|
|
1684
|
-
}
|
|
1685
|
-
},
|
|
1686
|
-
getStore(storeName) {
|
|
1687
|
-
return stores[storeName];
|
|
1688
|
-
},
|
|
1689
|
-
destroy() {
|
|
1690
|
-
log("Destroying federation");
|
|
1691
|
-
for (const unsubscribe of unsubscribers) {
|
|
1692
|
-
unsubscribe();
|
|
1693
|
-
}
|
|
1694
|
-
listeners.clear();
|
|
1695
|
-
}
|
|
1696
|
-
};
|
|
1697
|
-
}
|
|
1698
|
-
function createFederatedSelector(federation, selector2) {
|
|
1699
|
-
return () => selector2(federation.getState());
|
|
1700
|
-
}
|
|
1701
|
-
function createFederatedComputed(federation, selector2, equalityFn = Object.is) {
|
|
1702
|
-
let cachedValue = selector2(federation.getState());
|
|
1703
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1704
|
-
federation.subscribe((state) => {
|
|
1705
|
-
const newValue = selector2(state);
|
|
1706
|
-
if (!equalityFn(newValue, cachedValue)) {
|
|
1707
|
-
const prevValue = cachedValue;
|
|
1708
|
-
cachedValue = newValue;
|
|
1709
|
-
for (const listener of listeners) {
|
|
1710
|
-
listener(newValue, prevValue);
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
});
|
|
1714
|
-
return {
|
|
1715
|
-
get() {
|
|
1716
|
-
return cachedValue;
|
|
1717
|
-
},
|
|
1718
|
-
subscribe(listener) {
|
|
1719
|
-
listeners.add(listener);
|
|
1720
|
-
return () => {
|
|
1721
|
-
listeners.delete(listener);
|
|
1722
|
-
};
|
|
1723
|
-
}
|
|
1724
|
-
};
|
|
1725
|
-
}
|
|
1726
|
-
function waitForFederated(federation, predicate, timeout) {
|
|
1727
|
-
return new Promise((resolve, reject) => {
|
|
1728
|
-
const state = federation.getState();
|
|
1729
|
-
if (predicate(state)) {
|
|
1730
|
-
resolve(state);
|
|
1731
|
-
return;
|
|
1732
|
-
}
|
|
1733
|
-
let timeoutId;
|
|
1734
|
-
let unsubscribe;
|
|
1735
|
-
const cleanup = () => {
|
|
1736
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
1737
|
-
if (unsubscribe) unsubscribe();
|
|
1738
|
-
};
|
|
1739
|
-
if (timeout) {
|
|
1740
|
-
timeoutId = setTimeout(() => {
|
|
1741
|
-
cleanup();
|
|
1742
|
-
reject(new Error(`waitForFederated timed out after ${timeout}ms`));
|
|
1743
|
-
}, timeout);
|
|
1744
|
-
}
|
|
1745
|
-
unsubscribe = federation.subscribe((state2) => {
|
|
1746
|
-
if (predicate(state2)) {
|
|
1747
|
-
cleanup();
|
|
1748
|
-
resolve(state2);
|
|
1749
|
-
}
|
|
1750
|
-
});
|
|
1751
|
-
});
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
// src/plugins/persist.ts
|
|
1755
|
-
init_utils();
|
|
1756
|
-
var defaultStorage = {
|
|
1757
|
-
getItem: (key) => {
|
|
1758
|
-
if (typeof window === "undefined") return null;
|
|
1759
|
-
try {
|
|
1760
|
-
return window.localStorage.getItem(key);
|
|
1761
|
-
} catch {
|
|
1762
|
-
return null;
|
|
1763
|
-
}
|
|
1764
|
-
},
|
|
1765
|
-
setItem: (key, value) => {
|
|
1766
|
-
if (typeof window === "undefined") return;
|
|
1767
|
-
try {
|
|
1768
|
-
window.localStorage.setItem(key, value);
|
|
1769
|
-
} catch {
|
|
1770
|
-
}
|
|
1771
|
-
},
|
|
1772
|
-
/* c8 ignore next 3 */
|
|
1773
|
-
removeItem: () => {
|
|
1774
|
-
}
|
|
1775
|
-
};
|
|
1776
|
-
var sessionStorage = {
|
|
1777
|
-
getItem: (key) => {
|
|
1778
|
-
if (typeof window === "undefined") return null;
|
|
1779
|
-
try {
|
|
1780
|
-
return window.sessionStorage.getItem(key);
|
|
1781
|
-
} catch {
|
|
1782
|
-
return null;
|
|
1783
|
-
}
|
|
1784
|
-
},
|
|
1785
|
-
setItem: (key, value) => {
|
|
1786
|
-
if (typeof window === "undefined") return;
|
|
1787
|
-
try {
|
|
1788
|
-
window.sessionStorage.setItem(key, value);
|
|
1789
|
-
} catch {
|
|
1790
|
-
}
|
|
1791
|
-
},
|
|
1792
|
-
removeItem: (key) => {
|
|
1793
|
-
if (typeof window === "undefined") return;
|
|
1794
|
-
try {
|
|
1795
|
-
window.sessionStorage.removeItem(key);
|
|
1796
|
-
} catch {
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
};
|
|
1800
|
-
function createDebounced2(fn, delay2) {
|
|
1801
|
-
let timeoutId = null;
|
|
1802
|
-
const debounced = ((...args) => {
|
|
1803
|
-
if (timeoutId) {
|
|
1804
|
-
clearTimeout(timeoutId);
|
|
1805
|
-
}
|
|
1806
|
-
timeoutId = setTimeout(() => {
|
|
1807
|
-
fn(...args);
|
|
1808
|
-
timeoutId = null;
|
|
1809
|
-
}, delay2);
|
|
1810
|
-
});
|
|
1811
|
-
debounced.cancel = () => {
|
|
1812
|
-
if (timeoutId) {
|
|
1813
|
-
clearTimeout(timeoutId);
|
|
1814
|
-
timeoutId = null;
|
|
1815
|
-
}
|
|
1816
|
-
};
|
|
1817
|
-
return debounced;
|
|
1818
|
-
}
|
|
1819
|
-
function persist(options) {
|
|
1820
|
-
const {
|
|
1821
|
-
key,
|
|
1822
|
-
storage = defaultStorage,
|
|
1823
|
-
whitelist,
|
|
1824
|
-
blacklist,
|
|
1825
|
-
partialize,
|
|
1826
|
-
merge: customMerge,
|
|
1827
|
-
version = 0,
|
|
1828
|
-
migrate,
|
|
1829
|
-
serialize = JSON.stringify,
|
|
1830
|
-
deserialize = JSON.parse,
|
|
1831
|
-
encrypt,
|
|
1832
|
-
decrypt,
|
|
1833
|
-
writeDebounce,
|
|
1834
|
-
onRehydrateStorage,
|
|
1835
|
-
onHydrationComplete,
|
|
1836
|
-
onPersistError
|
|
1837
|
-
} = options;
|
|
1838
|
-
let cancelDebounce = null;
|
|
1839
|
-
return {
|
|
1840
|
-
name: "persist",
|
|
1841
|
-
version: "1.0.0",
|
|
1842
|
-
install(store) {
|
|
1843
|
-
try {
|
|
1844
|
-
let saved = storage.getItem(key);
|
|
1845
|
-
if (saved && decrypt) {
|
|
1846
|
-
try {
|
|
1847
|
-
saved = decrypt(saved);
|
|
1848
|
-
} catch {
|
|
1849
|
-
saved = null;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
if (saved) {
|
|
1853
|
-
let parsed;
|
|
1854
|
-
let persistedVersion = 0;
|
|
1855
|
-
try {
|
|
1856
|
-
const data = deserialize(saved);
|
|
1857
|
-
if (data && typeof data === "object" && "state" in data && "version" in data) {
|
|
1858
|
-
parsed = data.state;
|
|
1859
|
-
persistedVersion = data.version;
|
|
1860
|
-
} else {
|
|
1861
|
-
parsed = data;
|
|
1862
|
-
}
|
|
1863
|
-
} catch {
|
|
1864
|
-
parsed = deserialize(saved);
|
|
1865
|
-
}
|
|
1866
|
-
if (onRehydrateStorage) {
|
|
1867
|
-
onRehydrateStorage(parsed);
|
|
1868
|
-
}
|
|
1869
|
-
if (migrate && persistedVersion < version) {
|
|
1870
|
-
parsed = migrate(parsed, persistedVersion);
|
|
1871
|
-
}
|
|
1872
|
-
if (customMerge) {
|
|
1873
|
-
const currentState = store.getState();
|
|
1874
|
-
const mergedState = customMerge(parsed, currentState);
|
|
1875
|
-
store.setState(mergedState);
|
|
1876
|
-
} else {
|
|
1877
|
-
store.merge(parsed);
|
|
1878
|
-
}
|
|
1879
|
-
if (onHydrationComplete) {
|
|
1880
|
-
onHydrationComplete(store.getState());
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
} catch (error) {
|
|
1884
|
-
if (onPersistError) {
|
|
1885
|
-
onPersistError(error);
|
|
1886
|
-
} else {
|
|
1887
|
-
console.error(`Failed to hydrate state from '${key}':`, error);
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
const persistState = (state) => {
|
|
1891
|
-
try {
|
|
1892
|
-
let toSave = state;
|
|
1893
|
-
if (partialize) {
|
|
1894
|
-
toSave = partialize(state);
|
|
1895
|
-
} else if (whitelist) {
|
|
1896
|
-
toSave = pick(state, whitelist);
|
|
1897
|
-
} else if (blacklist) {
|
|
1898
|
-
toSave = omit(state, blacklist);
|
|
1899
|
-
}
|
|
1900
|
-
const dataToStore = {
|
|
1901
|
-
state: toSave,
|
|
1902
|
-
version
|
|
1903
|
-
};
|
|
1904
|
-
let serialized = serialize(dataToStore);
|
|
1905
|
-
if (encrypt) {
|
|
1906
|
-
serialized = encrypt(serialized);
|
|
1907
|
-
}
|
|
1908
|
-
storage.setItem(key, serialized);
|
|
1909
|
-
} catch (error) {
|
|
1910
|
-
if (onPersistError) {
|
|
1911
|
-
onPersistError(error);
|
|
1912
|
-
} else {
|
|
1913
|
-
console.error(`Failed to persist state to '${key}':`, error);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
};
|
|
1917
|
-
const debouncedPersist = writeDebounce && writeDebounce > 0 ? createDebounced2(persistState, writeDebounce) : persistState;
|
|
1918
|
-
if (writeDebounce && writeDebounce > 0) {
|
|
1919
|
-
cancelDebounce = () => debouncedPersist.cancel?.();
|
|
1920
|
-
}
|
|
1921
|
-
store.subscribe(debouncedPersist);
|
|
1922
|
-
},
|
|
1923
|
-
onDestroy() {
|
|
1924
|
-
if (cancelDebounce) {
|
|
1925
|
-
cancelDebounce();
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
};
|
|
1929
|
-
}
|
|
1930
|
-
function createStorage(storage) {
|
|
1931
|
-
return storage;
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
// src/plugins/devtools.ts
|
|
1935
|
-
function hasDevtools() {
|
|
1936
|
-
return typeof window !== "undefined" && !!window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
1937
|
-
}
|
|
1938
|
-
function getDevtools() {
|
|
1939
|
-
if (typeof window === "undefined") return null;
|
|
1940
|
-
return window.__REDUX_DEVTOOLS_EXTENSION__ || null;
|
|
1941
|
-
}
|
|
1942
|
-
function devtools(options = {}) {
|
|
1943
|
-
const { name = "OxogState Store", enabled = true, maxAge = 50 } = options;
|
|
1944
|
-
let connection = null;
|
|
1945
|
-
let history2 = [];
|
|
1946
|
-
return {
|
|
1947
|
-
name: "devtools",
|
|
1948
|
-
version: "1.0.0",
|
|
1949
|
-
install(store) {
|
|
1950
|
-
if (!enabled || !hasDevtools()) {
|
|
1951
|
-
return;
|
|
1952
|
-
}
|
|
1953
|
-
const extension = getDevtools();
|
|
1954
|
-
if (!extension) return;
|
|
1955
|
-
connection = extension.connect({ name });
|
|
1956
|
-
connection.init(store.getState());
|
|
1957
|
-
store.subscribe((state, prevState) => {
|
|
1958
|
-
if (!connection) return;
|
|
1959
|
-
history2.push({ state, action: "UPDATE" });
|
|
1960
|
-
if (history2.length > maxAge) {
|
|
1961
|
-
history2.shift();
|
|
1962
|
-
}
|
|
1963
|
-
connection.send({ type: "UPDATE", prev: prevState }, state);
|
|
1964
|
-
});
|
|
1965
|
-
connection.subscribe((message) => {
|
|
1966
|
-
if (message.type === "DISPATCH" && message.payload) {
|
|
1967
|
-
switch (message.payload.type) {
|
|
1968
|
-
case "JUMP_TO_STATE":
|
|
1969
|
-
case "JUMP_TO_ACTION": {
|
|
1970
|
-
const index = message.payload.type === "JUMP_TO_ACTION" ? history2.findIndex((h) => h.action === message.payload.action) : message.payload.index;
|
|
1971
|
-
if (index >= 0 && index < history2.length) {
|
|
1972
|
-
const entry = history2[index];
|
|
1973
|
-
if (entry) {
|
|
1974
|
-
store.setState(entry.state);
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
break;
|
|
1978
|
-
}
|
|
1979
|
-
case "COMMIT": {
|
|
1980
|
-
connection.init(store.getState());
|
|
1981
|
-
history2 = [];
|
|
1982
|
-
break;
|
|
1983
|
-
}
|
|
1984
|
-
case "ROLLBACK": {
|
|
1985
|
-
if (history2.length > 1) {
|
|
1986
|
-
const previous = history2[history2.length - 2];
|
|
1987
|
-
if (previous) {
|
|
1988
|
-
store.setState(previous.state);
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
break;
|
|
1992
|
-
}
|
|
1993
|
-
case "RESET": {
|
|
1994
|
-
store.reset();
|
|
1995
|
-
break;
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
});
|
|
2000
|
-
},
|
|
2001
|
-
onDestroy() {
|
|
2002
|
-
connection = null;
|
|
2003
|
-
history2 = [];
|
|
2004
|
-
}
|
|
2005
|
-
};
|
|
2006
|
-
}
|
|
2007
|
-
|
|
2008
|
-
// src/plugins/history.ts
|
|
2009
|
-
function history(options = {}) {
|
|
2010
|
-
const { limit = 50, keys } = options;
|
|
2011
|
-
let historyState = null;
|
|
2012
|
-
let isInternalUpdate = false;
|
|
2013
|
-
return {
|
|
2014
|
-
name: "history",
|
|
2015
|
-
version: "1.0.0",
|
|
2016
|
-
install(store) {
|
|
2017
|
-
historyState = {
|
|
2018
|
-
past: [],
|
|
2019
|
-
present: store.getState(),
|
|
2020
|
-
future: []
|
|
2021
|
-
};
|
|
2022
|
-
store.subscribe((state) => {
|
|
2023
|
-
if (!historyState || isInternalUpdate) return;
|
|
2024
|
-
const previousPresent = historyState.present;
|
|
2025
|
-
const newPresent = state;
|
|
2026
|
-
let hasChanged = true;
|
|
2027
|
-
if (keys && keys.length > 0) {
|
|
2028
|
-
hasChanged = keys.some((key) => {
|
|
2029
|
-
return previousPresent[key] !== newPresent[key];
|
|
2030
|
-
});
|
|
2031
|
-
} else {
|
|
2032
|
-
hasChanged = previousPresent !== newPresent;
|
|
2033
|
-
}
|
|
2034
|
-
if (!hasChanged) return;
|
|
2035
|
-
historyState.past.push(previousPresent);
|
|
2036
|
-
if (historyState.past.length > limit) {
|
|
2037
|
-
historyState.past.shift();
|
|
2038
|
-
}
|
|
2039
|
-
historyState.present = newPresent;
|
|
2040
|
-
historyState.future = [];
|
|
2041
|
-
});
|
|
2042
|
-
store.undo = () => {
|
|
2043
|
-
if (!historyState || historyState.past.length === 0) return;
|
|
2044
|
-
const previous = historyState.past.pop();
|
|
2045
|
-
historyState.future.push(historyState.present);
|
|
2046
|
-
historyState.present = previous;
|
|
2047
|
-
isInternalUpdate = true;
|
|
2048
|
-
store.setState(previous);
|
|
2049
|
-
isInternalUpdate = false;
|
|
2050
|
-
};
|
|
2051
|
-
store.redo = () => {
|
|
2052
|
-
if (!historyState || historyState.future.length === 0) return;
|
|
2053
|
-
const next = historyState.future.pop();
|
|
2054
|
-
historyState.past.push(historyState.present);
|
|
2055
|
-
historyState.present = next;
|
|
2056
|
-
isInternalUpdate = true;
|
|
2057
|
-
store.setState(next);
|
|
2058
|
-
isInternalUpdate = false;
|
|
2059
|
-
};
|
|
2060
|
-
store.clearHistory = () => {
|
|
2061
|
-
if (!historyState) return;
|
|
2062
|
-
historyState.past = [];
|
|
2063
|
-
historyState.future = [];
|
|
2064
|
-
};
|
|
2065
|
-
store.canUndo = () => {
|
|
2066
|
-
return historyState !== null && historyState.past.length > 0;
|
|
2067
|
-
};
|
|
2068
|
-
store.canRedo = () => {
|
|
2069
|
-
return historyState !== null && historyState.future.length > 0;
|
|
2070
|
-
};
|
|
2071
|
-
},
|
|
2072
|
-
onDestroy() {
|
|
2073
|
-
historyState = null;
|
|
2074
|
-
}
|
|
2075
|
-
};
|
|
2076
|
-
}
|
|
2077
|
-
function hasHistory(store) {
|
|
2078
|
-
return typeof store.undo === "function" && typeof store.redo === "function";
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
// src/plugins/sync.ts
|
|
2082
|
-
function sync(options = {}) {
|
|
2083
|
-
const { channel = "oxog-state" } = options;
|
|
2084
|
-
let broadcastChannel = null;
|
|
2085
|
-
let currentStore = null;
|
|
2086
|
-
let isLocalUpdate = false;
|
|
2087
|
-
return {
|
|
2088
|
-
name: "sync",
|
|
2089
|
-
version: "1.0.0",
|
|
2090
|
-
install(store) {
|
|
2091
|
-
currentStore = store;
|
|
2092
|
-
if (typeof BroadcastChannel === "undefined") {
|
|
2093
|
-
console.warn("BroadcastChannel is not supported in this environment");
|
|
2094
|
-
return;
|
|
2095
|
-
}
|
|
2096
|
-
broadcastChannel = new BroadcastChannel(channel);
|
|
2097
|
-
broadcastChannel.onmessage = (event) => {
|
|
2098
|
-
if (!isLocalUpdate) {
|
|
2099
|
-
try {
|
|
2100
|
-
store.setState(event.data);
|
|
2101
|
-
} catch (error) {
|
|
2102
|
-
console.error("Error applying sync state:", error);
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
};
|
|
2106
|
-
},
|
|
2107
|
-
onInit() {
|
|
2108
|
-
if (broadcastChannel && currentStore) {
|
|
2109
|
-
isLocalUpdate = true;
|
|
2110
|
-
try {
|
|
2111
|
-
broadcastChannel.postMessage(currentStore.getState());
|
|
2112
|
-
} catch (error) {
|
|
2113
|
-
console.error("Error broadcasting initial state:", error);
|
|
2114
|
-
}
|
|
2115
|
-
isLocalUpdate = false;
|
|
2116
|
-
}
|
|
2117
|
-
},
|
|
2118
|
-
onDestroy() {
|
|
2119
|
-
if (broadcastChannel) {
|
|
2120
|
-
broadcastChannel.close();
|
|
2121
|
-
broadcastChannel = null;
|
|
2122
|
-
}
|
|
2123
|
-
currentStore = null;
|
|
2124
|
-
}
|
|
2125
|
-
};
|
|
2126
|
-
}
|
|
2127
|
-
function triggerSync(store, channel = "oxog-state") {
|
|
2128
|
-
if (typeof BroadcastChannel === "undefined") {
|
|
2129
|
-
console.warn("BroadcastChannel is not supported in this environment");
|
|
2130
|
-
return;
|
|
2131
|
-
}
|
|
2132
|
-
const broadcastChannel = new BroadcastChannel(channel);
|
|
2133
|
-
broadcastChannel.postMessage(store.getState());
|
|
2134
|
-
broadcastChannel.close();
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
// src/plugins/immer.ts
|
|
2138
|
-
function createProxy(base, copies) {
|
|
2139
|
-
return new Proxy(base || {}, {
|
|
2140
|
-
get(target, key) {
|
|
2141
|
-
const value = target[key];
|
|
2142
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
2143
|
-
if (copies.has(value)) {
|
|
2144
|
-
return createProxy(copies.get(value), copies);
|
|
2145
|
-
}
|
|
2146
|
-
return createProxy(value, copies);
|
|
2147
|
-
}
|
|
2148
|
-
return value;
|
|
2149
|
-
},
|
|
2150
|
-
set(target, key, value) {
|
|
2151
|
-
if (!copies.has(target)) {
|
|
2152
|
-
copies.set(target, { ...target });
|
|
2153
|
-
}
|
|
2154
|
-
const copy = copies.get(target);
|
|
2155
|
-
copy[key] = value;
|
|
2156
|
-
return true;
|
|
2157
|
-
},
|
|
2158
|
-
deleteProperty(target, key) {
|
|
2159
|
-
if (!copies.has(target)) {
|
|
2160
|
-
copies.set(target, { ...target });
|
|
2161
|
-
}
|
|
2162
|
-
const copy = copies.get(target);
|
|
2163
|
-
delete copy[key];
|
|
2164
|
-
return true;
|
|
2165
|
-
}
|
|
2166
|
-
});
|
|
2167
|
-
}
|
|
2168
|
-
function finalize(base, copies) {
|
|
2169
|
-
if (!copies.has(base)) {
|
|
2170
|
-
return deepClone2(base);
|
|
2171
|
-
}
|
|
2172
|
-
const copy = copies.get(base);
|
|
2173
|
-
for (const key in copy) {
|
|
2174
|
-
if (Object.prototype.hasOwnProperty.call(copy, key)) {
|
|
2175
|
-
const value = copy[key];
|
|
2176
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
2177
|
-
copy[key] = finalize(value, copies);
|
|
2178
|
-
}
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
return copy;
|
|
2182
|
-
}
|
|
2183
|
-
function deepClone2(value) {
|
|
2184
|
-
if (value === null || typeof value !== "object") {
|
|
2185
|
-
return value;
|
|
2186
|
-
}
|
|
2187
|
-
if (Array.isArray(value)) {
|
|
2188
|
-
return value.map((v) => deepClone2(v));
|
|
2189
|
-
}
|
|
2190
|
-
const cloned = {};
|
|
2191
|
-
for (const key in value) {
|
|
2192
|
-
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
2193
|
-
cloned[key] = deepClone2(value[key]);
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
return cloned;
|
|
2197
|
-
}
|
|
2198
|
-
function produce(base, recipe) {
|
|
2199
|
-
const copies = /* @__PURE__ */ new Map();
|
|
2200
|
-
const draft = createProxy(base, copies);
|
|
2201
|
-
recipe(draft);
|
|
2202
|
-
return finalize(base, copies);
|
|
2203
|
-
}
|
|
2204
|
-
function immer() {
|
|
2205
|
-
return {
|
|
2206
|
-
name: "immer",
|
|
2207
|
-
version: "1.0.0",
|
|
2208
|
-
install(store) {
|
|
2209
|
-
const originalSetState = store.setState.bind(store);
|
|
2210
|
-
store.setState = (update) => {
|
|
2211
|
-
if (typeof update === "function") {
|
|
2212
|
-
const newState = produce(store.getState(), update);
|
|
2213
|
-
originalSetState(newState);
|
|
2214
|
-
} else {
|
|
2215
|
-
originalSetState(update);
|
|
2216
|
-
}
|
|
2217
|
-
};
|
|
2218
|
-
}
|
|
2219
|
-
};
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
// src/plugins/selector.ts
|
|
2223
|
-
function selector(options) {
|
|
2224
|
-
const { selectors } = options;
|
|
2225
|
-
return {
|
|
2226
|
-
name: "selector",
|
|
2227
|
-
version: "1.0.0",
|
|
2228
|
-
install(store) {
|
|
2229
|
-
const originalGetState = store.getState.bind(store);
|
|
2230
|
-
const cache = /* @__PURE__ */ new Map();
|
|
2231
|
-
const computedState = new Proxy({}, {
|
|
2232
|
-
get(_, prop) {
|
|
2233
|
-
const selectorFn = selectors[prop];
|
|
2234
|
-
if (selectorFn) {
|
|
2235
|
-
const currentState = originalGetState();
|
|
2236
|
-
const cacheKey = prop;
|
|
2237
|
-
const cached = cache.get(cacheKey);
|
|
2238
|
-
if (cached && cached.state === currentState) {
|
|
2239
|
-
return cached.value;
|
|
2240
|
-
}
|
|
2241
|
-
const value = selectorFn(currentState);
|
|
2242
|
-
cache.set(cacheKey, { value, state: currentState });
|
|
2243
|
-
return value;
|
|
2244
|
-
}
|
|
2245
|
-
return originalGetState()[prop];
|
|
2246
|
-
}
|
|
2247
|
-
});
|
|
2248
|
-
store.getState = () => computedState;
|
|
2249
|
-
store.subscribe(() => {
|
|
2250
|
-
cache.clear();
|
|
2251
|
-
});
|
|
2252
|
-
}
|
|
2253
|
-
};
|
|
2254
|
-
}
|
|
2255
|
-
|
|
2256
|
-
// src/plugins/logger.ts
|
|
2257
|
-
var LOG_LEVELS = {
|
|
2258
|
-
debug: 0,
|
|
2259
|
-
info: 1,
|
|
2260
|
-
warn: 2,
|
|
2261
|
-
error: 3
|
|
2262
|
-
};
|
|
2263
|
-
var COLORS = {
|
|
2264
|
-
title: "#9E9E9E",
|
|
2265
|
-
prevState: "#9E9E9E",
|
|
2266
|
-
action: "#03A9F4",
|
|
2267
|
-
nextState: "#4CAF50",
|
|
2268
|
-
diff: {
|
|
2269
|
-
changed: "#2196F3"
|
|
2270
|
-
}
|
|
2271
|
-
};
|
|
2272
|
-
function formatTime(date) {
|
|
2273
|
-
const hours = date.getHours().toString().padStart(2, "0");
|
|
2274
|
-
const minutes = date.getMinutes().toString().padStart(2, "0");
|
|
2275
|
-
const seconds = date.getSeconds().toString().padStart(2, "0");
|
|
2276
|
-
const ms = date.getMilliseconds().toString().padStart(3, "0");
|
|
2277
|
-
return `${hours}:${minutes}:${seconds}.${ms}`;
|
|
2278
|
-
}
|
|
2279
|
-
function calculateDiff(prevState, nextState) {
|
|
2280
|
-
const diff = {};
|
|
2281
|
-
if (typeof prevState !== "object" || typeof nextState !== "object") {
|
|
2282
|
-
if (prevState !== nextState) {
|
|
2283
|
-
diff["value"] = { prev: prevState, next: nextState };
|
|
2284
|
-
}
|
|
2285
|
-
return diff;
|
|
2286
|
-
}
|
|
2287
|
-
if (prevState === null || nextState === null) {
|
|
2288
|
-
if (prevState !== nextState) {
|
|
2289
|
-
diff["value"] = { prev: prevState, next: nextState };
|
|
2290
|
-
}
|
|
2291
|
-
return diff;
|
|
2292
|
-
}
|
|
2293
|
-
const allKeys = /* @__PURE__ */ new Set([
|
|
2294
|
-
...Object.keys(prevState),
|
|
2295
|
-
...Object.keys(nextState)
|
|
2296
|
-
]);
|
|
2297
|
-
for (const key of allKeys) {
|
|
2298
|
-
const prev = prevState[key];
|
|
2299
|
-
const next = nextState[key];
|
|
2300
|
-
if (prev !== next) {
|
|
2301
|
-
diff[key] = { prev, next };
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
return diff;
|
|
2305
|
-
}
|
|
2306
|
-
function isBrowser() {
|
|
2307
|
-
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
2308
|
-
}
|
|
2309
|
-
function logger(options = {}) {
|
|
2310
|
-
const {
|
|
2311
|
-
level = "debug",
|
|
2312
|
-
logger: customLogger = console,
|
|
2313
|
-
collapsed = true,
|
|
2314
|
-
diff = true,
|
|
2315
|
-
colors = isBrowser(),
|
|
2316
|
-
timestamp = true,
|
|
2317
|
-
filter,
|
|
2318
|
-
stateTransformer,
|
|
2319
|
-
actionName = "STATE_CHANGE",
|
|
2320
|
-
name = "Store",
|
|
2321
|
-
enabled = true
|
|
2322
|
-
} = options;
|
|
2323
|
-
const minLevel = LOG_LEVELS[level];
|
|
2324
|
-
return {
|
|
2325
|
-
name: "logger",
|
|
2326
|
-
version: "1.0.0",
|
|
2327
|
-
install(store) {
|
|
2328
|
-
if (!enabled) return;
|
|
2329
|
-
store.subscribe((state, prevState) => {
|
|
2330
|
-
if (filter && !filter(state, prevState)) {
|
|
2331
|
-
return;
|
|
2332
|
-
}
|
|
2333
|
-
if (LOG_LEVELS.info < minLevel) {
|
|
2334
|
-
return;
|
|
2335
|
-
}
|
|
2336
|
-
const now = /* @__PURE__ */ new Date();
|
|
2337
|
-
const action = typeof actionName === "function" ? actionName(state, prevState) : actionName;
|
|
2338
|
-
const displayPrevState = stateTransformer ? stateTransformer(prevState) : prevState;
|
|
2339
|
-
const displayNextState = stateTransformer ? stateTransformer(state) : state;
|
|
2340
|
-
const timeStr = timestamp ? ` @ ${formatTime(now)}` : "";
|
|
2341
|
-
const title = `${name} ${action}${timeStr}`;
|
|
2342
|
-
if (colors && isBrowser()) {
|
|
2343
|
-
logWithColors(
|
|
2344
|
-
customLogger,
|
|
2345
|
-
title,
|
|
2346
|
-
displayPrevState,
|
|
2347
|
-
displayNextState,
|
|
2348
|
-
collapsed,
|
|
2349
|
-
diff ? calculateDiff(prevState, state) : void 0
|
|
2350
|
-
);
|
|
2351
|
-
} else {
|
|
2352
|
-
logPlain(
|
|
2353
|
-
customLogger,
|
|
2354
|
-
title,
|
|
2355
|
-
displayPrevState,
|
|
2356
|
-
displayNextState,
|
|
2357
|
-
collapsed,
|
|
2358
|
-
diff ? calculateDiff(prevState, state) : void 0
|
|
2359
|
-
);
|
|
2360
|
-
}
|
|
2361
|
-
});
|
|
2362
|
-
}
|
|
2363
|
-
};
|
|
2364
|
-
}
|
|
2365
|
-
function logWithColors(log, title, prevState, nextState, collapsed, diff) {
|
|
2366
|
-
const titleStyle = `color: ${COLORS.title}; font-weight: lighter;`;
|
|
2367
|
-
const groupMethod = collapsed ? "groupCollapsed" : "group";
|
|
2368
|
-
log[groupMethod](`%c${title}`, titleStyle);
|
|
2369
|
-
log.log("%cprev state", `color: ${COLORS.prevState}; font-weight: bold;`, prevState);
|
|
2370
|
-
log.log("%cnext state", `color: ${COLORS.nextState}; font-weight: bold;`, nextState);
|
|
2371
|
-
if (diff && Object.keys(diff).length > 0) {
|
|
2372
|
-
log.log("%cdiff", `color: ${COLORS.action}; font-weight: bold;`);
|
|
2373
|
-
for (const [key, { prev, next }] of Object.entries(diff)) {
|
|
2374
|
-
log.log(
|
|
2375
|
-
` %c${key}:`,
|
|
2376
|
-
`color: ${COLORS.diff.changed};`,
|
|
2377
|
-
prev,
|
|
2378
|
-
"\u2192",
|
|
2379
|
-
next
|
|
2380
|
-
);
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
log.groupEnd();
|
|
2384
|
-
}
|
|
2385
|
-
function logPlain(log, title, prevState, nextState, collapsed, diff) {
|
|
2386
|
-
const hasGroupCollapsed = typeof log.groupCollapsed === "function";
|
|
2387
|
-
const groupMethod = collapsed && hasGroupCollapsed ? "groupCollapsed" : "group";
|
|
2388
|
-
const hasGroup = typeof log[groupMethod] === "function";
|
|
2389
|
-
if (hasGroup) {
|
|
2390
|
-
log[groupMethod](title);
|
|
2391
|
-
} else {
|
|
2392
|
-
log.log(`=== ${title} ===`);
|
|
2393
|
-
}
|
|
2394
|
-
log.log("prev state:", prevState);
|
|
2395
|
-
log.log("next state:", nextState);
|
|
2396
|
-
if (diff && Object.keys(diff).length > 0) {
|
|
2397
|
-
log.log("diff:");
|
|
2398
|
-
for (const [key, { prev, next }] of Object.entries(diff)) {
|
|
2399
|
-
log.log(` ${key}:`, prev, "\u2192", next);
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
if (hasGroup) {
|
|
2403
|
-
log.groupEnd();
|
|
2404
|
-
} else {
|
|
2405
|
-
log.log("===");
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
function createLogger(defaultOptions = {}) {
|
|
2409
|
-
return (options = {}) => logger({ ...defaultOptions, ...options });
|
|
2410
|
-
}
|
|
2411
|
-
|
|
2412
|
-
// src/plugins/effects.ts
|
|
2413
|
-
init_utils();
|
|
2414
|
-
function createDebounced3(fn, delay2) {
|
|
2415
|
-
let timeoutId = null;
|
|
2416
|
-
const debounced = ((...args) => {
|
|
2417
|
-
if (timeoutId) {
|
|
2418
|
-
clearTimeout(timeoutId);
|
|
2419
|
-
}
|
|
2420
|
-
timeoutId = setTimeout(() => {
|
|
2421
|
-
fn(...args);
|
|
2422
|
-
timeoutId = null;
|
|
2423
|
-
}, delay2);
|
|
2424
|
-
});
|
|
2425
|
-
debounced.cancel = () => {
|
|
2426
|
-
if (timeoutId) {
|
|
2427
|
-
clearTimeout(timeoutId);
|
|
2428
|
-
timeoutId = null;
|
|
2429
|
-
}
|
|
2430
|
-
};
|
|
2431
|
-
return debounced;
|
|
2432
|
-
}
|
|
2433
|
-
function effects(options) {
|
|
2434
|
-
const { effects: effectDefs, onError } = options;
|
|
2435
|
-
return {
|
|
2436
|
-
name: "effects",
|
|
2437
|
-
version: "1.0.0",
|
|
2438
|
-
install(store) {
|
|
2439
|
-
const cleanups = [];
|
|
2440
|
-
const effectCleanups = /* @__PURE__ */ new Map();
|
|
2441
|
-
for (let i = 0; i < effectDefs.length; i++) {
|
|
2442
|
-
const def = effectDefs[i];
|
|
2443
|
-
if (!def) continue;
|
|
2444
|
-
const {
|
|
2445
|
-
selector: selector2,
|
|
2446
|
-
effect,
|
|
2447
|
-
equalityFn = shallowEqual,
|
|
2448
|
-
fireImmediately = false,
|
|
2449
|
-
debounce,
|
|
2450
|
-
name
|
|
2451
|
-
} = def;
|
|
2452
|
-
let isActive = true;
|
|
2453
|
-
let prevValue = selector2(store.getState());
|
|
2454
|
-
const createUtils = () => ({
|
|
2455
|
-
getState: () => store.getState(),
|
|
2456
|
-
setState: (partial) => store.setState(partial),
|
|
2457
|
-
isActive: () => isActive,
|
|
2458
|
-
cancel: () => {
|
|
2459
|
-
isActive = false;
|
|
2460
|
-
},
|
|
2461
|
-
onlyIfActive: (fn) => {
|
|
2462
|
-
if (isActive) {
|
|
2463
|
-
return fn();
|
|
2464
|
-
}
|
|
2465
|
-
return void 0;
|
|
2466
|
-
}
|
|
2467
|
-
});
|
|
2468
|
-
const runEffect = async (value, prev) => {
|
|
2469
|
-
const prevCleanup = effectCleanups.get(i);
|
|
2470
|
-
if (prevCleanup) {
|
|
2471
|
-
try {
|
|
2472
|
-
prevCleanup();
|
|
2473
|
-
} catch (e) {
|
|
2474
|
-
}
|
|
2475
|
-
effectCleanups.delete(i);
|
|
2476
|
-
}
|
|
2477
|
-
isActive = true;
|
|
2478
|
-
try {
|
|
2479
|
-
const result = effect(value, prev, createUtils());
|
|
2480
|
-
if (result instanceof Promise) {
|
|
2481
|
-
const cleanup = await result;
|
|
2482
|
-
if (cleanup && isActive) {
|
|
2483
|
-
effectCleanups.set(i, cleanup);
|
|
2484
|
-
}
|
|
2485
|
-
} else if (result) {
|
|
2486
|
-
effectCleanups.set(i, result);
|
|
2487
|
-
}
|
|
2488
|
-
} catch (error) {
|
|
2489
|
-
if (onError) {
|
|
2490
|
-
onError(error, name);
|
|
2491
|
-
} else {
|
|
2492
|
-
console.error(`Effect error${name ? ` in '${name}'` : ""}:`, error);
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
};
|
|
2496
|
-
const effectFn = debounce && debounce > 0 ? createDebounced3(runEffect, debounce) : runEffect;
|
|
2497
|
-
if (fireImmediately) {
|
|
2498
|
-
effectFn(prevValue, prevValue);
|
|
2499
|
-
}
|
|
2500
|
-
const unsubscribe = store.subscribe(
|
|
2501
|
-
selector2,
|
|
2502
|
-
(value, prev) => {
|
|
2503
|
-
if (!equalityFn(value, prev)) {
|
|
2504
|
-
prevValue = value;
|
|
2505
|
-
effectFn(value, prev);
|
|
2506
|
-
}
|
|
2507
|
-
},
|
|
2508
|
-
equalityFn
|
|
2509
|
-
);
|
|
2510
|
-
cleanups.push(() => {
|
|
2511
|
-
unsubscribe();
|
|
2512
|
-
isActive = false;
|
|
2513
|
-
if ("cancel" in effectFn) {
|
|
2514
|
-
effectFn.cancel();
|
|
2515
|
-
}
|
|
2516
|
-
const cleanup = effectCleanups.get(i);
|
|
2517
|
-
if (cleanup) {
|
|
2518
|
-
try {
|
|
2519
|
-
cleanup();
|
|
2520
|
-
} catch {
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
});
|
|
2524
|
-
}
|
|
2525
|
-
store.__effectsCleanup = () => {
|
|
2526
|
-
for (const cleanup of cleanups) {
|
|
2527
|
-
cleanup();
|
|
2528
|
-
}
|
|
2529
|
-
effectCleanups.clear();
|
|
2530
|
-
};
|
|
2531
|
-
}
|
|
2532
|
-
};
|
|
2533
|
-
}
|
|
2534
|
-
function createEffect(name, selector2, effect, options = {}) {
|
|
2535
|
-
return {
|
|
2536
|
-
name,
|
|
2537
|
-
selector: selector2,
|
|
2538
|
-
effect,
|
|
2539
|
-
...options
|
|
2540
|
-
};
|
|
2541
|
-
}
|
|
2542
|
-
function createSimpleEffect(effect, options = {}) {
|
|
2543
|
-
return {
|
|
2544
|
-
selector: (s) => s,
|
|
2545
|
-
effect,
|
|
2546
|
-
equalityFn: () => false,
|
|
2547
|
-
// Always run
|
|
2548
|
-
...options
|
|
2549
|
-
};
|
|
2550
|
-
}
|
|
2551
|
-
function combineEffects(...effectDefs) {
|
|
2552
|
-
return {
|
|
2553
|
-
effects: effectDefs
|
|
2554
|
-
};
|
|
2555
|
-
}
|
|
2556
|
-
function createDebouncedEffect(delay2, selector2, effect, options = {}) {
|
|
2557
|
-
return {
|
|
2558
|
-
selector: selector2,
|
|
2559
|
-
effect,
|
|
2560
|
-
debounce: delay2,
|
|
2561
|
-
...options
|
|
2562
|
-
};
|
|
2563
|
-
}
|
|
2564
|
-
|
|
2565
|
-
// src/plugins/validate.ts
|
|
2566
|
-
function isZodLike(schema) {
|
|
2567
|
-
return typeof schema === "object" && schema !== null && "safeParse" in schema && typeof schema.safeParse === "function";
|
|
2568
|
-
}
|
|
2569
|
-
function isYupLike(schema) {
|
|
2570
|
-
return typeof schema === "object" && schema !== null && "validateSync" in schema && typeof schema.validateSync === "function";
|
|
2571
|
-
}
|
|
2572
|
-
function extractPaths(state, paths) {
|
|
2573
|
-
const result = {};
|
|
2574
|
-
for (const path of paths) {
|
|
2575
|
-
if (path in state) {
|
|
2576
|
-
result[path] = state[path];
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
return result;
|
|
2580
|
-
}
|
|
2581
|
-
function validateState(state, schema, paths) {
|
|
2582
|
-
const stateToValidate = paths ? extractPaths(state, paths) : state;
|
|
2583
|
-
if (typeof schema === "function") {
|
|
2584
|
-
const result = schema(stateToValidate);
|
|
2585
|
-
if (typeof result === "boolean") {
|
|
2586
|
-
return {
|
|
2587
|
-
valid: result,
|
|
2588
|
-
errors: result ? [] : [{ path: [], message: "Validation failed" }]
|
|
2589
|
-
};
|
|
2590
|
-
}
|
|
2591
|
-
if ("valid" in result && "errors" in result) {
|
|
2592
|
-
return result;
|
|
2593
|
-
}
|
|
2594
|
-
if (Array.isArray(result)) {
|
|
2595
|
-
return {
|
|
2596
|
-
valid: result.length === 0,
|
|
2597
|
-
errors: result
|
|
2598
|
-
};
|
|
2599
|
-
}
|
|
2600
|
-
return { valid: true, errors: [] };
|
|
2601
|
-
}
|
|
2602
|
-
if (isZodLike(schema)) {
|
|
2603
|
-
const result = schema.safeParse(stateToValidate);
|
|
2604
|
-
if (result.success) {
|
|
2605
|
-
return { valid: true, errors: [] };
|
|
2606
|
-
}
|
|
2607
|
-
const errors = (result.error?.issues || []).map((issue) => ({
|
|
2608
|
-
path: issue.path.map(String),
|
|
2609
|
-
message: issue.message,
|
|
2610
|
-
rule: issue.code
|
|
2611
|
-
}));
|
|
2612
|
-
return { valid: false, errors };
|
|
2613
|
-
}
|
|
2614
|
-
if (isYupLike(schema)) {
|
|
2615
|
-
try {
|
|
2616
|
-
schema.validateSync(stateToValidate, { abortEarly: false });
|
|
2617
|
-
return { valid: true, errors: [] };
|
|
2618
|
-
} catch (error) {
|
|
2619
|
-
const errors = [];
|
|
2620
|
-
if (error.inner && Array.isArray(error.inner)) {
|
|
2621
|
-
for (const err of error.inner) {
|
|
2622
|
-
errors.push({
|
|
2623
|
-
path: err.path ? err.path.split(".") : [],
|
|
2624
|
-
message: err.message,
|
|
2625
|
-
rule: err.type,
|
|
2626
|
-
value: err.value
|
|
2627
|
-
});
|
|
2628
|
-
}
|
|
2629
|
-
} else {
|
|
2630
|
-
errors.push({
|
|
2631
|
-
path: error.path ? error.path.split(".") : [],
|
|
2632
|
-
message: error.message || "Validation failed",
|
|
2633
|
-
rule: error.type
|
|
2634
|
-
});
|
|
2635
|
-
}
|
|
2636
|
-
return { valid: false, errors };
|
|
2637
|
-
}
|
|
2638
|
-
}
|
|
2639
|
-
return { valid: true, errors: [] };
|
|
2640
|
-
}
|
|
2641
|
-
function validate(options) {
|
|
2642
|
-
const {
|
|
2643
|
-
schema,
|
|
2644
|
-
on = "change",
|
|
2645
|
-
onError,
|
|
2646
|
-
throwOnError = false,
|
|
2647
|
-
paths,
|
|
2648
|
-
name = "validate"
|
|
2649
|
-
} = options;
|
|
2650
|
-
return {
|
|
2651
|
-
name,
|
|
2652
|
-
version: "1.0.0",
|
|
2653
|
-
install(store) {
|
|
2654
|
-
let currentErrors = [];
|
|
2655
|
-
const doValidate = () => {
|
|
2656
|
-
const state = store.getState();
|
|
2657
|
-
const result = validateState(state, schema, paths);
|
|
2658
|
-
currentErrors = result.errors;
|
|
2659
|
-
if (!result.valid) {
|
|
2660
|
-
if (onError) {
|
|
2661
|
-
onError(result.errors);
|
|
2662
|
-
}
|
|
2663
|
-
if (throwOnError) {
|
|
2664
|
-
const errorMessages = result.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join(", ");
|
|
2665
|
-
throw new Error(`Validation failed: ${errorMessages}`);
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
return result;
|
|
2669
|
-
};
|
|
2670
|
-
if (on === "change") {
|
|
2671
|
-
store.subscribe(() => {
|
|
2672
|
-
doValidate();
|
|
2673
|
-
});
|
|
2674
|
-
}
|
|
2675
|
-
const validationAPI = {
|
|
2676
|
-
validate: doValidate,
|
|
2677
|
-
isValid: () => currentErrors.length === 0,
|
|
2678
|
-
getErrors: () => [...currentErrors],
|
|
2679
|
-
clearErrors: () => {
|
|
2680
|
-
currentErrors = [];
|
|
2681
|
-
}
|
|
2682
|
-
};
|
|
2683
|
-
Object.assign(store, validationAPI);
|
|
2684
|
-
}
|
|
2685
|
-
};
|
|
2686
|
-
}
|
|
2687
|
-
function createValidator(predicate, message) {
|
|
2688
|
-
return (state) => {
|
|
2689
|
-
const valid = predicate(state);
|
|
2690
|
-
return {
|
|
2691
|
-
valid,
|
|
2692
|
-
errors: valid ? [] : [{ path: [], message }]
|
|
2693
|
-
};
|
|
2694
|
-
};
|
|
2695
|
-
}
|
|
2696
|
-
function combineValidators(...validators) {
|
|
2697
|
-
return (state) => {
|
|
2698
|
-
const allErrors = [];
|
|
2699
|
-
for (const validator of validators) {
|
|
2700
|
-
const result = validator(state);
|
|
2701
|
-
if (typeof result === "boolean") {
|
|
2702
|
-
if (!result) {
|
|
2703
|
-
allErrors.push({ path: [], message: "Validation failed" });
|
|
2704
|
-
}
|
|
2705
|
-
} else if ("valid" in result && "errors" in result) {
|
|
2706
|
-
allErrors.push(...result.errors);
|
|
2707
|
-
} else if (Array.isArray(result)) {
|
|
2708
|
-
allErrors.push(...result);
|
|
2709
|
-
}
|
|
2710
|
-
}
|
|
2711
|
-
return {
|
|
2712
|
-
valid: allErrors.length === 0,
|
|
2713
|
-
errors: allErrors
|
|
2714
|
-
};
|
|
2715
|
-
};
|
|
2716
|
-
}
|
|
2717
|
-
function createFieldValidator(field, predicate, message) {
|
|
2718
|
-
return (state) => {
|
|
2719
|
-
const valid = predicate(state[field], state);
|
|
2720
|
-
return {
|
|
2721
|
-
valid,
|
|
2722
|
-
errors: valid ? [] : [{ path: [String(field)], message, value: state[field] }]
|
|
2723
|
-
};
|
|
2724
|
-
};
|
|
2725
|
-
}
|
|
2726
|
-
function createAsyncValidator(validator) {
|
|
2727
|
-
return async (state) => {
|
|
2728
|
-
const errors = await validator(state);
|
|
2729
|
-
return {
|
|
2730
|
-
valid: errors.length === 0,
|
|
2731
|
-
errors
|
|
2732
|
-
};
|
|
2733
|
-
};
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
// src/index.ts
|
|
2737
|
-
init_utils();
|
|
2738
|
-
|
|
2739
|
-
// src/testing.ts
|
|
2740
|
-
init_store();
|
|
2741
|
-
init_utils();
|
|
2742
|
-
function createMockStorage() {
|
|
2743
|
-
const storage = /* @__PURE__ */ new Map();
|
|
2744
|
-
return {
|
|
2745
|
-
getItem(key) {
|
|
2746
|
-
return storage.get(key) ?? null;
|
|
2747
|
-
},
|
|
2748
|
-
setItem(key, value) {
|
|
2749
|
-
storage.set(key, value);
|
|
2750
|
-
},
|
|
2751
|
-
removeItem(key) {
|
|
2752
|
-
storage.delete(key);
|
|
2753
|
-
},
|
|
2754
|
-
clear() {
|
|
2755
|
-
storage.clear();
|
|
2756
|
-
},
|
|
2757
|
-
getAll() {
|
|
2758
|
-
const result = {};
|
|
2759
|
-
for (const [key, value] of storage) {
|
|
2760
|
-
result[key] = value;
|
|
2761
|
-
}
|
|
2762
|
-
return result;
|
|
2763
|
-
}
|
|
2764
|
-
};
|
|
2765
|
-
}
|
|
2766
|
-
function spyOnStore(store) {
|
|
2767
|
-
const changes = [];
|
|
2768
|
-
const waiters = [];
|
|
2769
|
-
const unsubscribe = store.subscribe((state, prevState) => {
|
|
2770
|
-
changes.push({
|
|
2771
|
-
state,
|
|
2772
|
-
prevState,
|
|
2773
|
-
timestamp: Date.now()
|
|
2774
|
-
});
|
|
2775
|
-
for (let i = waiters.length - 1; i >= 0; i--) {
|
|
2776
|
-
const waiter = waiters[i];
|
|
2777
|
-
if (waiter && waiter.predicate(state)) {
|
|
2778
|
-
waiter.resolve(state);
|
|
2779
|
-
waiters.splice(i, 1);
|
|
2780
|
-
}
|
|
2781
|
-
}
|
|
2782
|
-
});
|
|
2783
|
-
return {
|
|
2784
|
-
changes,
|
|
2785
|
-
lastChange: () => changes[changes.length - 1],
|
|
2786
|
-
lastState: () => changes[changes.length - 1]?.state,
|
|
2787
|
-
reset: () => {
|
|
2788
|
-
changes.length = 0;
|
|
2789
|
-
},
|
|
2790
|
-
unsubscribe,
|
|
2791
|
-
waitFor: (predicate, timeout = 5e3) => {
|
|
2792
|
-
return new Promise((resolve, reject) => {
|
|
2793
|
-
const current = store.getState();
|
|
2794
|
-
if (predicate(current)) {
|
|
2795
|
-
resolve(current);
|
|
2796
|
-
return;
|
|
2797
|
-
}
|
|
2798
|
-
const waiter = { resolve, predicate };
|
|
2799
|
-
waiters.push(waiter);
|
|
2800
|
-
const timeoutId = setTimeout(() => {
|
|
2801
|
-
const index = waiters.indexOf(waiter);
|
|
2802
|
-
if (index >= 0) {
|
|
2803
|
-
waiters.splice(index, 1);
|
|
2804
|
-
reject(new Error(`waitFor timeout after ${timeout}ms`));
|
|
2805
|
-
}
|
|
2806
|
-
}, timeout);
|
|
2807
|
-
const originalResolve = waiter.resolve;
|
|
2808
|
-
waiter.resolve = (state) => {
|
|
2809
|
-
clearTimeout(timeoutId);
|
|
2810
|
-
originalResolve(state);
|
|
2811
|
-
};
|
|
2812
|
-
});
|
|
2813
|
-
},
|
|
2814
|
-
waitForChanges: (count, timeout = 5e3) => {
|
|
2815
|
-
return new Promise((resolve, reject) => {
|
|
2816
|
-
const startCount = changes.length;
|
|
2817
|
-
const check = () => {
|
|
2818
|
-
if (changes.length >= startCount + count) {
|
|
2819
|
-
return changes.slice(startCount, startCount + count);
|
|
2820
|
-
}
|
|
2821
|
-
return null;
|
|
2822
|
-
};
|
|
2823
|
-
const immediate = check();
|
|
2824
|
-
if (immediate) {
|
|
2825
|
-
resolve(immediate);
|
|
2826
|
-
return;
|
|
2827
|
-
}
|
|
2828
|
-
const intervalId = setInterval(() => {
|
|
2829
|
-
const result = check();
|
|
2830
|
-
if (result) {
|
|
2831
|
-
clearInterval(intervalId);
|
|
2832
|
-
clearTimeout(timeoutId);
|
|
2833
|
-
resolve(result);
|
|
2834
|
-
}
|
|
2835
|
-
}, 10);
|
|
2836
|
-
const timeoutId = setTimeout(() => {
|
|
2837
|
-
clearInterval(intervalId);
|
|
2838
|
-
reject(new Error(`waitForChanges timeout after ${timeout}ms`));
|
|
2839
|
-
}, timeout);
|
|
2840
|
-
});
|
|
2841
|
-
}
|
|
2842
|
-
};
|
|
2843
|
-
}
|
|
2844
|
-
function assertState(store) {
|
|
2845
|
-
return {
|
|
2846
|
-
toEqual: (expected) => {
|
|
2847
|
-
const state = store.getState();
|
|
2848
|
-
for (const [key, value] of Object.entries(expected)) {
|
|
2849
|
-
if (state[key] !== value) {
|
|
2850
|
-
throw new Error(
|
|
2851
|
-
`Expected state.${key} to be ${JSON.stringify(value)}, but got ${JSON.stringify(state[key])}`
|
|
2852
|
-
);
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
|
-
},
|
|
2856
|
-
toHaveSelected: (selector2, expected) => {
|
|
2857
|
-
const actual = selector2(store.getState());
|
|
2858
|
-
if (!shallowEqual(actual, expected)) {
|
|
2859
|
-
throw new Error(
|
|
2860
|
-
`Expected selector to return ${JSON.stringify(expected)}, but got ${JSON.stringify(actual)}`
|
|
2861
|
-
);
|
|
2862
|
-
}
|
|
2863
|
-
},
|
|
2864
|
-
toMatch: (predicate) => {
|
|
2865
|
-
const state = store.getState();
|
|
2866
|
-
if (!predicate(state)) {
|
|
2867
|
-
throw new Error(
|
|
2868
|
-
`State did not match predicate: ${JSON.stringify(state)}`
|
|
2869
|
-
);
|
|
2870
|
-
}
|
|
2871
|
-
}
|
|
2872
|
-
};
|
|
2873
|
-
}
|
|
2874
|
-
function createTestStore(options) {
|
|
2875
|
-
const { initialState, spy: enableSpy = true } = options;
|
|
2876
|
-
const store = createStore(initialState);
|
|
2877
|
-
const spy = enableSpy ? spyOnStore(store) : void 0;
|
|
2878
|
-
const assert = assertState(store);
|
|
2879
|
-
return {
|
|
2880
|
-
store,
|
|
2881
|
-
spy,
|
|
2882
|
-
assert,
|
|
2883
|
-
reset: () => {
|
|
2884
|
-
store.reset();
|
|
2885
|
-
spy?.reset();
|
|
2886
|
-
},
|
|
2887
|
-
destroy: () => {
|
|
2888
|
-
spy?.unsubscribe();
|
|
2889
|
-
store.destroy();
|
|
2890
|
-
}
|
|
2891
|
-
};
|
|
2892
|
-
}
|
|
2893
|
-
function delay(ms) {
|
|
2894
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2895
|
-
}
|
|
2896
|
-
async function flushMicrotasks(fn) {
|
|
2897
|
-
if (fn) {
|
|
2898
|
-
fn();
|
|
2899
|
-
}
|
|
2900
|
-
await Promise.resolve();
|
|
2901
|
-
}
|
|
2902
|
-
function mockAction(fn) {
|
|
2903
|
-
const calls = [];
|
|
2904
|
-
const mocked = ((...args) => {
|
|
2905
|
-
calls.push(args);
|
|
2906
|
-
return fn(...args);
|
|
2907
|
-
});
|
|
2908
|
-
Object.defineProperty(mocked, "callCount", {
|
|
2909
|
-
get: () => calls.length
|
|
2910
|
-
});
|
|
2911
|
-
mocked.calls = calls;
|
|
2912
|
-
mocked.reset = () => {
|
|
2913
|
-
calls.length = 0;
|
|
2914
|
-
};
|
|
2915
|
-
return mocked;
|
|
2916
|
-
}
|
|
2917
|
-
function snapshot(store) {
|
|
2918
|
-
return JSON.parse(JSON.stringify(store.getState()));
|
|
2919
|
-
}
|
|
2920
|
-
function stateDiff(before, after) {
|
|
2921
|
-
const diff = {};
|
|
2922
|
-
const allKeys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
2923
|
-
for (const key of allKeys) {
|
|
2924
|
-
if (!shallowEqual(before[key], after[key])) {
|
|
2925
|
-
diff[key] = { before: before[key], after: after[key] };
|
|
2926
|
-
}
|
|
2927
|
-
}
|
|
2928
|
-
return diff;
|
|
2929
|
-
}
|
|
2930
|
-
|
|
2931
|
-
// src/compat/middleware.ts
|
|
2932
|
-
function toMiddlewareApi(store) {
|
|
2933
|
-
return {
|
|
2934
|
-
setState: (partial, replace) => {
|
|
2935
|
-
if (typeof partial === "function") {
|
|
2936
|
-
const currentState = store.getState();
|
|
2937
|
-
const newPartial = partial(currentState);
|
|
2938
|
-
if (replace) {
|
|
2939
|
-
store.setState(newPartial);
|
|
2940
|
-
} else {
|
|
2941
|
-
store.merge(newPartial);
|
|
2942
|
-
}
|
|
2943
|
-
} else {
|
|
2944
|
-
if (replace) {
|
|
2945
|
-
store.setState(partial);
|
|
2946
|
-
} else {
|
|
2947
|
-
store.merge(partial);
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
},
|
|
2951
|
-
getState: () => store.getState(),
|
|
2952
|
-
subscribe: (listener) => store.subscribe(listener),
|
|
2953
|
-
destroy: () => store.destroy()
|
|
2954
|
-
};
|
|
2955
|
-
}
|
|
2956
|
-
function middlewareCompat(middleware, options) {
|
|
2957
|
-
return {
|
|
2958
|
-
name: "middleware-compat",
|
|
2959
|
-
version: "1.0.0",
|
|
2960
|
-
install(store) {
|
|
2961
|
-
const api = toMiddlewareApi(store);
|
|
2962
|
-
const stateCreator = (set, get) => {
|
|
2963
|
-
return get();
|
|
2964
|
-
};
|
|
2965
|
-
const enhancedCreator = middleware(stateCreator);
|
|
2966
|
-
const enhancedState = enhancedCreator(api.setState, api.getState, api);
|
|
2967
|
-
if (enhancedState && typeof enhancedState === "object") {
|
|
2968
|
-
const currentState = store.getState();
|
|
2969
|
-
const stateOnly = {};
|
|
2970
|
-
for (const key in enhancedState) {
|
|
2971
|
-
const value = enhancedState[key];
|
|
2972
|
-
if (typeof value !== "function") {
|
|
2973
|
-
stateOnly[key] = value;
|
|
2974
|
-
}
|
|
2975
|
-
}
|
|
2976
|
-
if (Object.keys(stateOnly).length > 0) {
|
|
2977
|
-
const hasChanges = Object.keys(stateOnly).some(
|
|
2978
|
-
(key) => currentState[key] !== stateOnly[key]
|
|
2979
|
-
);
|
|
2980
|
-
if (hasChanges) {
|
|
2981
|
-
store.merge(stateOnly);
|
|
2982
|
-
}
|
|
2983
|
-
}
|
|
2984
|
-
}
|
|
2985
|
-
}
|
|
2986
|
-
};
|
|
2987
|
-
}
|
|
2988
|
-
function createWithMiddleware(creator) {
|
|
2989
|
-
const { createStore: createStore2 } = (init_store(), __toCommonJS(store_exports));
|
|
2990
|
-
let currentState = null;
|
|
2991
|
-
let storeRef = null;
|
|
2992
|
-
const set = (partial, replace) => {
|
|
2993
|
-
if (!storeRef) {
|
|
2994
|
-
throw new Error("Store not initialized");
|
|
2995
|
-
}
|
|
2996
|
-
if (typeof partial === "function") {
|
|
2997
|
-
const newPartial = partial(storeRef.getState());
|
|
2998
|
-
if (replace) {
|
|
2999
|
-
storeRef.setState(newPartial);
|
|
3000
|
-
} else {
|
|
3001
|
-
storeRef.merge(newPartial);
|
|
3002
|
-
}
|
|
3003
|
-
} else {
|
|
3004
|
-
if (replace) {
|
|
3005
|
-
storeRef.setState(partial);
|
|
3006
|
-
} else {
|
|
3007
|
-
storeRef.merge(partial);
|
|
3008
|
-
}
|
|
3009
|
-
}
|
|
3010
|
-
};
|
|
3011
|
-
const get = () => {
|
|
3012
|
-
if (storeRef) {
|
|
3013
|
-
return storeRef.getState();
|
|
3014
|
-
}
|
|
3015
|
-
if (currentState) {
|
|
3016
|
-
return currentState;
|
|
3017
|
-
}
|
|
3018
|
-
throw new Error("Store not initialized");
|
|
3019
|
-
};
|
|
3020
|
-
const placeholderApi = {
|
|
3021
|
-
setState: set,
|
|
3022
|
-
getState: get,
|
|
3023
|
-
subscribe: () => () => {
|
|
3024
|
-
}
|
|
3025
|
-
};
|
|
3026
|
-
currentState = creator(set, get, placeholderApi);
|
|
3027
|
-
storeRef = createStore2(currentState);
|
|
3028
|
-
const api = {
|
|
3029
|
-
setState: (partial, replace) => {
|
|
3030
|
-
if (typeof partial === "function") {
|
|
3031
|
-
const newPartial = partial(storeRef.getState());
|
|
3032
|
-
if (replace) {
|
|
3033
|
-
storeRef.setState(newPartial);
|
|
3034
|
-
} else {
|
|
3035
|
-
storeRef.merge(newPartial);
|
|
3036
|
-
}
|
|
3037
|
-
} else {
|
|
3038
|
-
if (replace) {
|
|
3039
|
-
storeRef.setState(partial);
|
|
3040
|
-
} else {
|
|
3041
|
-
storeRef.merge(partial);
|
|
3042
|
-
}
|
|
3043
|
-
}
|
|
3044
|
-
},
|
|
3045
|
-
getState: () => storeRef.getState(),
|
|
3046
|
-
subscribe: (listener) => storeRef.subscribe(listener),
|
|
3047
|
-
destroy: () => storeRef.destroy(),
|
|
3048
|
-
use: (plugin) => {
|
|
3049
|
-
storeRef.use(plugin);
|
|
3050
|
-
return api;
|
|
3051
|
-
}
|
|
3052
|
-
};
|
|
3053
|
-
return api;
|
|
3054
|
-
}
|
|
3055
|
-
function createSimpleMiddleware(name, enhancer) {
|
|
3056
|
-
const middleware = enhancer;
|
|
3057
|
-
Object.defineProperty(middleware, "name", { value: name });
|
|
3058
|
-
return middleware;
|
|
3059
|
-
}
|
|
3060
|
-
function compose(...middlewares) {
|
|
3061
|
-
return (creator) => {
|
|
3062
|
-
return middlewares.reduceRight((acc, middleware) => {
|
|
3063
|
-
return middleware(acc);
|
|
3064
|
-
}, creator);
|
|
3065
|
-
};
|
|
3066
|
-
}
|
|
3067
|
-
|
|
3068
|
-
exports.assertState = assertState;
|
|
3069
|
-
exports.batch = batch;
|
|
3070
|
-
exports.combineComputed = combineComputed;
|
|
3071
|
-
exports.combineEffects = combineEffects;
|
|
3072
|
-
exports.combineSlices = combineSlices;
|
|
3073
|
-
exports.combineValidators = combineValidators;
|
|
3074
|
-
exports.compose = compose;
|
|
3075
|
-
exports.computed = computed;
|
|
3076
|
-
exports.createAsyncValidator = createAsyncValidator;
|
|
3077
|
-
exports.createDebouncedEffect = createDebouncedEffect;
|
|
3078
|
-
exports.createEffect = createEffect;
|
|
3079
|
-
exports.createFederatedComputed = createFederatedComputed;
|
|
3080
|
-
exports.createFederatedSelector = createFederatedSelector;
|
|
3081
|
-
exports.createFederation = createFederation;
|
|
3082
|
-
exports.createFieldValidator = createFieldValidator;
|
|
3083
|
-
exports.createLogger = createLogger;
|
|
3084
|
-
exports.createMockStorage = createMockStorage;
|
|
3085
|
-
exports.createNamespacedSlice = createNamespacedSlice;
|
|
3086
|
-
exports.createSimpleEffect = createSimpleEffect;
|
|
3087
|
-
exports.createSimpleMiddleware = createSimpleMiddleware;
|
|
3088
|
-
exports.createSlice = createSlice;
|
|
3089
|
-
exports.createStorage = createStorage;
|
|
3090
|
-
exports.createStore = createStore;
|
|
3091
|
-
exports.createSubscriber = createSubscriber;
|
|
3092
|
-
exports.createTestStore = createTestStore;
|
|
3093
|
-
exports.createValidator = createValidator;
|
|
3094
|
-
exports.createWithMiddleware = createWithMiddleware;
|
|
3095
|
-
exports.deepClone = deepClone;
|
|
3096
|
-
exports.deepEqual = deepEqual;
|
|
3097
|
-
exports.deepMerge = deepMerge;
|
|
3098
|
-
exports.delay = delay;
|
|
3099
|
-
exports.devtools = devtools;
|
|
3100
|
-
exports.effects = effects;
|
|
3101
|
-
exports.extendStore = extendStore;
|
|
3102
|
-
exports.flushMicrotasks = flushMicrotasks;
|
|
3103
|
-
exports.hasHistory = hasHistory;
|
|
3104
|
-
exports.history = history;
|
|
3105
|
-
exports.identity = identity;
|
|
3106
|
-
exports.immer = immer;
|
|
3107
|
-
exports.isFunction = isFunction;
|
|
3108
|
-
exports.logger = logger;
|
|
3109
|
-
exports.memoizeSelector = memoizeSelector;
|
|
3110
|
-
exports.middlewareCompat = middlewareCompat;
|
|
3111
|
-
exports.mockAction = mockAction;
|
|
3112
|
-
exports.omit = omit;
|
|
3113
|
-
exports.persist = persist;
|
|
3114
|
-
exports.pick = pick;
|
|
3115
|
-
exports.produce = produce;
|
|
3116
|
-
exports.resetSlices = resetSlices;
|
|
3117
|
-
exports.selector = selector;
|
|
3118
|
-
exports.sessionStorage = sessionStorage;
|
|
3119
|
-
exports.shallowEqual = shallowEqual;
|
|
3120
|
-
exports.snapshot = snapshot;
|
|
3121
|
-
exports.spyOnStore = spyOnStore;
|
|
3122
|
-
exports.stateDiff = stateDiff;
|
|
3123
|
-
exports.subscribeOnce = subscribeOnce;
|
|
3124
|
-
exports.subscribeToMany = subscribeToMany;
|
|
3125
|
-
exports.subscribeWithOptions = subscribeWithOptions;
|
|
3126
|
-
exports.sync = sync;
|
|
3127
|
-
exports.toMiddlewareApi = toMiddlewareApi;
|
|
3128
|
-
exports.triggerSync = triggerSync;
|
|
169
|
+
Object.defineProperty(exports, "StoreError", {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
get: function () { return chunkIWT3T2PM_cjs.StoreError; }
|
|
172
|
+
});
|
|
173
|
+
Object.defineProperty(exports, "StoreErrorCode", {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function () { return chunkIWT3T2PM_cjs.StoreErrorCode; }
|
|
176
|
+
});
|
|
177
|
+
Object.defineProperty(exports, "assertState", {
|
|
178
|
+
enumerable: true,
|
|
179
|
+
get: function () { return chunkIWT3T2PM_cjs.assertState; }
|
|
180
|
+
});
|
|
181
|
+
Object.defineProperty(exports, "batch", {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
get: function () { return chunkIWT3T2PM_cjs.batch; }
|
|
184
|
+
});
|
|
185
|
+
Object.defineProperty(exports, "combineComputed", {
|
|
186
|
+
enumerable: true,
|
|
187
|
+
get: function () { return chunkIWT3T2PM_cjs.combineComputed; }
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(exports, "combineEffects", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
get: function () { return chunkIWT3T2PM_cjs.combineEffects; }
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(exports, "combineSlices", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
get: function () { return chunkIWT3T2PM_cjs.combineSlices; }
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(exports, "combineValidators", {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
get: function () { return chunkIWT3T2PM_cjs.combineValidators; }
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(exports, "compose", {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
get: function () { return chunkIWT3T2PM_cjs.compose; }
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(exports, "computed", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
get: function () { return chunkIWT3T2PM_cjs.computed; }
|
|
208
|
+
});
|
|
209
|
+
Object.defineProperty(exports, "createAsyncValidator", {
|
|
210
|
+
enumerable: true,
|
|
211
|
+
get: function () { return chunkIWT3T2PM_cjs.createAsyncValidator; }
|
|
212
|
+
});
|
|
213
|
+
Object.defineProperty(exports, "createDebouncedEffect", {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
get: function () { return chunkIWT3T2PM_cjs.createDebouncedEffect; }
|
|
216
|
+
});
|
|
217
|
+
Object.defineProperty(exports, "createEffect", {
|
|
218
|
+
enumerable: true,
|
|
219
|
+
get: function () { return chunkIWT3T2PM_cjs.createEffect; }
|
|
220
|
+
});
|
|
221
|
+
Object.defineProperty(exports, "createFederatedComputed", {
|
|
222
|
+
enumerable: true,
|
|
223
|
+
get: function () { return chunkIWT3T2PM_cjs.createFederatedComputed; }
|
|
224
|
+
});
|
|
225
|
+
Object.defineProperty(exports, "createFederatedSelector", {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
get: function () { return chunkIWT3T2PM_cjs.createFederatedSelector; }
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(exports, "createFederation", {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
get: function () { return chunkIWT3T2PM_cjs.createFederation; }
|
|
232
|
+
});
|
|
233
|
+
Object.defineProperty(exports, "createFieldValidator", {
|
|
234
|
+
enumerable: true,
|
|
235
|
+
get: function () { return chunkIWT3T2PM_cjs.createFieldValidator; }
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(exports, "createLogger", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
get: function () { return chunkIWT3T2PM_cjs.createLogger; }
|
|
240
|
+
});
|
|
241
|
+
Object.defineProperty(exports, "createMockStorage", {
|
|
242
|
+
enumerable: true,
|
|
243
|
+
get: function () { return chunkIWT3T2PM_cjs.createMockStorage; }
|
|
244
|
+
});
|
|
245
|
+
Object.defineProperty(exports, "createNamespacedSlice", {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
get: function () { return chunkIWT3T2PM_cjs.createNamespacedSlice; }
|
|
248
|
+
});
|
|
249
|
+
Object.defineProperty(exports, "createSimpleEffect", {
|
|
250
|
+
enumerable: true,
|
|
251
|
+
get: function () { return chunkIWT3T2PM_cjs.createSimpleEffect; }
|
|
252
|
+
});
|
|
253
|
+
Object.defineProperty(exports, "createSimpleMiddleware", {
|
|
254
|
+
enumerable: true,
|
|
255
|
+
get: function () { return chunkIWT3T2PM_cjs.createSimpleMiddleware; }
|
|
256
|
+
});
|
|
257
|
+
Object.defineProperty(exports, "createSlice", {
|
|
258
|
+
enumerable: true,
|
|
259
|
+
get: function () { return chunkIWT3T2PM_cjs.createSlice; }
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(exports, "createStorage", {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
get: function () { return chunkIWT3T2PM_cjs.createStorage; }
|
|
264
|
+
});
|
|
265
|
+
Object.defineProperty(exports, "createStore", {
|
|
266
|
+
enumerable: true,
|
|
267
|
+
get: function () { return chunkIWT3T2PM_cjs.createStore; }
|
|
268
|
+
});
|
|
269
|
+
Object.defineProperty(exports, "createSubscriber", {
|
|
270
|
+
enumerable: true,
|
|
271
|
+
get: function () { return chunkIWT3T2PM_cjs.createSubscriber; }
|
|
272
|
+
});
|
|
273
|
+
Object.defineProperty(exports, "createTestStore", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
get: function () { return chunkIWT3T2PM_cjs.createTestStore; }
|
|
276
|
+
});
|
|
277
|
+
Object.defineProperty(exports, "createValidator", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
get: function () { return chunkIWT3T2PM_cjs.createValidator; }
|
|
280
|
+
});
|
|
281
|
+
Object.defineProperty(exports, "createWithMiddleware", {
|
|
282
|
+
enumerable: true,
|
|
283
|
+
get: function () { return chunkIWT3T2PM_cjs.createWithMiddleware; }
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(exports, "deepClone", {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
get: function () { return chunkIWT3T2PM_cjs.deepClone; }
|
|
288
|
+
});
|
|
289
|
+
Object.defineProperty(exports, "deepEqual", {
|
|
290
|
+
enumerable: true,
|
|
291
|
+
get: function () { return chunkIWT3T2PM_cjs.deepEqual; }
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(exports, "deepMerge", {
|
|
294
|
+
enumerable: true,
|
|
295
|
+
get: function () { return chunkIWT3T2PM_cjs.deepMerge; }
|
|
296
|
+
});
|
|
297
|
+
Object.defineProperty(exports, "delay", {
|
|
298
|
+
enumerable: true,
|
|
299
|
+
get: function () { return chunkIWT3T2PM_cjs.delay; }
|
|
300
|
+
});
|
|
301
|
+
Object.defineProperty(exports, "devtools", {
|
|
302
|
+
enumerable: true,
|
|
303
|
+
get: function () { return chunkIWT3T2PM_cjs.devtools; }
|
|
304
|
+
});
|
|
305
|
+
Object.defineProperty(exports, "effects", {
|
|
306
|
+
enumerable: true,
|
|
307
|
+
get: function () { return chunkIWT3T2PM_cjs.effects; }
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(exports, "extendStore", {
|
|
310
|
+
enumerable: true,
|
|
311
|
+
get: function () { return chunkIWT3T2PM_cjs.extendStore; }
|
|
312
|
+
});
|
|
313
|
+
Object.defineProperty(exports, "flushMicrotasks", {
|
|
314
|
+
enumerable: true,
|
|
315
|
+
get: function () { return chunkIWT3T2PM_cjs.flushMicrotasks; }
|
|
316
|
+
});
|
|
317
|
+
Object.defineProperty(exports, "hasHistory", {
|
|
318
|
+
enumerable: true,
|
|
319
|
+
get: function () { return chunkIWT3T2PM_cjs.hasHistory; }
|
|
320
|
+
});
|
|
321
|
+
Object.defineProperty(exports, "history", {
|
|
322
|
+
enumerable: true,
|
|
323
|
+
get: function () { return chunkIWT3T2PM_cjs.history; }
|
|
324
|
+
});
|
|
325
|
+
Object.defineProperty(exports, "identity", {
|
|
326
|
+
enumerable: true,
|
|
327
|
+
get: function () { return chunkIWT3T2PM_cjs.identity; }
|
|
328
|
+
});
|
|
329
|
+
Object.defineProperty(exports, "immer", {
|
|
330
|
+
enumerable: true,
|
|
331
|
+
get: function () { return chunkIWT3T2PM_cjs.immer; }
|
|
332
|
+
});
|
|
333
|
+
Object.defineProperty(exports, "isFunction", {
|
|
334
|
+
enumerable: true,
|
|
335
|
+
get: function () { return chunkIWT3T2PM_cjs.isFunction; }
|
|
336
|
+
});
|
|
337
|
+
Object.defineProperty(exports, "logger", {
|
|
338
|
+
enumerable: true,
|
|
339
|
+
get: function () { return chunkIWT3T2PM_cjs.logger; }
|
|
340
|
+
});
|
|
341
|
+
Object.defineProperty(exports, "memoizeSelector", {
|
|
342
|
+
enumerable: true,
|
|
343
|
+
get: function () { return chunkIWT3T2PM_cjs.memoizeSelector; }
|
|
344
|
+
});
|
|
345
|
+
Object.defineProperty(exports, "middlewareCompat", {
|
|
346
|
+
enumerable: true,
|
|
347
|
+
get: function () { return chunkIWT3T2PM_cjs.middlewareCompat; }
|
|
348
|
+
});
|
|
349
|
+
Object.defineProperty(exports, "mockAction", {
|
|
350
|
+
enumerable: true,
|
|
351
|
+
get: function () { return chunkIWT3T2PM_cjs.mockAction; }
|
|
352
|
+
});
|
|
353
|
+
Object.defineProperty(exports, "omit", {
|
|
354
|
+
enumerable: true,
|
|
355
|
+
get: function () { return chunkIWT3T2PM_cjs.omit; }
|
|
356
|
+
});
|
|
357
|
+
Object.defineProperty(exports, "persist", {
|
|
358
|
+
enumerable: true,
|
|
359
|
+
get: function () { return chunkIWT3T2PM_cjs.persist; }
|
|
360
|
+
});
|
|
361
|
+
Object.defineProperty(exports, "pick", {
|
|
362
|
+
enumerable: true,
|
|
363
|
+
get: function () { return chunkIWT3T2PM_cjs.pick; }
|
|
364
|
+
});
|
|
365
|
+
Object.defineProperty(exports, "produce", {
|
|
366
|
+
enumerable: true,
|
|
367
|
+
get: function () { return chunkIWT3T2PM_cjs.produce; }
|
|
368
|
+
});
|
|
369
|
+
Object.defineProperty(exports, "resetSlices", {
|
|
370
|
+
enumerable: true,
|
|
371
|
+
get: function () { return chunkIWT3T2PM_cjs.resetSlices; }
|
|
372
|
+
});
|
|
373
|
+
Object.defineProperty(exports, "selector", {
|
|
374
|
+
enumerable: true,
|
|
375
|
+
get: function () { return chunkIWT3T2PM_cjs.selector; }
|
|
376
|
+
});
|
|
377
|
+
Object.defineProperty(exports, "sessionStorage", {
|
|
378
|
+
enumerable: true,
|
|
379
|
+
get: function () { return chunkIWT3T2PM_cjs.sessionStorage; }
|
|
380
|
+
});
|
|
381
|
+
Object.defineProperty(exports, "shallowEqual", {
|
|
382
|
+
enumerable: true,
|
|
383
|
+
get: function () { return chunkIWT3T2PM_cjs.shallowEqual; }
|
|
384
|
+
});
|
|
385
|
+
Object.defineProperty(exports, "snapshot", {
|
|
386
|
+
enumerable: true,
|
|
387
|
+
get: function () { return chunkIWT3T2PM_cjs.snapshot; }
|
|
388
|
+
});
|
|
389
|
+
Object.defineProperty(exports, "spyOnStore", {
|
|
390
|
+
enumerable: true,
|
|
391
|
+
get: function () { return chunkIWT3T2PM_cjs.spyOnStore; }
|
|
392
|
+
});
|
|
393
|
+
Object.defineProperty(exports, "stateDiff", {
|
|
394
|
+
enumerable: true,
|
|
395
|
+
get: function () { return chunkIWT3T2PM_cjs.stateDiff; }
|
|
396
|
+
});
|
|
397
|
+
Object.defineProperty(exports, "subscribeOnce", {
|
|
398
|
+
enumerable: true,
|
|
399
|
+
get: function () { return chunkIWT3T2PM_cjs.subscribeOnce; }
|
|
400
|
+
});
|
|
401
|
+
Object.defineProperty(exports, "subscribeToMany", {
|
|
402
|
+
enumerable: true,
|
|
403
|
+
get: function () { return chunkIWT3T2PM_cjs.subscribeToMany; }
|
|
404
|
+
});
|
|
405
|
+
Object.defineProperty(exports, "subscribeWithOptions", {
|
|
406
|
+
enumerable: true,
|
|
407
|
+
get: function () { return chunkIWT3T2PM_cjs.subscribeWithOptions; }
|
|
408
|
+
});
|
|
409
|
+
Object.defineProperty(exports, "sync", {
|
|
410
|
+
enumerable: true,
|
|
411
|
+
get: function () { return chunkIWT3T2PM_cjs.sync; }
|
|
412
|
+
});
|
|
413
|
+
Object.defineProperty(exports, "toMiddlewareApi", {
|
|
414
|
+
enumerable: true,
|
|
415
|
+
get: function () { return chunkIWT3T2PM_cjs.toMiddlewareApi; }
|
|
416
|
+
});
|
|
417
|
+
Object.defineProperty(exports, "triggerSync", {
|
|
418
|
+
enumerable: true,
|
|
419
|
+
get: function () { return chunkIWT3T2PM_cjs.triggerSync; }
|
|
420
|
+
});
|
|
421
|
+
Object.defineProperty(exports, "validate", {
|
|
422
|
+
enumerable: true,
|
|
423
|
+
get: function () { return chunkIWT3T2PM_cjs.validate; }
|
|
424
|
+
});
|
|
425
|
+
Object.defineProperty(exports, "waitForFederated", {
|
|
426
|
+
enumerable: true,
|
|
427
|
+
get: function () { return chunkIWT3T2PM_cjs.waitForFederated; }
|
|
428
|
+
});
|
|
3129
429
|
exports.useAction = useAction;
|
|
3130
430
|
exports.useCreateStore = useCreateStore;
|
|
3131
431
|
exports.useSetState = useSetState;
|
|
@@ -3134,7 +434,5 @@ exports.useStore = useStore;
|
|
|
3134
434
|
exports.useStoreActions = useStoreActions;
|
|
3135
435
|
exports.useStoreSelector = useStoreSelector;
|
|
3136
436
|
exports.useTransientSubscribe = useTransientSubscribe;
|
|
3137
|
-
exports.validate = validate;
|
|
3138
|
-
exports.waitForFederated = waitForFederated;
|
|
3139
437
|
//# sourceMappingURL=index.cjs.map
|
|
3140
438
|
//# sourceMappingURL=index.cjs.map
|