cross-state 0.6.10 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/cjs/hash.cjs +0 -682
  2. package/dist/cjs/hash.cjs.map +1 -1
  3. package/dist/cjs/immer/index.cjs +6 -0
  4. package/dist/cjs/immer/index.cjs.map +1 -0
  5. package/dist/cjs/immer/register.cjs +6 -0
  6. package/dist/cjs/immer/register.cjs.map +1 -0
  7. package/dist/cjs/immerMethods.cjs +23 -0
  8. package/dist/cjs/immerMethods.cjs.map +1 -0
  9. package/dist/cjs/index.cjs +387 -278
  10. package/dist/cjs/index.cjs.map +1 -1
  11. package/dist/cjs/react/index.cjs +54 -0
  12. package/dist/cjs/react/index.cjs.map +1 -0
  13. package/dist/cjs/react/register.cjs +30 -0
  14. package/dist/cjs/react/register.cjs.map +1 -0
  15. package/dist/cjs/scope.cjs +399 -0
  16. package/dist/cjs/scope.cjs.map +1 -0
  17. package/dist/cjs/scope2.cjs +513 -0
  18. package/dist/cjs/scope2.cjs.map +1 -0
  19. package/dist/cjs/store.cjs +798 -0
  20. package/dist/cjs/store.cjs.map +1 -0
  21. package/dist/es/hash.mjs +1 -683
  22. package/dist/es/hash.mjs.map +1 -1
  23. package/dist/es/immer/index.mjs +6 -0
  24. package/dist/es/immer/index.mjs.map +1 -0
  25. package/dist/es/immer/register.mjs +5 -0
  26. package/dist/es/immer/register.mjs.map +1 -0
  27. package/dist/es/immerMethods.mjs +24 -0
  28. package/dist/es/immerMethods.mjs.map +1 -0
  29. package/dist/es/index.mjs +383 -273
  30. package/dist/es/index.mjs.map +1 -1
  31. package/dist/es/react/index.mjs +55 -0
  32. package/dist/es/react/index.mjs.map +1 -0
  33. package/dist/es/react/register.mjs +29 -0
  34. package/dist/es/react/register.mjs.map +1 -0
  35. package/dist/es/scope.mjs +400 -0
  36. package/dist/es/scope.mjs.map +1 -0
  37. package/dist/es/scope2.mjs +514 -0
  38. package/dist/es/scope2.mjs.map +1 -0
  39. package/dist/es/store.mjs +799 -0
  40. package/dist/es/store.mjs.map +1 -0
  41. package/dist/types/core/cache.d.ts +7 -2
  42. package/dist/types/core/commonTypes.d.ts +8 -0
  43. package/dist/types/core/index.d.ts +6 -6
  44. package/dist/types/core/resourceGroup.d.ts +2 -2
  45. package/dist/types/core/scope.d.ts +5 -0
  46. package/dist/types/core/store.d.ts +8 -10
  47. package/dist/types/core/subscriptionCache.d.ts +51 -0
  48. package/dist/types/core/urlStore.d.ts +26 -0
  49. package/dist/types/immer/immerMethods.d.ts +10 -0
  50. package/dist/types/immer/index.d.ts +1 -1
  51. package/dist/types/immer/register.d.ts +7 -0
  52. package/dist/types/index.d.ts +3 -1
  53. package/dist/types/lib/calculationHelper.d.ts +15 -10
  54. package/dist/types/lib/equals.d.ts +3 -3
  55. package/dist/types/lib/path.d.ts +3 -3
  56. package/dist/types/lib/promiseWithState.d.ts +9 -0
  57. package/dist/types/lib/standardMethods.d.ts +2 -1
  58. package/dist/types/lib/trackingProxy.d.ts +2 -1
  59. package/dist/types/lib/typeHelpers.d.ts +3 -1
  60. package/dist/types/lib/updateHelpers.d.ts +1 -0
  61. package/dist/types/react/index.d.ts +3 -1
  62. package/dist/types/react/reactMethods.d.ts +9 -0
  63. package/dist/types/react/register.d.ts +29 -0
  64. package/dist/types/react/scope.d.ts +16 -0
  65. package/dist/types/react/useCache.d.ts +2 -1
  66. package/dist/types/react/useDecoupledState.d.ts +7 -0
  67. package/dist/types/react/useProp.d.ts +1 -2
  68. package/package.json +105 -27
  69. package/dist/cjs/immer.cjs +0 -10
  70. package/dist/cjs/immer.cjs.map +0 -1
  71. package/dist/cjs/react.cjs +0 -292
  72. package/dist/cjs/react.cjs.map +0 -1
  73. package/dist/es/immer.mjs +0 -10
  74. package/dist/es/immer.mjs.map +0 -1
  75. package/dist/es/react.mjs +0 -292
  76. package/dist/es/react.mjs.map +0 -1
  77. package/dist/types/core/storeScope.d.ts +0 -4
  78. package/dist/types/immer/immerActions.d.ts +0 -5
  79. package/dist/types/react/storeScope.d.ts +0 -12
package/dist/cjs/hash.cjs CHANGED
@@ -1,677 +1,4 @@
1
1
  "use strict";
2
- function calcDuration(t) {
3
- if (typeof t === "number")
4
- return t;
5
- return (t.milliseconds ?? 0) + (t.seconds ?? 0) * 1e3 + (t.minutes ?? 0) * 60 * 1e3 + (t.hours ?? 0) * 60 * 60 * 1e3 + (t.days ?? 0) * 24 * 60 * 60 * 1e3;
6
- }
7
- function queue() {
8
- const q = [];
9
- const completionListeners = /* @__PURE__ */ new Set();
10
- let active = false;
11
- const notify = () => {
12
- for (const listener of completionListeners) {
13
- listener();
14
- }
15
- completionListeners.clear();
16
- };
17
- const run = async () => {
18
- if (!active) {
19
- active = true;
20
- let next;
21
- while (next = q.shift()) {
22
- try {
23
- let result = next.action();
24
- if (result instanceof Promise) {
25
- result = await result;
26
- }
27
- next.resolve(result);
28
- } catch (error) {
29
- next.reject(error);
30
- }
31
- }
32
- active = false;
33
- notify();
34
- }
35
- };
36
- return Object.assign(
37
- (action, ref) => {
38
- return new Promise((resolve, reject) => {
39
- q.push({ action, resolve, reject, ref });
40
- run();
41
- });
42
- },
43
- {
44
- clear() {
45
- q.length = 0;
46
- },
47
- whenDone() {
48
- if (!active) {
49
- return Promise.resolve();
50
- }
51
- return new Promise((resolve) => {
52
- completionListeners.add(resolve);
53
- });
54
- },
55
- get size() {
56
- return q.length;
57
- },
58
- getRefs() {
59
- return q.map((item) => item.ref).filter((x) => x !== void 0);
60
- }
61
- }
62
- );
63
- }
64
- const ProxyKeys = [
65
- "get",
66
- "getOwnPropertyDescriptor",
67
- "getPrototypeOf",
68
- "has",
69
- "isExtensible",
70
- "ownKeys"
71
- ];
72
- function isPlainObject(value) {
73
- return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
74
- }
75
- function trackingProxy(value) {
76
- if (!isPlainObject(value) && !Array.isArray(value)) {
77
- return [value, (other) => other === value];
78
- }
79
- const deps = new Array();
80
- const proxy = new Proxy(
81
- value,
82
- Object.fromEntries(
83
- ProxyKeys.map((key) => [
84
- key,
85
- (currentValue, ...args) => {
86
- const function_ = Reflect[key];
87
- const [proxiedValue, equals] = trackingProxy(function_(currentValue, ...args));
88
- deps.push((otherValue) => {
89
- if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {
90
- return false;
91
- }
92
- return equals(function_(otherValue, ...args));
93
- });
94
- return proxiedValue;
95
- }
96
- ])
97
- )
98
- );
99
- return [proxy, (other) => !!other && deps.every((equals) => equals(other))];
100
- }
101
- class CalculationHelper {
102
- constructor(options) {
103
- this.options = options;
104
- options.addEffect(() => {
105
- if (this.current) {
106
- this.current.check();
107
- } else {
108
- this.execute();
109
- }
110
- });
111
- }
112
- execute() {
113
- this.stop();
114
- const { calculate, addEffect, getValue, setValue, setError, onInvalidate } = this.options;
115
- const checks = new Array();
116
- const deps = /* @__PURE__ */ new Map();
117
- const q = queue();
118
- let isActive = false;
119
- let isCancled = false;
120
- const cancelEffect = addEffect(() => {
121
- isActive = true;
122
- for (const dep of deps.values()) {
123
- dep.on();
124
- }
125
- return () => {
126
- isActive = false;
127
- for (const dep of deps.values()) {
128
- dep.off();
129
- }
130
- };
131
- });
132
- const cancel = () => {
133
- isCancled = true;
134
- cancelSubscription == null ? void 0 : cancelSubscription();
135
- cancelEffect();
136
- delete this.current;
137
- };
138
- const checkAll = () => {
139
- if (!checks.every((check) => check())) {
140
- cancel();
141
- onInvalidate == null ? void 0 : onInvalidate();
142
- }
143
- };
144
- const invalidateDependencies = () => {
145
- for (const dep of deps.values()) {
146
- dep.invalidate();
147
- }
148
- };
149
- const use = (store, { disableProxy } = {}) => {
150
- if (isCancled) {
151
- return store.get();
152
- }
153
- let value = store.get();
154
- let equals = (newValue) => {
155
- return newValue === value;
156
- };
157
- if (!disableProxy) {
158
- [value, equals] = trackingProxy(value);
159
- }
160
- let sub;
161
- const dep = {
162
- on() {
163
- this.off();
164
- sub = store.sub(checkAll, { runNow: false });
165
- },
166
- off() {
167
- sub == null ? void 0 : sub();
168
- sub = void 0;
169
- },
170
- invalidate() {
171
- if ("invalidate" in store && store.invalidate instanceof Function) {
172
- store.invalidate();
173
- }
174
- }
175
- };
176
- if (isActive) {
177
- dep.on();
178
- }
179
- checks.push(() => equals(store.get()));
180
- deps.set(store, dep);
181
- return value;
182
- };
183
- const updateValue = (update) => q(async () => {
184
- if (isCancled) {
185
- return;
186
- }
187
- if (update instanceof Function) {
188
- try {
189
- update = update(getValue == null ? void 0 : getValue());
190
- } catch (error) {
191
- setError == null ? void 0 : setError(error);
192
- return;
193
- }
194
- }
195
- if (update instanceof Promise) {
196
- try {
197
- update = await update;
198
- } catch (error) {
199
- if (!isCancled) {
200
- setError == null ? void 0 : setError(error);
201
- }
202
- return;
203
- }
204
- }
205
- if (!isCancled) {
206
- setValue == null ? void 0 : setValue(update);
207
- }
208
- });
209
- const updateError = (error) => q(() => {
210
- if (!isCancled) {
211
- setError == null ? void 0 : setError(error);
212
- }
213
- });
214
- let cancelSubscription;
215
- try {
216
- cancelSubscription = calculate({ use, updateValue, updateError });
217
- } catch (error) {
218
- setError == null ? void 0 : setError(error);
219
- }
220
- this.current = { cancel, check: checkAll, invalidateDependencies };
221
- }
222
- stop() {
223
- var _a;
224
- (_a = this.current) == null ? void 0 : _a.cancel();
225
- }
226
- check() {
227
- var _a;
228
- (_a = this.current) == null ? void 0 : _a.check();
229
- }
230
- invalidateDependencies() {
231
- var _a;
232
- (_a = this.current) == null ? void 0 : _a.invalidateDependencies();
233
- }
234
- }
235
- class Callable extends Function {
236
- constructor(_call) {
237
- super("...args", "return this._call(...args)");
238
- this._call = _call;
239
- return this.bind(this);
240
- }
241
- }
242
- function debounce(action, options) {
243
- const wait = typeof options === "object" && "wait" in options ? calcDuration(options.wait) : calcDuration(options);
244
- const maxWait = typeof options === "object" && "maxWait" in options && options.maxWait !== void 0 ? calcDuration(options.maxWait) : void 0;
245
- let timeout;
246
- let timeoutStarted;
247
- return (...args) => {
248
- const now = Date.now();
249
- timeoutStarted ?? (timeoutStarted = now);
250
- const deadline = Math.min(
251
- //
252
- now + wait,
253
- timeoutStarted + (maxWait ?? Number.POSITIVE_INFINITY)
254
- );
255
- if (timeout !== void 0) {
256
- clearTimeout(timeout);
257
- }
258
- timeout = setTimeout(() => {
259
- timeout = void 0;
260
- timeoutStarted = void 0;
261
- action(...args);
262
- }, deadline - now);
263
- };
264
- }
265
- function defaultEquals(a, b) {
266
- return a === b;
267
- }
268
- function forwardError(error) {
269
- setTimeout(() => {
270
- throw error;
271
- });
272
- }
273
- function flatClone(object) {
274
- if (object instanceof Map) {
275
- return new Map(object);
276
- }
277
- if (object instanceof Set) {
278
- return new Set(object);
279
- }
280
- if (Array.isArray(object)) {
281
- return [...object];
282
- }
283
- if (object instanceof Object) {
284
- return { ...object };
285
- }
286
- return object;
287
- }
288
- function castArrayPath(path) {
289
- if (Array.isArray(path)) {
290
- return path;
291
- }
292
- if (path === "") {
293
- return [];
294
- }
295
- return path.split(".");
296
- }
297
- function get(object, path) {
298
- const _path = castArrayPath(path);
299
- const [first, ...rest] = _path;
300
- if (first === void 0 || !object) {
301
- return object;
302
- }
303
- if (object instanceof Map) {
304
- return get(object.get(first), rest);
305
- }
306
- if (object instanceof Set) {
307
- return get(Array.from(object)[Number(first)], rest);
308
- }
309
- if (object instanceof Object) {
310
- return get(object[first], rest);
311
- }
312
- throw new Error(`Could not get ${path} of ${object}`);
313
- }
314
- function set(object, path, value, rootPath = path) {
315
- const _path = castArrayPath(path);
316
- const [first, ...rest] = _path;
317
- if (first === void 0) {
318
- return value;
319
- }
320
- const updateChild = (child) => {
321
- if (!child && rest.length > 0) {
322
- const _rootPath = castArrayPath(rootPath);
323
- const prefix = _rootPath.slice(0, -rest.length);
324
- throw new Error(`Cannot set ${rootPath} because ${prefix.join(".")} is ${child}`);
325
- }
326
- return set(child, rest, value, rootPath);
327
- };
328
- if (object instanceof Map) {
329
- const copy = flatClone(object);
330
- const child = copy.get(first);
331
- copy.set(first, updateChild(child));
332
- return copy;
333
- }
334
- if (object instanceof Set) {
335
- const copy = [...object];
336
- const child = copy[Number(first)];
337
- copy[Number(first)] = updateChild(child);
338
- return new Set(copy);
339
- }
340
- if (object instanceof Object) {
341
- const copy = flatClone(object);
342
- copy[first] = updateChild(copy[first]);
343
- return copy;
344
- }
345
- throw new Error(`Could not set ${path} of ${object}`);
346
- }
347
- function makeSelector(selector) {
348
- if (!selector) {
349
- return (x) => x;
350
- }
351
- if (selector instanceof Function) {
352
- return selector;
353
- }
354
- return (x) => get(x, selector);
355
- }
356
- function createArrayAction(prop) {
357
- return function arrayAction(...args) {
358
- const newArray = this.get().slice();
359
- const result = newArray[prop](...args);
360
- this.set(newArray);
361
- return result;
362
- };
363
- }
364
- const arrayMethods = {
365
- splice: /* @__PURE__ */ createArrayAction("splice"),
366
- push: /* @__PURE__ */ createArrayAction("push"),
367
- pop: /* @__PURE__ */ createArrayAction("pop"),
368
- shift: /* @__PURE__ */ createArrayAction("shift"),
369
- unshift: /* @__PURE__ */ createArrayAction("unshift"),
370
- reverse: /* @__PURE__ */ createArrayAction("reverse"),
371
- sort: /* @__PURE__ */ createArrayAction("sort")
372
- };
373
- const recordMethods = {
374
- delete(key) {
375
- const copy = { ...this.get() };
376
- delete copy[key];
377
- this.set(copy);
378
- },
379
- clear() {
380
- this.set({});
381
- }
382
- };
383
- const mapMethods = {
384
- delete(key) {
385
- const newMap = new Map(this.get());
386
- const result = newMap.delete(key);
387
- this.set(newMap);
388
- return result;
389
- },
390
- clear() {
391
- this.set(/* @__PURE__ */ new Map());
392
- }
393
- };
394
- const setMethods = {
395
- add(value) {
396
- const newSet = new Set(this.get());
397
- newSet.add(value);
398
- this.set(newSet);
399
- },
400
- delete(value) {
401
- const newSet = new Set(this.get());
402
- newSet.delete(value);
403
- this.set(newSet);
404
- },
405
- clear() {
406
- this.set(/* @__PURE__ */ new Set());
407
- }
408
- };
409
- function throttle(action, duration) {
410
- const ms = calcDuration(duration);
411
- let t = 0;
412
- let timeout;
413
- return (...args) => {
414
- if (timeout !== void 0) {
415
- clearTimeout(timeout);
416
- }
417
- const dt = t + ms - Date.now();
418
- if (dt <= 0) {
419
- action(...args);
420
- t = Date.now();
421
- return;
422
- }
423
- timeout = setTimeout(() => {
424
- action(...args);
425
- t = Date.now();
426
- }, dt);
427
- };
428
- }
429
- function noop() {
430
- return void 0;
431
- }
432
- class Store extends Callable {
433
- constructor(getter, options = {}, derivedFrom, _call = () => void 0) {
434
- super(_call);
435
- this.getter = getter;
436
- this.options = options;
437
- this.derivedFrom = derivedFrom;
438
- this._call = _call;
439
- this.listeners = /* @__PURE__ */ new Map();
440
- this.effects = /* @__PURE__ */ new Map();
441
- this.notifyId = {};
442
- this.calculationHelper = new CalculationHelper({
443
- calculate: ({ use }) => {
444
- if (this.getter instanceof Function) {
445
- const value = this.getter.apply({ use }, [{ use }]);
446
- this._value = { v: value };
447
- this.notify();
448
- }
449
- },
450
- addEffect: this.addEffect.bind(this),
451
- onInvalidate: this.reset.bind(this)
452
- });
453
- this.get = this.get.bind(this);
454
- this.set = this.set.bind(this);
455
- this.sub = this.sub.bind(this);
456
- this.once = this.once.bind(this);
457
- this.map = this.map.bind(this);
458
- this.addEffect = this.addEffect.bind(this);
459
- this.isActive = this.isActive.bind(this);
460
- if (!(getter instanceof Function)) {
461
- this._value = { v: getter };
462
- }
463
- }
464
- get() {
465
- this.calculationHelper.check();
466
- if (!this._value) {
467
- this.calculationHelper.execute();
468
- return this.get();
469
- }
470
- return this._value.v;
471
- }
472
- set(...args) {
473
- const path = args.length > 1 ? args[0] : [];
474
- let update = args.length > 1 ? args[1] : args[0];
475
- if (update instanceof Function) {
476
- const before = this.get();
477
- const valueBefore = get(before, path);
478
- const valueAfter = update(valueBefore);
479
- update = set(before, path, valueAfter);
480
- } else if (path.length > 0) {
481
- update = set(this.get(), path, update);
482
- }
483
- if (this.derivedFrom && this.derivedFrom.selectors.every((selector) => typeof selector === "string")) {
484
- const derivationPath = this.derivedFrom.selectors.join(".");
485
- this.derivedFrom.store.set((before) => set(before, derivationPath, update));
486
- return;
487
- }
488
- if (this.derivedFrom) {
489
- throw new TypeError(
490
- "Can only updated computed stores that are derived from other stores using string selectors"
491
- );
492
- }
493
- this._value = { v: update };
494
- this.notify();
495
- }
496
- reset() {
497
- this._value = void 0;
498
- if (this.isActive()) {
499
- this.calculationHelper.execute();
500
- }
501
- }
502
- sub(listener, options) {
503
- var _a;
504
- const {
505
- passive,
506
- runNow = true,
507
- throttle: throttleOption,
508
- debounce: debounceOption,
509
- equals = defaultEquals
510
- } = options ?? {};
511
- let compareToValue = (_a = this._value) == null ? void 0 : _a.v;
512
- let previousValue;
513
- let hasRun = false;
514
- let innerListener = (force) => {
515
- if (!this._value) {
516
- return;
517
- }
518
- const value = this._value.v;
519
- if (!force && equals(value, compareToValue)) {
520
- return;
521
- }
522
- compareToValue = value;
523
- const _previousValue = previousValue;
524
- previousValue = value;
525
- hasRun = true;
526
- try {
527
- listener(value, _previousValue);
528
- } catch (error) {
529
- forwardError(error);
530
- }
531
- };
532
- if (throttleOption) {
533
- innerListener = throttle(innerListener, throttleOption);
534
- } else if (debounceOption) {
535
- innerListener = debounce(innerListener, debounceOption);
536
- }
537
- this.listeners.set(innerListener, !passive);
538
- if (!passive) {
539
- this.onSubscribe();
540
- }
541
- if (runNow && !hasRun) {
542
- innerListener(true);
543
- }
544
- return () => {
545
- this.listeners.delete(innerListener);
546
- if (!passive) {
547
- this.onUnsubscribe();
548
- }
549
- };
550
- }
551
- once(condition = (value) => !!value) {
552
- return new Promise((resolve) => {
553
- let stopped = false;
554
- const cancel = this.sub(
555
- (value) => {
556
- if (stopped || condition && !condition(value)) {
557
- return;
558
- }
559
- resolve(value);
560
- stopped = true;
561
- setTimeout(() => cancel());
562
- },
563
- {
564
- runNow: !!condition
565
- }
566
- );
567
- });
568
- }
569
- map(_selector, options) {
570
- const selector = makeSelector(_selector);
571
- const derivedFrom = {
572
- store: this.derivedFrom ? this.derivedFrom.store : this,
573
- selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector]
574
- };
575
- return new Store(
576
- ({ use }) => {
577
- return selector(use(this, options));
578
- },
579
- this.options,
580
- derivedFrom
581
- );
582
- }
583
- /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.
584
- * @param effect
585
- * If there is already a subscriber, the effect will be executed immediately.
586
- * Otherweise it will be executed as soon as the first subscription is created.
587
- * Every time all subscriptions are removed and the first is created again, the effect will be executed again.
588
- * @param retain
589
- * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.
590
- * @returns
591
- * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.
592
- */
593
- addEffect(effect, retain) {
594
- this.effects.set(effect, {
595
- handle: this.isActive() ? effect() ?? noop : void 0,
596
- retain: retain !== void 0 ? calcDuration(retain) : void 0
597
- });
598
- return () => {
599
- const { handle, timeout } = this.effects.get(effect) ?? {};
600
- handle == null ? void 0 : handle();
601
- if (timeout !== void 0) {
602
- clearTimeout(timeout);
603
- }
604
- this.effects.delete(effect);
605
- };
606
- }
607
- /** Return whether the store is currently active, which means whether it has at least one subscriber. */
608
- isActive() {
609
- return [...this.listeners.values()].some(Boolean);
610
- }
611
- onSubscribe() {
612
- if ([...this.listeners.values()].filter(Boolean).length > 1)
613
- return;
614
- for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {
615
- if (timeout !== void 0) {
616
- clearTimeout(timeout);
617
- }
618
- this.effects.set(effect, {
619
- handle: handle ?? effect() ?? noop,
620
- retain,
621
- timeout: void 0
622
- });
623
- }
624
- }
625
- onUnsubscribe() {
626
- if ([...this.listeners.values()].some(Boolean))
627
- return;
628
- for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {
629
- if (!retain) {
630
- handle == null ? void 0 : handle();
631
- }
632
- if (timeout !== void 0) {
633
- clearTimeout(timeout);
634
- }
635
- this.effects.set(effect, {
636
- handle: retain ? handle : void 0,
637
- retain,
638
- timeout: retain && handle ? setTimeout(handle, retain) : void 0
639
- });
640
- }
641
- }
642
- notify() {
643
- const n = {};
644
- this.notifyId = n;
645
- const snapshot = [...this.listeners.keys()];
646
- for (const listener of snapshot) {
647
- listener();
648
- if (n !== this.notifyId)
649
- break;
650
- }
651
- }
652
- }
653
- const defaultOptions = {};
654
- function create(initialState, options) {
655
- const store = new Store(initialState, options);
656
- if (initialState instanceof Function) {
657
- return store;
658
- }
659
- let methods = options == null ? void 0 : options.methods;
660
- if (initialState instanceof Map) {
661
- methods = { ...mapMethods, ...methods };
662
- } else if (initialState instanceof Set) {
663
- methods = { ...setMethods, ...methods };
664
- } else if (Array.isArray(initialState)) {
665
- methods = { ...arrayMethods, ...methods };
666
- } else if (initialState instanceof Object) {
667
- methods = { ...recordMethods, ...methods };
668
- }
669
- const boundMethods = Object.fromEntries(
670
- Object.entries(methods ?? {}).filter(([name]) => !(name in store)).map(([name, action]) => [name, action.bind(store)])
671
- );
672
- return Object.assign(store, boundMethods);
673
- }
674
- const createStore = /* @__PURE__ */ Object.assign(create, { defaultOptions });
675
2
  function hash(value) {
676
3
  if (value instanceof Set) {
677
4
  return `s[${[...value].map(hash).sort().join(",")}]`;
@@ -687,14 +14,5 @@ function hash(value) {
687
14
  }
688
15
  return JSON.stringify(value);
689
16
  }
690
- exports.Store = Store;
691
- exports.arrayMethods = arrayMethods;
692
- exports.calcDuration = calcDuration;
693
- exports.createStore = createStore;
694
17
  exports.hash = hash;
695
- exports.makeSelector = makeSelector;
696
- exports.mapMethods = mapMethods;
697
- exports.recordMethods = recordMethods;
698
- exports.setMethods = setMethods;
699
- exports.trackingProxy = trackingProxy;
700
18
  //# sourceMappingURL=hash.cjs.map