r-state-tree 0.3.1 → 0.4.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.
@@ -1,6 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const signalsCore = require("@preact/signals-core");
4
+ var lib = {};
5
+ var hasRequiredLib;
6
+ function requireLib() {
7
+ if (hasRequiredLib) return lib;
8
+ hasRequiredLib = 1;
9
+ Object.defineProperty(lib, "__esModule", { value: true });
10
+ Symbol.metadata ??= Symbol("Symbol.metadata");
11
+ return lib;
12
+ }
13
+ requireLib();
14
+ var CommonCfgTypes = /* @__PURE__ */ ((CommonCfgTypes2) => {
15
+ CommonCfgTypes2["child"] = "child";
16
+ return CommonCfgTypes2;
17
+ })(CommonCfgTypes || {});
18
+ var ModelCfgTypes = /* @__PURE__ */ ((ModelCfgTypes2) => {
19
+ ModelCfgTypes2["state"] = "state";
20
+ ModelCfgTypes2["id"] = "id";
21
+ ModelCfgTypes2["modelRef"] = "modelRef";
22
+ return ModelCfgTypes2;
23
+ })(ModelCfgTypes || {});
24
+ var StoreCfgTypes = /* @__PURE__ */ ((StoreCfgTypes2) => {
25
+ StoreCfgTypes2["model"] = "model";
26
+ return StoreCfgTypes2;
27
+ })(StoreCfgTypes || {});
28
+ var ObservableCfgTypes = /* @__PURE__ */ ((ObservableCfgTypes2) => {
29
+ ObservableCfgTypes2["observable"] = "observable";
30
+ ObservableCfgTypes2["computed"] = "computed";
31
+ return ObservableCfgTypes2;
32
+ })(ObservableCfgTypes || {});
33
+ const childType = Object.assign(
34
+ function(childType2) {
35
+ return { type: "child", childType: childType2 };
36
+ },
37
+ {
38
+ type: "child"
39
+ /* child */
40
+ }
41
+ );
42
+ const stateType = {
43
+ type: "state"
44
+ /* state */
45
+ };
46
+ const modelRefType = Object.assign(
47
+ function(childType2) {
48
+ return { type: "modelRef", childType: childType2 };
49
+ },
50
+ {
51
+ type: "modelRef"
52
+ /* modelRef */
53
+ }
54
+ );
55
+ const idType = {
56
+ type: "id"
57
+ /* id */
58
+ };
59
+ const modelType = {
60
+ type: "model"
61
+ /* model */
62
+ };
4
63
  function isNonPrimitive(val) {
5
64
  return val != null && (typeof val === "object" || typeof val === "function");
6
65
  }
@@ -8,15 +67,34 @@ function isPropertyKey(val) {
8
67
  return typeof val === "string" || typeof val === "number" || typeof val === "symbol";
9
68
  }
10
69
  function getPropertyType(key, obj) {
70
+ const hasMetadata = obj.constructor[Symbol.metadata] !== void 0;
11
71
  const descriptor = getPropertyDescriptor$1(obj, key);
12
- if (descriptor) {
13
- if (typeof descriptor.get === "function" || typeof descriptor.set === "function") {
72
+ if (descriptor?.value && typeof descriptor.value === "function") {
73
+ return "action";
74
+ }
75
+ const isGetter = descriptor && (typeof descriptor.get === "function" || typeof descriptor.set === "function");
76
+ if (!hasMetadata) {
77
+ if (isGetter) {
14
78
  return "computed";
15
- } else if (typeof descriptor.value === "function") {
16
- return "action";
79
+ }
80
+ return "observable";
81
+ }
82
+ const metadata = obj.constructor[Symbol.metadata];
83
+ if (metadata && metadata[key]) {
84
+ const config = metadata[key];
85
+ switch (config.type) {
86
+ case ObservableCfgTypes.computed:
87
+ return "computed";
88
+ case ModelCfgTypes.state:
89
+ case ObservableCfgTypes.observable:
90
+ case ModelCfgTypes.id:
91
+ case ModelCfgTypes.modelRef:
92
+ case CommonCfgTypes.child:
93
+ case StoreCfgTypes.model:
94
+ return "observable";
17
95
  }
18
96
  }
19
- return "observable";
97
+ return null;
20
98
  }
21
99
  function getPropertyDescriptor$1(obj, key) {
22
100
  let node = obj;
@@ -38,9 +116,15 @@ function resolveNode(node) {
38
116
  return node.node ?? node;
39
117
  }
40
118
  let circularRefSet = null;
41
- const _Administration = class _Administration {
119
+ class Administration {
120
+ static proxyTraps = {};
121
+ proxy;
122
+ source;
123
+ atom;
124
+ valuesMap;
125
+ isObserved = false;
126
+ forceObservedAtoms;
42
127
  constructor(source2) {
43
- this.isObserved = false;
44
128
  this.atom = createObservedAtom();
45
129
  this.source = source2;
46
130
  this.proxy = new Proxy(
@@ -87,12 +171,13 @@ const _Administration = class _Administration {
87
171
  circularRefSet = null;
88
172
  }
89
173
  }
90
- };
91
- _Administration.proxyTraps = {};
92
- let Administration = _Administration;
174
+ }
93
175
  class NodeMap {
176
+ map;
177
+ weakMap;
178
+ observedAtom;
179
+ cleanUpRegistered = false;
94
180
  constructor(observedAtom) {
95
- this.cleanUpRegistered = false;
96
181
  this.observedAtom = observedAtom;
97
182
  }
98
183
  registerCleanup() {
@@ -155,7 +240,47 @@ class SignalMap extends NodeMap {
155
240
  return createSignal(initialValue);
156
241
  }
157
242
  }
158
- const _ObjectAdministration = class _ObjectAdministration extends Administration {
243
+ class ObjectAdministration extends Administration {
244
+ keysAtom;
245
+ hasMap;
246
+ valuesMap;
247
+ computedMap;
248
+ types;
249
+ static proxyTraps = {
250
+ has(target, name) {
251
+ const adm = getAdministration(target);
252
+ if (!(name in Object.prototype) && isPropertyKey(name))
253
+ return adm.has(name);
254
+ return Reflect.has(adm.source, name);
255
+ },
256
+ get(target, name) {
257
+ const adm = getAdministration(target);
258
+ if (!(name in Object.prototype) && isPropertyKey(name) && (typeof adm.source !== "function" || name !== "prototype")) {
259
+ return adm.read(name);
260
+ }
261
+ return Reflect.get(adm.source, name, adm.proxy);
262
+ },
263
+ set(target, name, value) {
264
+ if (!isPropertyKey(name)) return false;
265
+ const adm = getAdministration(target);
266
+ adm.write(name, value);
267
+ return true;
268
+ },
269
+ deleteProperty(target, name) {
270
+ if (!isPropertyKey(name)) return false;
271
+ const adm = getAdministration(target);
272
+ adm.remove(name);
273
+ return true;
274
+ },
275
+ ownKeys(target) {
276
+ const adm = getAdministration(target);
277
+ signalsCore.batch(() => {
278
+ adm.keysAtom.reportObserved();
279
+ adm.atom.reportObserved();
280
+ });
281
+ return Reflect.ownKeys(adm.source);
282
+ }
283
+ };
159
284
  constructor(source2 = {}) {
160
285
  super(source2);
161
286
  this.keysAtom = createAtom();
@@ -167,7 +292,7 @@ const _ObjectAdministration = class _ObjectAdministration extends Administration
167
292
  return Reflect.get(this.source, key, this.proxy);
168
293
  }
169
294
  set(key, value) {
170
- runInBatch(() => {
295
+ signalsCore.batch(() => {
171
296
  Reflect.set(this.source, key, value, this.proxy);
172
297
  });
173
298
  }
@@ -190,7 +315,7 @@ const _ObjectAdministration = class _ObjectAdministration extends Administration
190
315
  }
191
316
  getType(key) {
192
317
  let type = this.types.get(key);
193
- if (!type) {
318
+ if (type === void 0) {
194
319
  type = getPropertyType(key, this.source);
195
320
  this.types.set(key, type);
196
321
  }
@@ -223,6 +348,9 @@ const _ObjectAdministration = class _ObjectAdministration extends Administration
223
348
  }
224
349
  read(key) {
225
350
  const type = this.getType(key);
351
+ if (type === null) {
352
+ return this.get(key);
353
+ }
226
354
  switch (type) {
227
355
  case "observable":
228
356
  case "action": {
@@ -247,8 +375,12 @@ const _ObjectAdministration = class _ObjectAdministration extends Administration
247
375
  }
248
376
  write(key, newValue) {
249
377
  const type = this.getType(key);
378
+ if (type === null) {
379
+ this.set(key, newValue);
380
+ return;
381
+ }
250
382
  if (type === "computed") {
251
- runInBatch(() => this.set(key, newValue));
383
+ signalsCore.batch(() => this.set(key, newValue));
252
384
  return;
253
385
  }
254
386
  const had = key in this.source;
@@ -259,7 +391,7 @@ const _ObjectAdministration = class _ObjectAdministration extends Administration
259
391
  }
260
392
  if (!had || (isObservable(oldValue) ? oldValue !== newValue : oldValue !== targetValue)) {
261
393
  this.set(key, targetValue);
262
- runInBatch(() => {
394
+ signalsCore.batch(() => {
263
395
  this.flushChange();
264
396
  if (!had) {
265
397
  this.keysAtom.reportChanged();
@@ -279,7 +411,7 @@ const _ObjectAdministration = class _ObjectAdministration extends Administration
279
411
  remove(key) {
280
412
  if (!(key in this.source)) return;
281
413
  delete this.source[key];
282
- runInBatch(() => {
414
+ signalsCore.batch(() => {
283
415
  this.flushChange();
284
416
  this.valuesMap.reportChanged(key, void 0);
285
417
  this.keysAtom.reportChanged();
@@ -287,61 +419,24 @@ const _ObjectAdministration = class _ObjectAdministration extends Administration
287
419
  this.valuesMap.delete(key);
288
420
  });
289
421
  }
290
- };
291
- _ObjectAdministration.proxyTraps = {
292
- has(target, name) {
293
- const adm = getAdministration(target);
294
- if (!(name in Object.prototype) && isPropertyKey(name))
295
- return adm.has(name);
296
- return Reflect.has(adm.source, name);
297
- },
298
- get(target, name) {
299
- const adm = getAdministration(target);
300
- if (!(name in Object.prototype) && isPropertyKey(name) && (typeof adm.source !== "function" || name !== "prototype")) {
301
- return adm.read(name);
302
- }
303
- return Reflect.get(adm.source, name, adm.proxy);
304
- },
305
- set(target, name, value) {
306
- if (!isPropertyKey(name)) return false;
307
- const adm = getAdministration(target);
308
- adm.write(name, value);
309
- return true;
310
- },
311
- deleteProperty(target, name) {
312
- if (!isPropertyKey(name)) return false;
313
- const adm = getAdministration(target);
314
- adm.remove(name);
315
- return true;
316
- },
317
- ownKeys(target) {
318
- const adm = getAdministration(target);
319
- runInBatch(() => {
320
- adm.keysAtom.reportObserved();
321
- adm.atom.reportObserved();
322
- });
323
- return Reflect.ownKeys(adm.source);
324
- }
325
- };
326
- let ObjectAdministration = _ObjectAdministration;
327
- const _PreactObjectAdministration = class _PreactObjectAdministration extends ObjectAdministration {
328
- };
329
- _PreactObjectAdministration.proxyTraps = Object.assign(
330
- {},
331
- ObjectAdministration.proxyTraps,
332
- {
333
- get(target, prop, proxy) {
334
- if (!(prop in target) && (typeof prop === "string" || typeof prop === "number") && String(prop)[0] === "$") {
335
- return getSignal(proxy, prop.substring(1));
422
+ }
423
+ class PreactObjectAdministration extends ObjectAdministration {
424
+ static proxyTraps = Object.assign(
425
+ {},
426
+ ObjectAdministration.proxyTraps,
427
+ {
428
+ get(target, prop, proxy) {
429
+ if (!(prop in target) && (typeof prop === "string" || typeof prop === "number") && String(prop)[0] === "$") {
430
+ return getSignal(proxy, prop.substring(1));
431
+ }
432
+ return ObjectAdministration.proxyTraps.get?.apply(
433
+ null,
434
+ arguments
435
+ );
336
436
  }
337
- return ObjectAdministration.proxyTraps.get?.apply(
338
- null,
339
- arguments
340
- );
341
437
  }
342
- }
343
- );
344
- let PreactObjectAdministration = _PreactObjectAdministration;
438
+ );
439
+ }
345
440
  function createObservedAtom() {
346
441
  let value = 0;
347
442
  const callbacks = /* @__PURE__ */ new Set();
@@ -406,13 +501,7 @@ function createAtom() {
406
501
  }
407
502
  };
408
503
  }
409
- function createEffect(fn) {
410
- return signalsCore.effect(fn);
411
- }
412
- function runInUntracked(fn) {
413
- return signalsCore.untracked(() => fn());
414
- }
415
- function createReaction(fn, callback) {
504
+ function reaction(fn, callback) {
416
505
  let initialized = false;
417
506
  let currentValue;
418
507
  return signalsCore.effect(() => {
@@ -484,15 +573,23 @@ function createComputed(fn, context = null) {
484
573
  }
485
574
  };
486
575
  }
487
- function observable(obj) {
488
- return getObservable(obj);
576
+ function observable(value, context) {
577
+ if (context && typeof context === "object" && "kind" in context) {
578
+ context.metadata[context.name] = { type: "observable" };
579
+ return value;
580
+ }
581
+ return getObservable(value);
582
+ }
583
+ function computed(value, context) {
584
+ if (context && typeof context === "object" && "kind" in context) {
585
+ context.metadata[context.name] = { type: "computed" };
586
+ return value;
587
+ }
588
+ return signalsCore.computed(value);
489
589
  }
490
590
  function source(obj) {
491
591
  return getSource(obj);
492
592
  }
493
- function runInBatch(fn) {
494
- return signalsCore.batch(() => fn());
495
- }
496
593
  class Observable {
497
594
  constructor() {
498
595
  return getObservableClassInstance(this);
@@ -536,11 +633,40 @@ function getSignal(obj, key) {
536
633
  }
537
634
  return node;
538
635
  }
539
- var _a, _b;
540
- const _CollectionAdministration = class _CollectionAdministration extends Administration {
636
+ class CollectionAdministration extends Administration {
637
+ isMap;
638
+ hasMap;
639
+ valuesMap;
640
+ keysAtom;
641
+ static proxyTraps = {
642
+ get(target, name) {
643
+ const adm = getAdministration(target);
644
+ if (name === "size" && "size" in adm.source) {
645
+ return adm.size;
646
+ }
647
+ const val = adm.source[name];
648
+ const collectionMethods = adm.constructor.methods;
649
+ if (collectionMethods.hasOwnProperty(name) && typeof val === "function") {
650
+ return collectionMethods[name];
651
+ }
652
+ return val;
653
+ }
654
+ };
655
+ static methods = {
656
+ clear: createMethod$1("clear"),
657
+ forEach: createMethod$1("forEach"),
658
+ has: createMethod$1("has"),
659
+ add: createMethod$1("add"),
660
+ set: createMethod$1("set"),
661
+ get: createMethod$1("get"),
662
+ delete: createMethod$1("delete"),
663
+ entries: createMethod$1("entries"),
664
+ keys: createMethod$1("keys"),
665
+ values: createMethod$1("values"),
666
+ [Symbol.iterator]: createMethod$1(Symbol.iterator)
667
+ };
541
668
  constructor(source2) {
542
669
  super(source2);
543
- this[_a] = "Set";
544
670
  this.hasMap = new AtomMap(this.atom);
545
671
  this.valuesMap = new SignalMap();
546
672
  this.keysAtom = createAtom();
@@ -550,7 +676,7 @@ const _CollectionAdministration = class _CollectionAdministration extends Admini
550
676
  return this.source.has(getSource(key)) || this.source.has(key);
551
677
  }
552
678
  onCollectionChange(key) {
553
- runInBatch(() => {
679
+ signalsCore.batch(() => {
554
680
  this.keysAtom.reportChanged();
555
681
  this.hasMap.reportChanged(key);
556
682
  this.flushChange();
@@ -575,7 +701,7 @@ const _CollectionAdministration = class _CollectionAdministration extends Admini
575
701
  );
576
702
  }
577
703
  clear() {
578
- runInBatch(() => {
704
+ signalsCore.batch(() => {
579
705
  this.source.forEach((_, key) => this.delete(key));
580
706
  });
581
707
  }
@@ -676,7 +802,7 @@ const _CollectionAdministration = class _CollectionAdministration extends Admini
676
802
  const hasKey = this.hasEntry(key);
677
803
  const oldValue = sourceMap.get(targetKey) ?? sourceMap.get(key);
678
804
  if (!hasKey || isObservable(oldValue) ? oldValue !== value : oldValue !== targetValue) {
679
- runInBatch(() => {
805
+ signalsCore.batch(() => {
680
806
  this.flushChange();
681
807
  if (sourceMap.has(key)) {
682
808
  sourceMap.set(key, targetValue);
@@ -711,45 +837,126 @@ const _CollectionAdministration = class _CollectionAdministration extends Admini
711
837
  }
712
838
  };
713
839
  }
714
- [(_b = Symbol.iterator, _a = Symbol.toStringTag, _b)]() {
840
+ [Symbol.iterator]() {
715
841
  return this.isMap ? this.entries() : this.values();
716
842
  }
717
- };
718
- _CollectionAdministration.proxyTraps = {
719
- get(target, name) {
720
- const adm = getAdministration(target);
721
- if (name === "size" && "size" in adm.source) {
722
- return adm.size;
723
- }
724
- const val = adm.source[name];
725
- const collectionMethods = adm.constructor.methods;
726
- if (collectionMethods.hasOwnProperty(name) && typeof val === "function") {
727
- return collectionMethods[name];
728
- }
729
- return val;
730
- }
731
- };
732
- _CollectionAdministration.methods = {
733
- clear: createMethod$1("clear"),
734
- forEach: createMethod$1("forEach"),
735
- has: createMethod$1("has"),
736
- add: createMethod$1("add"),
737
- set: createMethod$1("set"),
738
- get: createMethod$1("get"),
739
- delete: createMethod$1("delete"),
740
- entries: createMethod$1("entries"),
741
- keys: createMethod$1("keys"),
742
- values: createMethod$1("values"),
743
- [Symbol.iterator]: createMethod$1(Symbol.iterator)
744
- };
745
- let CollectionAdministration = _CollectionAdministration;
843
+ [Symbol.toStringTag] = "Set";
844
+ }
746
845
  function createMethod$1(method) {
747
846
  return function() {
748
847
  const adm = getAdministration(this);
749
848
  return adm[method].apply(adm, arguments);
750
849
  };
751
850
  }
752
- const _ArrayAdministration = class _ArrayAdministration extends Administration {
851
+ class ArrayAdministration extends Administration {
852
+ valuesMap;
853
+ keysAtom;
854
+ static proxyTraps = {
855
+ get(target, name) {
856
+ const adm = getAdministration(target);
857
+ if (name === "length") {
858
+ return adm.getArrayLength();
859
+ }
860
+ if (typeof name === "number") {
861
+ return adm.get(name);
862
+ }
863
+ if (typeof name === "string" && String(parseInt(name)) === name) {
864
+ return adm.get(parseInt(name));
865
+ }
866
+ const arrayMethods = adm.constructor.methods;
867
+ if (arrayMethods.hasOwnProperty(name)) {
868
+ return arrayMethods[name];
869
+ }
870
+ return adm.source[name];
871
+ },
872
+ set(target, name, value) {
873
+ const adm = getAdministration(target);
874
+ if (name === "length") {
875
+ adm.setArrayLength(value);
876
+ } else if (typeof name === "number") {
877
+ adm.set(name, value);
878
+ } else if (typeof name === "string" && String(parseInt(name)) === name) {
879
+ adm.set(parseInt(name), value);
880
+ } else {
881
+ adm.source[name] = value;
882
+ }
883
+ return true;
884
+ }
885
+ };
886
+ static methods = {
887
+ fill(value, start, end) {
888
+ const adm = getAdministration(this);
889
+ const oldLength = adm.source.length;
890
+ adm.source.fill(value, start, end);
891
+ adm.onArrayChanged(oldLength !== adm.source.length, start, end);
892
+ return this;
893
+ },
894
+ splice(index, deleteCount, ...newItems) {
895
+ const adm = getAdministration(this);
896
+ switch (arguments.length) {
897
+ case 0:
898
+ return [];
899
+ case 1:
900
+ return adm.spliceWithArray(index);
901
+ case 2:
902
+ return adm.spliceWithArray(index, deleteCount);
903
+ }
904
+ return adm.spliceWithArray(index, deleteCount, newItems);
905
+ },
906
+ push(...items) {
907
+ const adm = getAdministration(this);
908
+ adm.spliceWithArray(adm.source.length, 0, items);
909
+ return adm.source.length;
910
+ },
911
+ pop() {
912
+ return this.splice(
913
+ Math.max(getAdministration(this).source.length - 1, 0),
914
+ 1
915
+ )[0];
916
+ },
917
+ shift() {
918
+ return this.splice(0, 1)[0];
919
+ },
920
+ unshift(...items) {
921
+ const adm = getAdministration(this);
922
+ adm.spliceWithArray(0, 0, items);
923
+ return adm.source.length;
924
+ },
925
+ reverse() {
926
+ const adm = getAdministration(this);
927
+ adm.source.reverse();
928
+ adm.onArrayChanged(false, 0, adm.source.length);
929
+ return this;
930
+ },
931
+ sort(compareFn) {
932
+ const adm = getAdministration(this);
933
+ adm.onArrayChanged();
934
+ adm.source.sort(
935
+ compareFn && ((a, b) => compareFn(getObservable(a), getObservable(b)))
936
+ );
937
+ return this;
938
+ },
939
+ join: createStringMethod("join"),
940
+ toString: createStringMethod("toString"),
941
+ toLocaleString: createStringMethod("toLocaleString"),
942
+ indexOf: createSearchMethod("indexOf"),
943
+ lastIndexOf: createSearchMethod("lastIndexOf"),
944
+ includes: createSearchMethod("includes"),
945
+ slice: createCopyMethod("slice"),
946
+ concat: createCopyMethod("concat"),
947
+ flat: createCopyMethod("flat"),
948
+ copyWithin: createCopyMethod("copyWithin"),
949
+ every: createMapMethod("every"),
950
+ forEach: createMapMethod("forEach"),
951
+ map: createMapMethod("map"),
952
+ flatMap: createMapMethod("flatMap"),
953
+ findIndex: createMapMethod("findIndex"),
954
+ some: createMapMethod("some"),
955
+ filter: createFilterMethod("filter"),
956
+ find: createFilterMethod("find"),
957
+ reduce: createReduceMethod("reduce"),
958
+ reduceRight: createReduceMethod("reduceRight")
959
+ };
753
960
  constructor(source2 = []) {
754
961
  super(source2);
755
962
  this.valuesMap = new SignalMap();
@@ -840,7 +1047,7 @@ const _ArrayAdministration = class _ArrayAdministration extends Administration {
840
1047
  );
841
1048
  }
842
1049
  onArrayChanged(lengthChanged = false, index, count) {
843
- runInBatch(() => {
1050
+ signalsCore.batch(() => {
844
1051
  if (lengthChanged) {
845
1052
  this.keysAtom.reportChanged();
846
1053
  }
@@ -854,114 +1061,7 @@ const _ArrayAdministration = class _ArrayAdministration extends Administration {
854
1061
  this.flushChange();
855
1062
  });
856
1063
  }
857
- };
858
- _ArrayAdministration.proxyTraps = {
859
- get(target, name) {
860
- const adm = getAdministration(target);
861
- if (name === "length") {
862
- return adm.getArrayLength();
863
- }
864
- if (typeof name === "number") {
865
- return adm.get(name);
866
- }
867
- if (typeof name === "string" && String(parseInt(name)) === name) {
868
- return adm.get(parseInt(name));
869
- }
870
- const arrayMethods = adm.constructor.methods;
871
- if (arrayMethods.hasOwnProperty(name)) {
872
- return arrayMethods[name];
873
- }
874
- return adm.source[name];
875
- },
876
- set(target, name, value) {
877
- const adm = getAdministration(target);
878
- if (name === "length") {
879
- adm.setArrayLength(value);
880
- } else if (typeof name === "number") {
881
- adm.set(name, value);
882
- } else if (typeof name === "string" && String(parseInt(name)) === name) {
883
- adm.set(parseInt(name), value);
884
- } else {
885
- adm.source[name] = value;
886
- }
887
- return true;
888
- }
889
- };
890
- _ArrayAdministration.methods = {
891
- fill(value, start, end) {
892
- const adm = getAdministration(this);
893
- const oldLength = adm.source.length;
894
- adm.source.fill(value, start, end);
895
- adm.onArrayChanged(oldLength !== adm.source.length, start, end);
896
- return this;
897
- },
898
- splice(index, deleteCount, ...newItems) {
899
- const adm = getAdministration(this);
900
- switch (arguments.length) {
901
- case 0:
902
- return [];
903
- case 1:
904
- return adm.spliceWithArray(index);
905
- case 2:
906
- return adm.spliceWithArray(index, deleteCount);
907
- }
908
- return adm.spliceWithArray(index, deleteCount, newItems);
909
- },
910
- push(...items) {
911
- const adm = getAdministration(this);
912
- adm.spliceWithArray(adm.source.length, 0, items);
913
- return adm.source.length;
914
- },
915
- pop() {
916
- return this.splice(
917
- Math.max(getAdministration(this).source.length - 1, 0),
918
- 1
919
- )[0];
920
- },
921
- shift() {
922
- return this.splice(0, 1)[0];
923
- },
924
- unshift(...items) {
925
- const adm = getAdministration(this);
926
- adm.spliceWithArray(0, 0, items);
927
- return adm.source.length;
928
- },
929
- reverse() {
930
- const adm = getAdministration(this);
931
- adm.source.reverse();
932
- adm.onArrayChanged(false, 0, adm.source.length);
933
- return this;
934
- },
935
- sort(compareFn) {
936
- const adm = getAdministration(this);
937
- adm.onArrayChanged();
938
- adm.source.sort(
939
- compareFn && ((a, b) => compareFn(getObservable(a), getObservable(b)))
940
- );
941
- return this;
942
- },
943
- join: createStringMethod("join"),
944
- toString: createStringMethod("toString"),
945
- toLocaleString: createStringMethod("toLocaleString"),
946
- indexOf: createSearchMethod("indexOf"),
947
- lastIndexOf: createSearchMethod("lastIndexOf"),
948
- includes: createSearchMethod("includes"),
949
- slice: createCopyMethod("slice"),
950
- concat: createCopyMethod("concat"),
951
- flat: createCopyMethod("flat"),
952
- copyWithin: createCopyMethod("copyWithin"),
953
- every: createMapMethod("every"),
954
- forEach: createMapMethod("forEach"),
955
- map: createMapMethod("map"),
956
- flatMap: createMapMethod("flatMap"),
957
- findIndex: createMapMethod("findIndex"),
958
- some: createMapMethod("some"),
959
- filter: createFilterMethod("filter"),
960
- find: createFilterMethod("find"),
961
- reduce: createReduceMethod("reduce"),
962
- reduceRight: createReduceMethod("reduceRight")
963
- };
964
- let ArrayAdministration = _ArrayAdministration;
1064
+ }
965
1065
  function createMethod(method, func) {
966
1066
  if (Array.prototype.hasOwnProperty(method)) {
967
1067
  return func;
@@ -1048,23 +1148,22 @@ function createReduceMethod(method) {
1048
1148
  return adm.source[method].apply(adm.source, arguments);
1049
1149
  });
1050
1150
  }
1051
- const _DateAdministration = class _DateAdministration extends Administration {
1052
- };
1053
- _DateAdministration.proxyTraps = {
1054
- get(target, name) {
1055
- const adm = getAdministration(target);
1056
- if (typeof adm.source[name] === "function") {
1057
- if (typeof name === "string" && name.startsWith("set")) {
1058
- addDateSetMethod(name);
1059
- } else {
1060
- addDateGetMethod(name);
1151
+ class DateAdministration extends Administration {
1152
+ static proxyTraps = {
1153
+ get(target, name) {
1154
+ const adm = getAdministration(target);
1155
+ if (typeof adm.source[name] === "function") {
1156
+ if (typeof name === "string" && name.startsWith("set")) {
1157
+ addDateSetMethod(name);
1158
+ } else {
1159
+ addDateGetMethod(name);
1160
+ }
1161
+ return dateMethods[name];
1061
1162
  }
1062
- return dateMethods[name];
1163
+ return adm.source[name];
1063
1164
  }
1064
- return adm.source[name];
1065
- }
1066
- };
1067
- let DateAdministration = _DateAdministration;
1165
+ };
1166
+ }
1068
1167
  const dateMethods = /* @__PURE__ */ Object.create(null);
1069
1168
  function addDateSetMethod(method) {
1070
1169
  if (!dateMethods[method])
@@ -1159,60 +1258,6 @@ function getInternalNode(obj, key) {
1159
1258
  }
1160
1259
  return adm.getNode(key);
1161
1260
  }
1162
- var CommonCfgTypes = /* @__PURE__ */ ((CommonCfgTypes2) => {
1163
- CommonCfgTypes2["child"] = "child";
1164
- CommonCfgTypes2["children"] = "children";
1165
- return CommonCfgTypes2;
1166
- })(CommonCfgTypes || {});
1167
- var ModelCfgTypes = /* @__PURE__ */ ((ModelCfgTypes2) => {
1168
- ModelCfgTypes2["state"] = "state";
1169
- ModelCfgTypes2["id"] = "id";
1170
- ModelCfgTypes2["modelRef"] = "modelRef";
1171
- ModelCfgTypes2["modelRefs"] = "modelRefs";
1172
- return ModelCfgTypes2;
1173
- })(ModelCfgTypes || {});
1174
- var StoreCfgTypes = /* @__PURE__ */ ((StoreCfgTypes2) => {
1175
- StoreCfgTypes2["model"] = "model";
1176
- return StoreCfgTypes2;
1177
- })(StoreCfgTypes || {});
1178
- const childType = Object.assign(
1179
- function(childType2) {
1180
- return { type: "child", childType: childType2 };
1181
- },
1182
- {
1183
- type: "child"
1184
- /* child */
1185
- }
1186
- );
1187
- const childrenType = Object.assign(
1188
- function(childType2) {
1189
- return { type: "children", childType: childType2 };
1190
- },
1191
- {
1192
- type: "children"
1193
- /* children */
1194
- }
1195
- );
1196
- const stateType = {
1197
- type: "state"
1198
- /* state */
1199
- };
1200
- const modelRefType = {
1201
- type: "modelRef"
1202
- /* modelRef */
1203
- };
1204
- const modelRefsType = {
1205
- type: "modelRefs"
1206
- /* modelRefs */
1207
- };
1208
- const idType = {
1209
- type: "id"
1210
- /* id */
1211
- };
1212
- const modelType = {
1213
- type: "model"
1214
- /* model */
1215
- };
1216
1261
  function getPropertyDescriptor(obj, key) {
1217
1262
  let node = obj;
1218
1263
  while (node) {
@@ -1251,17 +1296,20 @@ function getDiff(o1, o2, getConfig) {
1251
1296
  const key = keys[i];
1252
1297
  if (obj1[key] !== obj2[key]) {
1253
1298
  if (config?.[key]?.type === CommonCfgTypes.child) {
1254
- const childDiff = getDiff(obj1[key], obj2[key], getConfig);
1255
- if (childDiff) {
1256
- diff[key] = childDiff;
1257
- }
1258
- } else if (config?.[key]?.type === CommonCfgTypes.children) {
1259
- diff[key] = obj2[key].map((model2, index) => {
1260
- if (obj1[key][index]) {
1261
- return getDiff(obj1[key][index], model2, getConfig);
1299
+ const value = obj2[key];
1300
+ if (Array.isArray(value)) {
1301
+ diff[key] = value.map((model2, index) => {
1302
+ if (obj1[key][index]) {
1303
+ return getDiff(obj1[key][index], model2, getConfig);
1304
+ }
1305
+ return model2;
1306
+ });
1307
+ } else {
1308
+ const childDiff = getDiff(obj1[key], obj2[key], getConfig);
1309
+ if (childDiff) {
1310
+ diff[key] = childDiff;
1262
1311
  }
1263
- return model2;
1264
- });
1312
+ }
1265
1313
  } else {
1266
1314
  diff[key] = obj2[key];
1267
1315
  }
@@ -1269,25 +1317,9 @@ function getDiff(o1, o2, getConfig) {
1269
1317
  }
1270
1318
  return Object.keys(diff).length > 0 ? diff : null;
1271
1319
  }
1272
- function computedProxy(computed) {
1273
- const initial = {};
1274
- Object.keys(computed.get()).forEach((k) => initial[k] = void 0);
1275
- const proxy = new Proxy(initial, {
1276
- get(target, key) {
1277
- if (!target[key]) {
1278
- target[key] = createComputed(
1279
- () => computed.get()[key],
1280
- null
1281
- );
1282
- }
1283
- return target[key].get();
1284
- }
1285
- });
1286
- return proxy;
1287
- }
1288
1320
  function updateProps(props, newProps) {
1289
- runInUntracked(() => {
1290
- runInBatch(() => {
1321
+ signalsCore.untracked(() => {
1322
+ signalsCore.batch(() => {
1291
1323
  const propKeys = Object.keys(newProps);
1292
1324
  propKeys.forEach((k) => {
1293
1325
  if (k !== "models") {
@@ -1304,26 +1336,63 @@ function updateProps(props, newProps) {
1304
1336
  function getStoreAdm(store) {
1305
1337
  return getAdministration(store);
1306
1338
  }
1307
- const _StoreAdministration = class _StoreAdministration extends PreactObjectAdministration {
1308
- constructor() {
1309
- super(...arguments);
1310
- this.parent = null;
1311
- this.mounted = false;
1312
- this.contextReactionUnsub = null;
1313
- this.childStoreDataMap = /* @__PURE__ */ new Map();
1314
- this.reactionsUnsub = [];
1315
- }
1316
- setConfiguration(configuration) {
1317
- this.configuration = configuration;
1339
+ class StoreAdministration extends PreactObjectAdministration {
1340
+ static proxyTraps = Object.assign(
1341
+ {},
1342
+ PreactObjectAdministration.proxyTraps,
1343
+ {
1344
+ get(target, name) {
1345
+ if (name === "key") {
1346
+ return target.key;
1347
+ }
1348
+ const adm = getAdministration(target);
1349
+ switch (adm.configuration[name]?.type) {
1350
+ case CommonCfgTypes.child:
1351
+ return adm.getStore(name);
1352
+ case StoreCfgTypes.model:
1353
+ return adm.getModelRef(name);
1354
+ default:
1355
+ return PreactObjectAdministration.proxyTraps.get?.apply(
1356
+ null,
1357
+ arguments
1358
+ );
1359
+ }
1360
+ },
1361
+ set(target, name, value) {
1362
+ const adm = getAdministration(target);
1363
+ if (name === "props") {
1364
+ throw new Error(`r-state-tree: ${name} is read-only`);
1365
+ }
1366
+ if (adm.configuration[name]?.type === StoreCfgTypes.model) {
1367
+ if (value !== void 0) {
1368
+ throw new Error(`r-state-tree: model ${String(name)} is read-only`);
1369
+ }
1370
+ }
1371
+ return PreactObjectAdministration.proxyTraps.set?.apply(
1372
+ null,
1373
+ arguments
1374
+ );
1375
+ }
1376
+ }
1377
+ );
1378
+ parent = null;
1379
+ mounted = false;
1380
+ contextCache = /* @__PURE__ */ new Map();
1381
+ childStoreDataMap = /* @__PURE__ */ new Map();
1382
+ reactionsUnsub = [];
1383
+ configurationGetter;
1384
+ setConfiguration(configurationGetter) {
1385
+ this.configurationGetter = configurationGetter;
1386
+ }
1387
+ get configuration() {
1388
+ return this.configurationGetter?.() ?? {};
1318
1389
  }
1319
1390
  createChildStore(element) {
1320
1391
  return allowNewStore(() => new element.Type(element.props));
1321
1392
  }
1322
1393
  setStoreList(name, elements) {
1323
1394
  const childStoreData = this.childStoreDataMap.get(name);
1324
- const oldStores = runInUntracked(
1325
- () => childStoreData.value.get()
1326
- );
1395
+ const oldStores = signalsCore.untracked(() => childStoreData.value.get());
1327
1396
  const stores = [];
1328
1397
  let keyedIndexChanged = false;
1329
1398
  if (!oldStores) {
@@ -1382,7 +1451,7 @@ const _StoreAdministration = class _StoreAdministration extends PreactObjectAdmi
1382
1451
  }
1383
1452
  });
1384
1453
  if (newStores.size || removedStores.size || keyedIndexChanged) {
1385
- runInBatch(() => childStoreData.value.set(stores));
1454
+ signalsCore.batch(() => childStoreData.value.set(stores));
1386
1455
  }
1387
1456
  removedStores.forEach((s) => getStoreAdm(s).unmount());
1388
1457
  newStores.forEach((s) => getStoreAdm(s).mount(this));
@@ -1390,24 +1459,24 @@ const _StoreAdministration = class _StoreAdministration extends PreactObjectAdmi
1390
1459
  }
1391
1460
  setSingleStore(name, element) {
1392
1461
  const childStoreData = this.childStoreDataMap.get(name);
1393
- const oldStore = runInUntracked(
1462
+ const oldStore = signalsCore.untracked(
1394
1463
  () => childStoreData.value.get()
1395
1464
  );
1396
1465
  const { key, Type, props } = element || {};
1397
1466
  if (!element) {
1398
1467
  oldStore && getStoreAdm(oldStore).unmount();
1399
- runInBatch(() => childStoreData.value.set(null));
1468
+ signalsCore.batch(() => childStoreData.value.set(null));
1400
1469
  return null;
1401
1470
  } else if (!oldStore || oldStore.props.key !== key || !(oldStore instanceof Type)) {
1402
1471
  if (oldStore) {
1403
1472
  getStoreAdm(oldStore).unmount();
1404
1473
  }
1405
1474
  const childStore = this.createChildStore(element);
1406
- runInBatch(() => childStoreData.value.set(childStore));
1475
+ signalsCore.batch(() => childStoreData.value.set(childStore));
1407
1476
  getStoreAdm(childStore).mount(this);
1408
1477
  return childStore;
1409
1478
  } else {
1410
- runInBatch(() => updateProps(oldStore.props, props));
1479
+ signalsCore.batch(() => updateProps(oldStore.props, props));
1411
1480
  return oldStore;
1412
1481
  }
1413
1482
  }
@@ -1416,14 +1485,7 @@ const _StoreAdministration = class _StoreAdministration extends PreactObjectAdmi
1416
1485
  const storeElement = childStoreData.listener.track(
1417
1486
  () => childStoreData.computed.get()
1418
1487
  );
1419
- this.setSingleStore(name, storeElement);
1420
- }
1421
- updateStores(name) {
1422
- const childStoreData = this.childStoreDataMap.get(name);
1423
- const storeElement = childStoreData.listener.track(
1424
- () => childStoreData.computed.get()
1425
- );
1426
- this.setStoreList(name, storeElement);
1488
+ Array.isArray(storeElement) ? this.setStoreList(name, storeElement) : this.setSingleStore(name, storeElement);
1427
1489
  }
1428
1490
  getComputedGetter(name) {
1429
1491
  const descriptor = getPropertyDescriptor(this.source, name);
@@ -1443,21 +1505,7 @@ const _StoreAdministration = class _StoreAdministration extends PreactObjectAdmi
1443
1505
  const storeElement = childStoreData.listener.track(
1444
1506
  () => childStoreData.computed.get()
1445
1507
  );
1446
- this.setSingleStore(name, storeElement);
1447
- return childStoreData.value.get();
1448
- }
1449
- initializeStores(name) {
1450
- const value = createSignal([]);
1451
- const childStoreData = this.childStoreDataMap.get(name) ?? {
1452
- computed: this.getComputedGetter(name),
1453
- listener: createListener(() => this.updateStores(name)),
1454
- value
1455
- };
1456
- this.childStoreDataMap.set(name, childStoreData);
1457
- const storeElement = childStoreData.listener.track(
1458
- () => childStoreData.computed.get()
1459
- );
1460
- this.setStoreList(name, storeElement);
1508
+ Array.isArray(storeElement) ? this.setStoreList(name, storeElement) : this.setSingleStore(name, storeElement);
1461
1509
  return childStoreData.value.get();
1462
1510
  }
1463
1511
  getStore(name) {
@@ -1465,18 +1513,8 @@ const _StoreAdministration = class _StoreAdministration extends PreactObjectAdmi
1465
1513
  if (!childStoreData) {
1466
1514
  return this.initializeStore(name);
1467
1515
  } else {
1468
- const storeElement = runInUntracked(() => childStoreData.computed.get());
1469
- this.setSingleStore(name, storeElement);
1470
- return childStoreData.value.get();
1471
- }
1472
- }
1473
- getStores(name) {
1474
- const childStoreData = this.childStoreDataMap.get(name);
1475
- if (!childStoreData) {
1476
- return this.initializeStores(name);
1477
- } else {
1478
- const storeElement = runInUntracked(() => childStoreData.computed.get());
1479
- this.setStoreList(name, storeElement);
1516
+ const storeElement = signalsCore.untracked(() => childStoreData.computed.get());
1517
+ Array.isArray(storeElement) ? this.setStoreList(name, storeElement) : this.setSingleStore(name, storeElement);
1480
1518
  return childStoreData.value.get();
1481
1519
  }
1482
1520
  }
@@ -1486,22 +1524,46 @@ const _StoreAdministration = class _StoreAdministration extends PreactObjectAdmi
1486
1524
  isRoot() {
1487
1525
  return !this.parent;
1488
1526
  }
1489
- createReaction(track, callback) {
1490
- const unsub = createReaction(track, callback);
1527
+ getContextValue(contextId, provideSymbol, defaultValue, hasDefault) {
1528
+ let computed2 = this.contextCache.get(contextId);
1529
+ if (!computed2) {
1530
+ computed2 = createComputed(() => {
1531
+ return this.lookupContextValue(
1532
+ contextId,
1533
+ provideSymbol,
1534
+ defaultValue,
1535
+ hasDefault
1536
+ );
1537
+ });
1538
+ this.contextCache.set(contextId, computed2);
1539
+ }
1540
+ return computed2.get();
1541
+ }
1542
+ lookupContextValue(contextId, provideSymbol, defaultValue, hasDefault) {
1543
+ const provideMethod = this.source[provideSymbol];
1544
+ if (typeof provideMethod === "function") {
1545
+ return provideMethod.call(this.proxy);
1546
+ }
1547
+ if (this.parent) {
1548
+ return this.parent.getContextValue(
1549
+ contextId,
1550
+ provideSymbol,
1551
+ defaultValue,
1552
+ hasDefault
1553
+ );
1554
+ }
1555
+ if (hasDefault) {
1556
+ return defaultValue;
1557
+ }
1558
+ return void 0;
1559
+ }
1560
+ reaction(track, callback) {
1561
+ const unsub = reaction(track, callback);
1491
1562
  this.reactionsUnsub.push(unsub);
1492
1563
  return unsub;
1493
1564
  }
1494
1565
  mount(parent = null) {
1495
1566
  this.parent = parent || null;
1496
- if (this.parent) {
1497
- const parentSource = this.parent.proxy;
1498
- this.computedContext = computedProxy(
1499
- createComputed(() => ({
1500
- ...parentSource.context,
1501
- ...parentSource.provideContext()
1502
- }))
1503
- );
1504
- }
1505
1567
  this.childStoreDataMap.forEach(({ value }) => {
1506
1568
  const stores = value.get();
1507
1569
  if (Array.isArray(stores)) {
@@ -1511,69 +1573,29 @@ const _StoreAdministration = class _StoreAdministration extends PreactObjectAdmi
1511
1573
  }
1512
1574
  });
1513
1575
  this.mounted = true;
1514
- runInBatch(() => this.proxy.storeDidMount?.());
1576
+ signalsCore.batch(() => this.proxy.storeDidMount?.());
1515
1577
  }
1516
1578
  unmount() {
1517
1579
  this.proxy.storeWillUnmount?.();
1518
1580
  this.mounted = false;
1519
1581
  this.childStoreDataMap.forEach((data) => {
1520
- const { value, computed, listener } = data;
1582
+ const { value, computed: computed2, listener } = data;
1521
1583
  const stores = value.get();
1522
1584
  if (Array.isArray(stores)) {
1523
1585
  stores?.forEach((s) => getStoreAdm(s)?.unmount());
1524
1586
  } else if (stores) {
1525
1587
  getStoreAdm(stores)?.unmount();
1526
1588
  }
1527
- computed.clear();
1589
+ computed2.clear();
1528
1590
  listener.dispose();
1529
1591
  });
1530
1592
  this.childStoreDataMap.clear();
1531
- this.contextReactionUnsub?.();
1593
+ this.contextCache.forEach((computed2) => computed2.clear());
1594
+ this.contextCache.clear();
1532
1595
  this.reactionsUnsub.forEach((u) => u());
1533
1596
  this.parent = null;
1534
1597
  }
1535
- };
1536
- _StoreAdministration.proxyTraps = Object.assign(
1537
- {},
1538
- PreactObjectAdministration.proxyTraps,
1539
- {
1540
- get(target, name) {
1541
- if (name === "key") {
1542
- return target.key;
1543
- } else if (name === "context") {
1544
- return target.context;
1545
- }
1546
- const adm = getAdministration(target);
1547
- switch (adm.configuration[name]?.type) {
1548
- case CommonCfgTypes.child:
1549
- return adm.getStore(name);
1550
- case CommonCfgTypes.children:
1551
- return adm.getStores(name);
1552
- case StoreCfgTypes.model:
1553
- return adm.getModelRef(name);
1554
- default:
1555
- return PreactObjectAdministration.proxyTraps.get?.apply(
1556
- null,
1557
- arguments
1558
- );
1559
- }
1560
- },
1561
- set(target, name, value) {
1562
- const adm = getAdministration(target);
1563
- if (name === "props" || name === "context") {
1564
- throw new Error(`r-state-tree: ${name} is read-only`);
1565
- }
1566
- if (adm.configuration[name]?.type === StoreCfgTypes.model) {
1567
- throw new Error(`r-state-tree: model ${String(name)} is read-only`);
1568
- }
1569
- return PreactObjectAdministration.proxyTraps.set?.apply(
1570
- null,
1571
- arguments
1572
- );
1573
- }
1574
- }
1575
- );
1576
- let StoreAdministration = _StoreAdministration;
1598
+ }
1577
1599
  let initEnabled$1 = false;
1578
1600
  function allowNewStore(fn) {
1579
1601
  initEnabled$1 = true;
@@ -1594,18 +1616,23 @@ function updateStore(store, props) {
1594
1616
  updateProps(store.props, props);
1595
1617
  return store;
1596
1618
  }
1597
- const _Store = class _Store {
1619
+ class Store {
1620
+ static get types() {
1621
+ return this[Symbol.metadata];
1622
+ }
1623
+ props;
1598
1624
  constructor(props) {
1599
1625
  if (!initEnabled$1) {
1600
1626
  throw new Error("r-state-tree: Can't initialize store directly");
1601
1627
  }
1602
- const config = this.constructor.types;
1603
1628
  const observable2 = createObservableWithCustomAdministration(
1604
1629
  this,
1605
1630
  StoreAdministration
1606
1631
  );
1607
1632
  const adm = getStoreAdm(observable2);
1608
- adm.setConfiguration(config ?? {});
1633
+ adm.setConfiguration(
1634
+ () => this.constructor.types ?? {}
1635
+ );
1609
1636
  adm.write("props", getObservable({}));
1610
1637
  updateProps(observable2.props, props);
1611
1638
  return observable2;
@@ -1613,14 +1640,8 @@ const _Store = class _Store {
1613
1640
  get key() {
1614
1641
  return this.props.key;
1615
1642
  }
1616
- get context() {
1617
- return getStoreAdm(this).computedContext;
1618
- }
1619
- createReaction(track, callback) {
1620
- return getStoreAdm(this).createReaction(track, callback);
1621
- }
1622
- provideContext() {
1623
- return null;
1643
+ reaction(track, callback) {
1644
+ return getStoreAdm(this).reaction(track, callback);
1624
1645
  }
1625
1646
  // eslint-disable-next-line @typescript-eslint/no-empty-function
1626
1647
  storeDidMount() {
@@ -1628,9 +1649,7 @@ const _Store = class _Store {
1628
1649
  // eslint-disable-next-line @typescript-eslint/no-empty-function
1629
1650
  storeWillUnmount() {
1630
1651
  }
1631
- };
1632
- _Store.types = {};
1633
- let Store = _Store;
1652
+ }
1634
1653
  const attachedIdMap = /* @__PURE__ */ new WeakMap();
1635
1654
  const idMap = /* @__PURE__ */ new WeakMap();
1636
1655
  let loadingSnapshot = false;
@@ -1786,9 +1805,8 @@ function observe(obj, method) {
1786
1805
  return listener.subscribe(method);
1787
1806
  }
1788
1807
  class ObservableListener {
1789
- constructor() {
1790
- this.notifying = false;
1791
- }
1808
+ listeners;
1809
+ notifying = false;
1792
1810
  subscribe(l) {
1793
1811
  let unsubed = false;
1794
1812
  this.listeners = this.listeners || [];
@@ -1820,7 +1838,7 @@ class ObservableListener {
1820
1838
  }
1821
1839
  class ChildModelsAdministration extends ArrayAdministration {
1822
1840
  set(index, newValue) {
1823
- return runInBatch(() => {
1841
+ return signalsCore.batch(() => {
1824
1842
  super.set(index, newValue);
1825
1843
  const sourceValue = getSource(newValue);
1826
1844
  if (this.source[index] !== sourceValue) {
@@ -1829,7 +1847,7 @@ class ChildModelsAdministration extends ArrayAdministration {
1829
1847
  });
1830
1848
  }
1831
1849
  spliceWithArray(index, deleteCount, newItems) {
1832
- return runInBatch(() => {
1850
+ return signalsCore.batch(() => {
1833
1851
  const deleted = super.spliceWithArray(index, deleteCount, newItems);
1834
1852
  if (deleteCount || newItems?.length) {
1835
1853
  notifySpliceArray(this.proxy, index, newItems ?? [], deleted);
@@ -1873,19 +1891,108 @@ function getSnapshotRefId(snapshot) {
1873
1891
  }
1874
1892
  return snapshot[keys[0]];
1875
1893
  }
1876
- const _ModelAdministration = class _ModelAdministration extends PreactObjectAdministration {
1877
- constructor() {
1878
- super(...arguments);
1879
- this.parent = null;
1880
- this.activeModels = /* @__PURE__ */ new Set();
1881
- this.root = this;
1882
- this.modelsTraceUnsub = /* @__PURE__ */ new Map();
1883
- this.writeInProgress = /* @__PURE__ */ new Set();
1884
- this.snapshotMap = /* @__PURE__ */ new Map();
1885
- this.parentName = null;
1894
+ class ModelAdministration extends PreactObjectAdministration {
1895
+ static proxyTraps = Object.assign(
1896
+ {},
1897
+ PreactObjectAdministration.proxyTraps,
1898
+ {
1899
+ get(target, prop, proxy) {
1900
+ const adm = getAdministration(target);
1901
+ if (prop === "parent") {
1902
+ return target.parent;
1903
+ }
1904
+ switch (adm.configuration[prop]?.type) {
1905
+ case ModelCfgTypes.modelRef:
1906
+ if (Array.isArray(adm.source[prop])) {
1907
+ return adm.getModelRefs(prop);
1908
+ }
1909
+ return adm.getModelRef(prop);
1910
+ default:
1911
+ return PreactObjectAdministration.proxyTraps.get?.apply(
1912
+ null,
1913
+ arguments
1914
+ );
1915
+ }
1916
+ },
1917
+ set(target, name, value) {
1918
+ const adm = getAdministration(target);
1919
+ adm.writeInProgress.add(name);
1920
+ try {
1921
+ switch (adm.configuration[name]?.type) {
1922
+ case ModelCfgTypes.modelRef: {
1923
+ Array.isArray(value) ? adm.setModelRefs(name, value) : adm.setModelRef(name, value);
1924
+ return true;
1925
+ }
1926
+ case CommonCfgTypes.child: {
1927
+ if (Array.isArray(value)) {
1928
+ adm.setModels(name, value);
1929
+ return true;
1930
+ } else {
1931
+ adm.setModel(name, value ?? null);
1932
+ break;
1933
+ }
1934
+ }
1935
+ case ModelCfgTypes.id: {
1936
+ adm.setId(name, value);
1937
+ break;
1938
+ }
1939
+ case ModelCfgTypes.state: {
1940
+ adm.setState(name, value);
1941
+ break;
1942
+ }
1943
+ }
1944
+ return PreactObjectAdministration.proxyTraps.set?.apply(
1945
+ null,
1946
+ arguments
1947
+ );
1948
+ } finally {
1949
+ adm.writeInProgress.delete(name);
1950
+ }
1951
+ },
1952
+ defineProperty(target, name, desc) {
1953
+ const adm = getAdministration(target);
1954
+ if (desc && "value" in desc && !adm.writeInProgress.has(name)) {
1955
+ switch (adm.configuration[name]?.type) {
1956
+ case ModelCfgTypes.modelRef:
1957
+ case CommonCfgTypes.child:
1958
+ case ModelCfgTypes.id: {
1959
+ adm.proxy[name] = desc.value;
1960
+ return true;
1961
+ }
1962
+ }
1963
+ }
1964
+ return Reflect.defineProperty(target, name, desc);
1965
+ }
1966
+ }
1967
+ );
1968
+ configurationGetter;
1969
+ _parent = null;
1970
+ parentAtom = createAtom();
1971
+ referencedAtoms;
1972
+ referencedModels;
1973
+ activeModels = /* @__PURE__ */ new Set();
1974
+ root = this;
1975
+ modelsTraceUnsub = /* @__PURE__ */ new Map();
1976
+ writeInProgress = /* @__PURE__ */ new Set();
1977
+ computedSnapshot;
1978
+ snapshotMap = /* @__PURE__ */ new Map();
1979
+ contextCache = /* @__PURE__ */ new Map();
1980
+ parentName = null;
1981
+ get parent() {
1982
+ this.parentAtom.reportObserved();
1983
+ return this._parent;
1984
+ }
1985
+ set parent(value) {
1986
+ if (this._parent !== value) {
1987
+ this._parent = value;
1988
+ this.parentAtom.reportChanged();
1989
+ }
1886
1990
  }
1887
- setConfiguration(configuration) {
1888
- this.configuration = configuration;
1991
+ setConfiguration(configurationGetter) {
1992
+ this.configurationGetter = configurationGetter;
1993
+ }
1994
+ get configuration() {
1995
+ return this.configurationGetter?.() ?? {};
1889
1996
  }
1890
1997
  getReferencedAtom(name) {
1891
1998
  let a = this.referencedAtoms?.get(name);
@@ -1923,13 +2030,18 @@ const _ModelAdministration = class _ModelAdministration extends PreactObjectAdmi
1923
2030
  }
1924
2031
  }
1925
2032
  setModel(name, newModel) {
1926
- const oldModel = this.getModel(name);
1927
- if (oldModel === newModel) {
2033
+ const currentValue = this.proxy[name];
2034
+ if (currentValue === newModel) {
1928
2035
  return;
1929
2036
  }
1930
2037
  this.activeModels.add(name);
1931
- if (oldModel) {
1932
- getModelAdm(oldModel).detach();
2038
+ if (Array.isArray(currentValue)) {
2039
+ const oldModels = currentValue;
2040
+ oldModels.forEach((child2) => getModelAdm(child2).detach());
2041
+ this.modelsTraceUnsub.get(name)?.();
2042
+ this.modelsTraceUnsub.delete(name);
2043
+ } else if (currentValue) {
2044
+ getModelAdm(currentValue).detach();
1933
2045
  }
1934
2046
  if (newModel) {
1935
2047
  const adm = getModelAdm(newModel);
@@ -1942,17 +2054,21 @@ const _ModelAdministration = class _ModelAdministration extends PreactObjectAdmi
1942
2054
  ChildModelsAdministration
1943
2055
  );
1944
2056
  newModels.push(...newModelsSource);
1945
- const oldModels = this.getModels(name) ?? [];
1946
- if (oldModels === newModels) {
2057
+ const currentValue = this.proxy[name];
2058
+ if (currentValue === newModels) {
1947
2059
  return;
1948
2060
  }
1949
- const oldModelSet = new Set(oldModels);
1950
- const newModelSet = new Set(newModels);
1951
2061
  this.activeModels.add(name);
1952
- oldModels.forEach(
1953
- (child2) => newModelSet.has(child2) || getModelAdm(child2).detach()
1954
- );
1955
- this.modelsTraceUnsub.get(name)?.();
2062
+ if (currentValue && !Array.isArray(currentValue)) {
2063
+ getModelAdm(currentValue).detach();
2064
+ } else if (Array.isArray(currentValue)) {
2065
+ const oldModels = currentValue;
2066
+ const newModelSet = new Set(newModels);
2067
+ oldModels.forEach(
2068
+ (child2) => newModelSet.has(child2) || getModelAdm(child2).detach()
2069
+ );
2070
+ this.modelsTraceUnsub.get(name)?.();
2071
+ }
1956
2072
  PreactObjectAdministration.proxyTraps.set(
1957
2073
  this.source,
1958
2074
  name,
@@ -1972,20 +2088,13 @@ const _ModelAdministration = class _ModelAdministration extends PreactObjectAdmi
1972
2088
  })
1973
2089
  );
1974
2090
  newModels.forEach((child2) => {
2091
+ const oldModelSet = Array.isArray(currentValue) ? new Set(currentValue) : /* @__PURE__ */ new Set();
1975
2092
  if (!oldModelSet.has(child2)) {
1976
2093
  const internalModel = getModelAdm(child2);
1977
2094
  internalModel.attach(this, name);
1978
2095
  }
1979
2096
  });
1980
2097
  }
1981
- getModel(name) {
1982
- const model2 = this.proxy[name];
1983
- return model2 ?? null;
1984
- }
1985
- getModels(name) {
1986
- const model2 = this.proxy[name];
1987
- return model2 ?? [];
1988
- }
1989
2098
  getModelRef(name) {
1990
2099
  const a = this.getReferencedAtom(name);
1991
2100
  a.reportObserved();
@@ -2042,19 +2151,55 @@ const _ModelAdministration = class _ModelAdministration extends PreactObjectAdmi
2042
2151
  this.root = parent.root;
2043
2152
  this.parentName = parentName;
2044
2153
  }
2045
- runInBatch(() => {
2154
+ signalsCore.batch(() => {
2046
2155
  onModelAttached(this.proxy);
2047
2156
  this.proxy.modelDidAttach();
2048
2157
  });
2049
2158
  }
2050
2159
  detach() {
2051
- runInBatch(() => {
2160
+ signalsCore.batch(() => {
2052
2161
  this.proxy.modelWillDetach();
2053
2162
  onModelDetached(this.proxy);
2054
2163
  });
2164
+ this.contextCache.forEach((computed2) => computed2.clear());
2165
+ this.contextCache.clear();
2055
2166
  this.parent = null;
2056
2167
  this.root = this;
2057
2168
  }
2169
+ getContextValue(contextId, provideSymbol, defaultValue, hasDefault) {
2170
+ let computed2 = this.contextCache.get(contextId);
2171
+ if (!computed2) {
2172
+ computed2 = createComputed(() => {
2173
+ return this.lookupContextValue(
2174
+ contextId,
2175
+ provideSymbol,
2176
+ defaultValue,
2177
+ hasDefault
2178
+ );
2179
+ });
2180
+ this.contextCache.set(contextId, computed2);
2181
+ }
2182
+ return computed2.get();
2183
+ }
2184
+ lookupContextValue(contextId, provideSymbol, defaultValue, hasDefault) {
2185
+ const provideMethod = this.source[provideSymbol];
2186
+ if (typeof provideMethod === "function") {
2187
+ return provideMethod.call(this.proxy);
2188
+ }
2189
+ const parent = this.parent;
2190
+ if (parent) {
2191
+ return parent.getContextValue(
2192
+ contextId,
2193
+ provideSymbol,
2194
+ defaultValue,
2195
+ hasDefault
2196
+ );
2197
+ }
2198
+ if (hasDefault) {
2199
+ return defaultValue;
2200
+ }
2201
+ return void 0;
2202
+ }
2058
2203
  toJSON() {
2059
2204
  return Object.keys(this.configuration).reduce((json, key) => {
2060
2205
  switch (this.configuration[key].type) {
@@ -2064,44 +2209,47 @@ const _ModelAdministration = class _ModelAdministration extends PreactObjectAdmi
2064
2209
  break;
2065
2210
  case ModelCfgTypes.modelRef:
2066
2211
  const model2 = this.proxy[key];
2067
- json[key] = model2 && getModelRefSnapshot(model2);
2068
- break;
2069
- case ModelCfgTypes.modelRefs:
2070
- if (!this.snapshotMap.has(key)) {
2071
- this.snapshotMap.set(
2072
- key,
2073
- createComputed(() => {
2074
- const models = this.proxy[key] ?? [];
2075
- return models.map((m) => getModelRefSnapshot(m));
2076
- })
2077
- );
2212
+ if (Array.isArray(model2)) {
2213
+ if (!this.snapshotMap.has(key)) {
2214
+ this.snapshotMap.set(
2215
+ key,
2216
+ createComputed(() => {
2217
+ const models = this.proxy[key] ?? [];
2218
+ return models.map((m) => getModelRefSnapshot(m));
2219
+ })
2220
+ );
2221
+ }
2222
+ json[key] = this.snapshotMap.get(key).get();
2223
+ break;
2078
2224
  }
2079
- json[key] = this.snapshotMap.get(key).get();
2225
+ json[key] = model2 && getModelRefSnapshot(model2);
2080
2226
  break;
2081
2227
  case CommonCfgTypes.child:
2082
- json[key] = getModelAdm(this.proxy[key])?.getSnapshot();
2083
- break;
2084
- case CommonCfgTypes.children:
2085
- if (!this.snapshotMap.has(key)) {
2086
- this.snapshotMap.set(
2087
- key,
2088
- createComputed(() => {
2089
- return getSource(
2090
- (this.proxy[key] ?? []).map(
2091
- (model22) => getModelAdm(model22).getSnapshot()
2092
- )
2093
- );
2094
- })
2095
- );
2228
+ const child2 = this.proxy[key];
2229
+ if (Array.isArray(child2)) {
2230
+ if (!this.snapshotMap.has(key)) {
2231
+ this.snapshotMap.set(
2232
+ key,
2233
+ createComputed(() => {
2234
+ return getSource(
2235
+ (this.proxy[key] ?? []).map(
2236
+ (model22) => getModelAdm(model22).getSnapshot()
2237
+ )
2238
+ );
2239
+ })
2240
+ );
2241
+ }
2242
+ json[key] = this.snapshotMap.get(key).get();
2243
+ break;
2096
2244
  }
2097
- json[key] = this.snapshotMap.get(key).get();
2245
+ json[key] = getModelAdm(child2)?.getSnapshot();
2098
2246
  break;
2099
2247
  }
2100
2248
  return json;
2101
2249
  }, {});
2102
2250
  }
2103
2251
  onSnapshotChange(onChange) {
2104
- return createReaction(
2252
+ return reaction(
2105
2253
  () => this.getSnapshot(),
2106
2254
  (snapshot) => onChange(snapshot, this.proxy)
2107
2255
  );
@@ -2124,29 +2272,53 @@ const _ModelAdministration = class _ModelAdministration extends PreactObjectAdmi
2124
2272
  this.proxy[key] = value;
2125
2273
  break;
2126
2274
  case ModelCfgTypes.modelRef:
2127
- if (value instanceof Model) {
2275
+ if (Array.isArray(value)) {
2276
+ if (value?.[0] instanceof Model) {
2277
+ this.proxy[key] = value;
2278
+ } else {
2279
+ this.source[key] = value.map(
2280
+ (snapshot2) => getSnapshotRefId(snapshot2)
2281
+ );
2282
+ this.referencedAtoms?.get(key)?.reportChanged();
2283
+ }
2284
+ break;
2285
+ } else if (value instanceof Model) {
2128
2286
  this.proxy[key] = value;
2129
2287
  } else {
2130
2288
  this.source[key] = getSnapshotRefId(value);
2131
2289
  this.referencedAtoms?.get(key)?.reportChanged();
2132
2290
  }
2133
2291
  break;
2134
- case ModelCfgTypes.modelRefs:
2135
- if (value?.[0] instanceof Model) {
2136
- this.proxy[key] = value;
2137
- } else {
2138
- this.source[key] = value.map(
2139
- (snapshot2) => getSnapshotRefId(snapshot2)
2140
- );
2141
- this.referencedAtoms?.get(key)?.reportChanged();
2142
- }
2143
- break;
2144
2292
  case ModelCfgTypes.id:
2145
2293
  this.setId(key, value);
2146
2294
  break;
2147
2295
  case CommonCfgTypes.child:
2148
2296
  let model2;
2149
- if (value instanceof Model) {
2297
+ if (Array.isArray(value)) {
2298
+ const Ctor = childType2;
2299
+ this.proxy[key] = value?.map(
2300
+ (snapshot2, index) => {
2301
+ snapshot2 = snapshot2 ?? {};
2302
+ let model22;
2303
+ if (snapshot2 instanceof Model) {
2304
+ model22 = snapshot2;
2305
+ } else {
2306
+ ensureChildTypes(key);
2307
+ const id = childType2 && getSnapshotId(snapshot2, Ctor);
2308
+ const foundModel = id != null ? getModelById(this.root.proxy, id) : this.proxy[key][index];
2309
+ const adm = foundModel && getModelAdm(foundModel);
2310
+ if (adm && foundModel.parent === this.proxy && adm?.parentName === key) {
2311
+ adm.loadSnapshot(snapshot2);
2312
+ model22 = foundModel;
2313
+ } else {
2314
+ model22 = Ctor.create(snapshot2);
2315
+ }
2316
+ }
2317
+ return model22;
2318
+ }
2319
+ );
2320
+ break;
2321
+ } else if (value instanceof Model) {
2150
2322
  model2 = value;
2151
2323
  } else {
2152
2324
  ensureChildTypes(key);
@@ -2161,28 +2333,6 @@ const _ModelAdministration = class _ModelAdministration extends PreactObjectAdmi
2161
2333
  }
2162
2334
  this.proxy[key] = model2;
2163
2335
  break;
2164
- case CommonCfgTypes.children:
2165
- const Ctor = childType2;
2166
- this.proxy[key] = value?.map((snapshot2, index) => {
2167
- snapshot2 = snapshot2 ?? {};
2168
- let model22;
2169
- if (snapshot2 instanceof Model) {
2170
- model22 = snapshot2;
2171
- } else {
2172
- ensureChildTypes(key);
2173
- const id = childType2 && getSnapshotId(snapshot2, Ctor);
2174
- const foundModel = id != null ? getModelById(this.root.proxy, id) : this.proxy[key][index];
2175
- const adm = foundModel && getModelAdm(foundModel);
2176
- if (adm && foundModel.parent === this.proxy && adm?.parentName === key) {
2177
- adm.loadSnapshot(snapshot2);
2178
- model22 = foundModel;
2179
- } else {
2180
- model22 = Ctor.create(snapshot2);
2181
- }
2182
- }
2183
- return model22;
2184
- });
2185
- break;
2186
2336
  default:
2187
2337
  console.warn(
2188
2338
  `r-state-tree: invalid key '${key}' found in snapshot, ignored.`
@@ -2201,87 +2351,13 @@ const _ModelAdministration = class _ModelAdministration extends PreactObjectAdmi
2201
2351
  }
2202
2352
  return this.computedSnapshot.get();
2203
2353
  }
2204
- };
2205
- _ModelAdministration.proxyTraps = Object.assign(
2206
- {},
2207
- PreactObjectAdministration.proxyTraps,
2208
- {
2209
- get(target, prop, proxy) {
2210
- const adm = getAdministration(target);
2211
- if (prop === "parent") {
2212
- return target.parent;
2213
- }
2214
- switch (adm.configuration[prop]?.type) {
2215
- case ModelCfgTypes.modelRef:
2216
- return adm.getModelRef(prop);
2217
- case ModelCfgTypes.modelRefs:
2218
- return adm.getModelRefs(prop);
2219
- default:
2220
- return PreactObjectAdministration.proxyTraps.get?.apply(
2221
- null,
2222
- arguments
2223
- );
2224
- }
2225
- },
2226
- set(target, name, value) {
2227
- const adm = getAdministration(target);
2228
- adm.writeInProgress.add(name);
2229
- try {
2230
- switch (adm.configuration[name]?.type) {
2231
- case ModelCfgTypes.modelRef: {
2232
- adm.setModelRef(name, value);
2233
- return true;
2234
- }
2235
- case ModelCfgTypes.modelRefs: {
2236
- adm.setModelRefs(name, value);
2237
- return true;
2238
- }
2239
- case CommonCfgTypes.children: {
2240
- adm.setModels(name, value);
2241
- return true;
2242
- }
2243
- case CommonCfgTypes.child: {
2244
- adm.setModel(name, value);
2245
- break;
2246
- }
2247
- case ModelCfgTypes.id: {
2248
- adm.setId(name, value);
2249
- break;
2250
- }
2251
- case ModelCfgTypes.state: {
2252
- adm.setState(name, value);
2253
- break;
2254
- }
2255
- }
2256
- return PreactObjectAdministration.proxyTraps.set?.apply(
2257
- null,
2258
- arguments
2259
- );
2260
- } finally {
2261
- adm.writeInProgress.delete(name);
2262
- }
2263
- },
2264
- defineProperty(target, name, desc) {
2265
- const adm = getAdministration(target);
2266
- if (desc && "value" in desc && !adm.writeInProgress.has(name)) {
2267
- switch (adm.configuration[name]?.type) {
2268
- case ModelCfgTypes.modelRef:
2269
- case ModelCfgTypes.modelRefs:
2270
- case CommonCfgTypes.children:
2271
- case CommonCfgTypes.child:
2272
- case ModelCfgTypes.id: {
2273
- adm.proxy[name] = desc.value;
2274
- return true;
2275
- }
2276
- }
2277
- }
2278
- return Reflect.defineProperty(target, name, desc);
2279
- }
2280
- }
2281
- );
2282
- let ModelAdministration = _ModelAdministration;
2354
+ }
2283
2355
  let initEnabled = false;
2284
- const _Model = class _Model {
2356
+ class Model {
2357
+ static get types() {
2358
+ return this[Symbol.metadata];
2359
+ }
2360
+ static childTypes = {};
2285
2361
  static create(snapshot, ...args) {
2286
2362
  let instance;
2287
2363
  try {
@@ -2306,8 +2382,9 @@ const _Model = class _Model {
2306
2382
  ModelAdministration
2307
2383
  );
2308
2384
  const adm = getModelAdm(observable2);
2309
- const config = this.constructor.types;
2310
- adm.setConfiguration(config ?? {});
2385
+ adm.setConfiguration(
2386
+ () => this.constructor.types ?? {}
2387
+ );
2311
2388
  return observable2;
2312
2389
  }
2313
2390
  get parent() {
@@ -2322,10 +2399,7 @@ const _Model = class _Model {
2322
2399
  // eslint-disable-next-line @typescript-eslint/no-empty-function
2323
2400
  modelWillDetach() {
2324
2401
  }
2325
- };
2326
- _Model.types = {};
2327
- _Model.childTypes = {};
2328
- let Model = _Model;
2402
+ }
2329
2403
  function mount(container) {
2330
2404
  return allowNewStore(() => {
2331
2405
  const element = container;
@@ -2363,55 +2437,98 @@ function applySnapshot(model2, snapshot) {
2363
2437
  adm.loadSnapshot(snapshot);
2364
2438
  return model2;
2365
2439
  }
2366
- function makeDecorator(type, asMethod = (val) => makeDecorator(type(val))) {
2367
- return function(...args) {
2368
- if (args.length === 1) {
2369
- return asMethod(args[0]);
2370
- } else {
2371
- const [target, propertyKey, descriptor] = args;
2372
- const Ctor = target.constructor;
2373
- if (Ctor.types === Store.types || Ctor.types === Model.types) {
2374
- Ctor.types = {};
2440
+ const CONTEXT_SYMBOL = Symbol("context");
2441
+ const HAS_DEFAULT = Symbol("hasDefault");
2442
+ function createContext(defaultValue) {
2443
+ const provideSymbol = Symbol("provide");
2444
+ const contextId = Symbol("contextId");
2445
+ const hasDefault = arguments.length > 0;
2446
+ return {
2447
+ [CONTEXT_SYMBOL]: contextId,
2448
+ [HAS_DEFAULT]: hasDefault,
2449
+ defaultValue,
2450
+ provide: provideSymbol,
2451
+ consume(instance) {
2452
+ const adm = getAdministration(instance);
2453
+ if (!adm || typeof adm.getContextValue !== "function") {
2454
+ throw new Error("Context can only be consumed in Models or Stores");
2375
2455
  }
2376
- Ctor.types[propertyKey] = type;
2377
- return descriptor;
2456
+ return adm.getContextValue(
2457
+ contextId,
2458
+ provideSymbol,
2459
+ defaultValue,
2460
+ hasDefault
2461
+ );
2378
2462
  }
2379
2463
  };
2380
2464
  }
2381
- const child = makeDecorator(childType);
2382
- const children = makeDecorator(childrenType);
2465
+ function makeDecorator(type) {
2466
+ return function(value, context) {
2467
+ context.metadata[context.name] = type;
2468
+ return value;
2469
+ };
2470
+ }
2471
+ function makeChildDecorator(typeObj) {
2472
+ return function(valueOrChildType, context) {
2473
+ if (context !== void 0) {
2474
+ return makeDecorator(typeObj)(valueOrChildType, context);
2475
+ }
2476
+ const childCtor = valueOrChildType;
2477
+ return function(value, context2) {
2478
+ const typeWithCtor = typeObj(childCtor);
2479
+ return makeDecorator(typeWithCtor)(value, context2);
2480
+ };
2481
+ };
2482
+ }
2483
+ const child = makeChildDecorator(childType);
2484
+ const modelRef = makeChildDecorator(modelRefType);
2383
2485
  const model = makeDecorator(modelType);
2384
- const modelRef = makeDecorator(modelRefType);
2385
- const modelRefs = makeDecorator(modelRefsType);
2386
2486
  const identifier = makeDecorator(idType);
2387
2487
  const state = makeDecorator(stateType);
2488
+ Object.defineProperty(exports, "ReadonlySignal", {
2489
+ enumerable: true,
2490
+ get: () => signalsCore.ReadonlySignal
2491
+ });
2492
+ Object.defineProperty(exports, "Signal", {
2493
+ enumerable: true,
2494
+ get: () => signalsCore.Signal
2495
+ });
2496
+ Object.defineProperty(exports, "batch", {
2497
+ enumerable: true,
2498
+ get: () => signalsCore.batch
2499
+ });
2500
+ Object.defineProperty(exports, "effect", {
2501
+ enumerable: true,
2502
+ get: () => signalsCore.effect
2503
+ });
2504
+ Object.defineProperty(exports, "signal", {
2505
+ enumerable: true,
2506
+ get: () => signalsCore.signal
2507
+ });
2508
+ Object.defineProperty(exports, "untracked", {
2509
+ enumerable: true,
2510
+ get: () => signalsCore.untracked
2511
+ });
2388
2512
  exports.Model = Model;
2389
2513
  exports.Observable = Observable;
2390
2514
  exports.Store = Store;
2391
2515
  exports.applySnapshot = applySnapshot;
2392
2516
  exports.child = child;
2393
- exports.children = children;
2394
- exports.createAtom = createAtom;
2395
- exports.createComputed = createComputed;
2396
- exports.createEffect = createEffect;
2397
- exports.createListener = createListener;
2398
- exports.createReaction = createReaction;
2399
- exports.createSignal = createSignal;
2517
+ exports.computed = computed;
2518
+ exports.createContext = createContext;
2400
2519
  exports.createStore = createStore;
2401
2520
  exports.getSignal = getSignal;
2402
2521
  exports.identifier = identifier;
2403
2522
  exports.isObservable = isObservable;
2404
2523
  exports.model = model;
2405
2524
  exports.modelRef = modelRef;
2406
- exports.modelRefs = modelRefs;
2407
2525
  exports.mount = mount;
2408
2526
  exports.observable = observable;
2409
2527
  exports.onSnapshot = onSnapshot;
2410
2528
  exports.onSnapshotDiff = onSnapshotDiff;
2529
+ exports.reaction = reaction;
2411
2530
  exports.reportChanged = reportChanged;
2412
2531
  exports.reportObserved = reportObserved;
2413
- exports.runInBatch = runInBatch;
2414
- exports.runInUntracked = runInUntracked;
2415
2532
  exports.source = source;
2416
2533
  exports.state = state;
2417
2534
  exports.toSnapshot = toSnapshot;