mobx 6.1.8 → 6.3.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 (45) hide show
  1. package/CHANGELOG.md +57 -5
  2. package/README.md +2 -1
  3. package/dist/api/annotation.d.ts +6 -12
  4. package/dist/api/flow.d.ts +1 -0
  5. package/dist/api/object-api.d.ts +2 -0
  6. package/dist/errors.d.ts +2 -0
  7. package/dist/internal.d.ts +1 -0
  8. package/dist/mobx.cjs.development.js +322 -310
  9. package/dist/mobx.cjs.development.js.map +1 -1
  10. package/dist/mobx.cjs.production.min.js +1 -1
  11. package/dist/mobx.cjs.production.min.js.map +1 -1
  12. package/dist/mobx.d.ts +1 -1
  13. package/dist/mobx.esm.development.js +320 -311
  14. package/dist/mobx.esm.development.js.map +1 -1
  15. package/dist/mobx.esm.js +320 -311
  16. package/dist/mobx.esm.js.map +1 -1
  17. package/dist/mobx.esm.production.min.js +1 -1
  18. package/dist/mobx.esm.production.min.js.map +1 -1
  19. package/dist/mobx.umd.development.js +322 -310
  20. package/dist/mobx.umd.development.js.map +1 -1
  21. package/dist/mobx.umd.production.min.js +1 -1
  22. package/dist/mobx.umd.production.min.js.map +1 -1
  23. package/dist/types/actionannotation.d.ts +7 -1
  24. package/dist/types/autoannotation.d.ts +3 -0
  25. package/dist/types/observableobject.d.ts +4 -7
  26. package/package.json +1 -1
  27. package/src/api/annotation.ts +13 -42
  28. package/src/api/flow.ts +6 -1
  29. package/src/api/makeObservable.ts +25 -34
  30. package/src/api/object-api.ts +14 -0
  31. package/src/api/observable.ts +3 -8
  32. package/src/api/tojs.ts +10 -7
  33. package/src/core/observable.ts +7 -6
  34. package/src/errors.ts +14 -1
  35. package/src/internal.ts +1 -0
  36. package/src/mobx.ts +4 -0
  37. package/src/types/actionannotation.ts +27 -51
  38. package/src/types/autoannotation.ts +107 -0
  39. package/src/types/computedannotation.ts +7 -37
  40. package/src/types/dynamicobject.ts +1 -1
  41. package/src/types/flowannotation.ts +31 -42
  42. package/src/types/modifiers.ts +13 -2
  43. package/src/types/observableannotation.ts +7 -34
  44. package/src/types/observableobject.ts +34 -63
  45. package/src/types/overrideannotation.ts +4 -2
@@ -9,6 +9,18 @@
9
9
  1: function _(annotationType, key) {
10
10
  return "Cannot apply '" + annotationType + "' to '" + key.toString() + "': Field not found.";
11
11
  },
12
+
13
+ /*
14
+ 2(prop) {
15
+ return `invalid decorator for '${prop.toString()}'`
16
+ },
17
+ 3(prop) {
18
+ return `Cannot decorate '${prop.toString()}': action can only be used on properties with a function value.`
19
+ },
20
+ 4(prop) {
21
+ return `Cannot decorate '${prop.toString()}': computed can only be used on getter properties.`
22
+ },
23
+ */
12
24
  5: "'keys()' can only be used on observable objects, arrays, sets and maps",
13
25
  6: "'values()' can only be used on observable objects, arrays, sets and maps",
14
26
  7: "'entries()' can only be used on observable objects, arrays and maps",
@@ -65,7 +77,9 @@
65
77
  36: "isolateGlobalState should be called before MobX is running any reactions",
66
78
  37: function _(method) {
67
79
  return "[mobx] `observableArray." + method + "()` mutates the array in-place, which is not allowed inside a derivation. Use `array.slice()." + method + "()` instead";
68
- }
80
+ },
81
+ 38: "'ownKeys()' can only be used on observable objects",
82
+ 39: "'defineProperty()' can only be used on observable objects"
69
83
  };
70
84
  var errors = niceErrors ;
71
85
  function die(error) {
@@ -528,6 +542,15 @@
528
542
  if (isES6Set(v)) return observable.set(v, {
529
543
  name: name
530
544
  });
545
+
546
+ if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
547
+ if (isGenerator(v)) {
548
+ return flow(v);
549
+ } else {
550
+ return autoAction(name, v);
551
+ }
552
+ }
553
+
531
554
  return v;
532
555
  }
533
556
  function shallowEnhancer(v, _, name) {
@@ -581,6 +604,10 @@
581
604
  if ( !hasProp(adm.appliedAnnotations_, key)) {
582
605
  die("'" + adm.name_ + "." + key.toString() + "' is annotated with '" + this.annotationType_ + "', " + "but no such annotated member was found on prototype.");
583
606
  }
607
+
608
+ return 0
609
+ /* Cancel */
610
+ ;
584
611
  }
585
612
 
586
613
  function extend_(adm, key, descriptor, proxyTrap) {
@@ -596,65 +623,41 @@
596
623
  };
597
624
  }
598
625
 
599
- function make_$1(adm, key) {
600
- var _this$options_$bound, _this$options_, _adm$target_$storedAn;
626
+ function make_$1(adm, key, descriptor, source) {
627
+ var _this$options_;
601
628
 
602
- var annotated = false;
603
- var source = adm.target_;
604
- var bound = (_this$options_$bound = (_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) != null ? _this$options_$bound : false;
629
+ // bound
630
+ if ((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) {
631
+ return this.extend_(adm, key, descriptor, false) === null ? 0
632
+ /* Cancel */
633
+ : 1
634
+ /* Break */
635
+ ;
636
+ } // own
605
637
 
606
- while (source && source !== objectPrototype) {
607
- var descriptor = getDescriptor(source, key);
608
638
 
609
- if (descriptor) {
610
- // Instance or bound
611
- // Keep first because the operation can be intercepted
612
- // and we don't want to end up with partially annotated proto chain
613
- if (source === adm.target_ || bound) {
614
- var actionDescriptor = createActionDescriptor(adm, this, key, descriptor);
615
- var definePropertyOutcome = adm.defineProperty_(key, actionDescriptor);
639
+ if (source === adm.target_) {
640
+ return this.extend_(adm, key, descriptor, false) === null ? 0
641
+ /* Cancel */
642
+ : 2
643
+ /* Continue */
644
+ ;
645
+ } // prototype
616
646
 
617
- if (!definePropertyOutcome) {
618
- // Intercepted
619
- return;
620
- }
621
-
622
- annotated = true; // Don't annotate protos if bound
623
-
624
- if (bound) {
625
- break;
626
- }
627
- } // Prototype
628
-
629
-
630
- if (source !== adm.target_) {
631
- if (isAction(descriptor.value)) {
632
- // A prototype could have been annotated already by other constructor,
633
- // rest of the proto chain must be annotated already
634
- annotated = true;
635
- break;
636
- }
637
-
638
- var _actionDescriptor = createActionDescriptor(adm, this, key, descriptor, false);
639
-
640
- defineProperty(source, key, _actionDescriptor);
641
- annotated = true;
642
- }
643
- }
644
647
 
645
- source = Object.getPrototypeOf(source);
648
+ if (isAction(descriptor.value)) {
649
+ // A prototype could have been annotated already by other constructor,
650
+ // rest of the proto chain must be annotated already
651
+ return 1
652
+ /* Break */
653
+ ;
646
654
  }
647
655
 
648
- if (annotated) {
649
- recordAnnotationApplied(adm, this, key);
650
- } else if (!((_adm$target_$storedAn = adm.target_[storedAnnotationsSymbol]) == null ? void 0 : _adm$target_$storedAn[key])) {
651
- // Throw on missing key, except for decorators:
652
- // Decorator annotations are collected from whole prototype chain.
653
- // When called from super() some props may not exist yet.
654
- // However we don't have to worry about missing prop,
655
- // because the decorator must have been applied to something.
656
- die(1, this.annotationType_, adm.name_ + "." + key.toString());
657
- }
656
+ var actionDescriptor = createActionDescriptor(adm, this, key, descriptor, false);
657
+ defineProperty(source, key, actionDescriptor);
658
+ return 2
659
+ /* Continue */
660
+ ;
658
661
  }
659
662
 
660
663
  function extend_$1(adm, key, descriptor, proxyTrap) {
@@ -710,58 +713,45 @@
710
713
  };
711
714
  }
712
715
 
713
- function make_$2(adm, key) {
714
- var _adm$target_$storedAn;
715
-
716
- var annotated = false;
717
- var source = adm.target_;
718
-
719
- while (source && source !== objectPrototype) {
720
- var descriptor = getDescriptor(source, key);
721
-
722
- if (descriptor) {
723
- if (source !== adm.target_) {
724
- // Prototype
725
- if (isFlow(descriptor.value)) {
726
- // A prototype could have been annotated already by other constructor,
727
- // rest of the proto chain must be annotated already
728
- annotated = true;
729
- break;
730
- }
731
-
732
- var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false);
733
- defineProperty(source, key, flowDescriptor);
734
- } else {
735
- var _flowDescriptor = createFlowDescriptor(adm, this, key, descriptor);
736
-
737
- var definePropertyOutcome = adm.defineProperty_(key, _flowDescriptor);
716
+ function make_$2(adm, key, descriptor, source) {
717
+ var _this$options_;
738
718
 
739
- if (!definePropertyOutcome) {
740
- // Intercepted
741
- return;
742
- }
743
- }
719
+ // own
720
+ if (source === adm.target_) {
721
+ return this.extend_(adm, key, descriptor, false) === null ? 0
722
+ /* Cancel */
723
+ : 2
724
+ /* Continue */
725
+ ;
726
+ } // prototype
727
+ // bound - must annotate protos to support super.flow()
744
728
 
745
- annotated = true;
746
- }
747
729
 
748
- source = Object.getPrototypeOf(source);
730
+ if (((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) && !isFlow(adm.target_[key])) {
731
+ if (this.extend_(adm, key, descriptor, false) === null) return 0
732
+ /* Cancel */
733
+ ;
749
734
  }
750
735
 
751
- if (annotated) {
752
- recordAnnotationApplied(adm, this, key);
753
- } else if (!((_adm$target_$storedAn = adm.target_[storedAnnotationsSymbol]) == null ? void 0 : _adm$target_$storedAn[key])) {
754
- // Throw on missing key, except for decorators:
755
- // Decorator annotations are collected from whole prototype chain.
756
- // When called from super() some props may not exist yet.
757
- // However we don't have to worry about missing prop,
758
- // because the decorator must have been applied to something.
759
- die(1, this.annotationType_, adm.name_ + "." + key.toString());
736
+ if (isFlow(descriptor.value)) {
737
+ // A prototype could have been annotated already by other constructor,
738
+ // rest of the proto chain must be annotated already
739
+ return 1
740
+ /* Break */
741
+ ;
760
742
  }
743
+
744
+ var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false, false);
745
+ defineProperty(source, key, flowDescriptor);
746
+ return 2
747
+ /* Continue */
748
+ ;
761
749
  }
762
750
 
763
751
  function extend_$2(adm, key, descriptor, proxyTrap) {
764
- var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor);
752
+ var _this$options_2;
753
+
754
+ var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, (_this$options_2 = this.options_) == null ? void 0 : _this$options_2.bound);
765
755
  return adm.defineProperty_(key, flowDescriptor, proxyTrap);
766
756
  }
767
757
 
@@ -774,15 +764,23 @@
774
764
  }
775
765
  }
776
766
 
777
- function createFlowDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
767
+ function createFlowDescriptor(adm, annotation, key, descriptor, bound, // provides ability to disable safeDescriptors for prototypes
778
768
  safeDescriptors) {
779
769
  if (safeDescriptors === void 0) {
780
770
  safeDescriptors = globalState.safeDescriptors;
781
771
  }
782
772
 
783
773
  assertFlowDescriptor(adm, annotation, key, descriptor);
774
+ var value = descriptor.value;
775
+
776
+ if (bound) {
777
+ var _adm$proxy_;
778
+
779
+ value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
780
+ }
781
+
784
782
  return {
785
- value: flow(descriptor.value),
783
+ value: flow(value),
786
784
  // Non-configurable for classes
787
785
  // prevents accidental field redefinition in subclass
788
786
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -803,41 +801,12 @@
803
801
  };
804
802
  }
805
803
 
806
- function make_$3(adm, key) {
807
- var _adm$target_$storedAn;
808
-
809
- var source = adm.target_;
810
-
811
- while (source && source !== objectPrototype) {
812
- var descriptor = getDescriptor(source, key);
813
-
814
- if (descriptor) {
815
- assertComputedDescriptor(adm, this, key, descriptor);
816
- var definePropertyOutcome = adm.defineComputedProperty_(key, _extends({}, this.options_, {
817
- get: descriptor.get,
818
- set: descriptor.set
819
- }));
820
-
821
- if (!definePropertyOutcome) {
822
- // Intercepted
823
- return;
824
- }
825
-
826
- recordAnnotationApplied(adm, this, key);
827
- return;
828
- }
829
-
830
- source = Object.getPrototypeOf(source);
831
- }
832
-
833
- if (!((_adm$target_$storedAn = adm.target_[storedAnnotationsSymbol]) == null ? void 0 : _adm$target_$storedAn[key])) {
834
- // Throw on missing key, except for decorators:
835
- // Decorator annotations are collected from whole prototype chain.
836
- // When called from super() some props may not exist yet.
837
- // However we don't have to worry about missing prop,
838
- // because the decorator must have been applied to something.
839
- die(1, this.annotationType_, adm.name_ + "." + key.toString());
840
- }
804
+ function make_$3(adm, key, descriptor) {
805
+ return this.extend_(adm, key, descriptor, false) === null ? 0
806
+ /* Cancel */
807
+ : 1
808
+ /* Break */
809
+ ;
841
810
  }
842
811
 
843
812
  function extend_$3(adm, key, descriptor, proxyTrap) {
@@ -866,56 +835,130 @@
866
835
  };
867
836
  }
868
837
 
869
- function make_$4(adm, key) {
870
- var _adm$target_$storedAn;
838
+ function make_$4(adm, key, descriptor) {
839
+ return this.extend_(adm, key, descriptor, false) === null ? 0
840
+ /* Cancel */
841
+ : 1
842
+ /* Break */
843
+ ;
844
+ }
871
845
 
872
- var source = adm.target_; // Copy props from proto as well, see test:
873
- // "decorate should work with Object.create"
846
+ function extend_$4(adm, key, descriptor, proxyTrap) {
847
+ var _this$options_$enhanc, _this$options_;
848
+
849
+ assertObservableDescriptor(adm, this, key, descriptor);
850
+ return adm.defineObservableProperty_(key, descriptor.value, (_this$options_$enhanc = (_this$options_ = this.options_) == null ? void 0 : _this$options_.enhancer) != null ? _this$options_$enhanc : deepEnhancer, proxyTrap);
851
+ }
852
+
853
+ function assertObservableDescriptor(adm, _ref, key, descriptor) {
854
+ var annotationType_ = _ref.annotationType_;
855
+
856
+ if ( !("value" in descriptor)) {
857
+ die("Cannot apply '" + annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + annotationType_ + "' cannot be used on getter/setter properties"));
858
+ }
859
+ }
874
860
 
875
- while (source && source !== objectPrototype) {
876
- var descriptor = getDescriptor(source, key);
861
+ var AUTO = "true";
862
+ var autoAnnotation = /*#__PURE__*/createAutoAnnotation();
863
+ function createAutoAnnotation(options) {
864
+ return {
865
+ annotationType_: AUTO,
866
+ options_: options,
867
+ make_: make_$5,
868
+ extend_: extend_$5
869
+ };
870
+ }
877
871
 
878
- if (descriptor) {
879
- var _this$options_$enhanc, _this$options_;
872
+ function make_$5(adm, key, descriptor, source) {
873
+ var _this$options_3, _this$options_4;
880
874
 
881
- assertObservableDescriptor(adm, this, key, descriptor);
882
- var definePropertyOutcome = adm.defineObservableProperty_(key, descriptor.value, (_this$options_$enhanc = (_this$options_ = this.options_) == null ? void 0 : _this$options_.enhancer) != null ? _this$options_$enhanc : deepEnhancer);
875
+ // getter -> computed
876
+ if (descriptor.get) {
877
+ return computed.make_(adm, key, descriptor, source);
878
+ } // lone setter -> action setter
883
879
 
884
- if (!definePropertyOutcome) {
885
- // Intercepted
886
- return;
887
- }
888
880
 
889
- recordAnnotationApplied(adm, this, key);
890
- return;
881
+ if (descriptor.set) {
882
+ // TODO make action applicable to setter and delegate to action.make_
883
+ var set = createAction(key.toString(), descriptor.set); // own
884
+
885
+ if (source === adm.target_) {
886
+ return adm.defineProperty_(key, {
887
+ configurable: globalState.safeDescriptors ? adm.isPlainObject_ : true,
888
+ set: set
889
+ }) === null ? 0
890
+ /* Cancel */
891
+ : 2
892
+ /* Continue */
893
+ ;
894
+ } // proto
895
+
896
+
897
+ defineProperty(source, key, {
898
+ configurable: true,
899
+ set: set
900
+ });
901
+ return 2
902
+ /* Continue */
903
+ ;
904
+ } // function on proto -> autoAction/flow
905
+
906
+
907
+ if (source !== adm.target_ && typeof descriptor.value === "function") {
908
+ var _this$options_2;
909
+
910
+ if (isGenerator(descriptor.value)) {
911
+ var _this$options_;
912
+
913
+ var flowAnnotation = ((_this$options_ = this.options_) == null ? void 0 : _this$options_.autoBind) ? flow.bound : flow;
914
+ return flowAnnotation.make_(adm, key, descriptor, source);
891
915
  }
892
916
 
893
- source = Object.getPrototypeOf(source);
894
- }
917
+ var actionAnnotation = ((_this$options_2 = this.options_) == null ? void 0 : _this$options_2.autoBind) ? autoAction.bound : autoAction;
918
+ return actionAnnotation.make_(adm, key, descriptor, source);
919
+ } // other -> observable
920
+ // Copy props from proto as well, see test:
921
+ // "decorate should work with Object.create"
922
+
923
+
924
+ var observableAnnotation = ((_this$options_3 = this.options_) == null ? void 0 : _this$options_3.deep) === false ? observable.ref : observable; // if function respect autoBind option
895
925
 
896
- if (!((_adm$target_$storedAn = adm.target_[storedAnnotationsSymbol]) == null ? void 0 : _adm$target_$storedAn[key])) {
897
- // Throw on missing key, except for decorators:
898
- // Decorator annotations are collected from whole prototype chain.
899
- // When called from super() some props may not exist yet.
900
- // However we don't have to worry about missing prop,
901
- // because the decorator must have been applied to something.
902
- die(1, this.annotationType_, adm.name_ + "." + key.toString());
926
+ if (typeof descriptor.value === "function" && ((_this$options_4 = this.options_) == null ? void 0 : _this$options_4.autoBind)) {
927
+ var _adm$proxy_;
928
+
929
+ descriptor.value = descriptor.value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
903
930
  }
931
+
932
+ return observableAnnotation.make_(adm, key, descriptor, source);
904
933
  }
905
934
 
906
- function extend_$4(adm, key, descriptor, proxyTrap) {
907
- var _this$options_$enhanc2, _this$options_2;
935
+ function extend_$5(adm, key, descriptor, proxyTrap) {
936
+ var _this$options_5, _this$options_6;
908
937
 
909
- assertObservableDescriptor(adm, this, key, descriptor);
910
- return adm.defineObservableProperty_(key, descriptor.value, (_this$options_$enhanc2 = (_this$options_2 = this.options_) == null ? void 0 : _this$options_2.enhancer) != null ? _this$options_$enhanc2 : deepEnhancer, proxyTrap);
911
- }
938
+ // getter -> computed
939
+ if (descriptor.get) {
940
+ return computed.extend_(adm, key, descriptor, proxyTrap);
941
+ } // lone setter -> action setter
912
942
 
913
- function assertObservableDescriptor(adm, _ref, key, descriptor) {
914
- var annotationType_ = _ref.annotationType_;
915
943
 
916
- if ( !("value" in descriptor)) {
917
- die("Cannot apply '" + annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + annotationType_ + "' cannot be used on getter/setter properties"));
944
+ if (descriptor.set) {
945
+ // TODO make action applicable to setter and delegate to action.extend_
946
+ return adm.defineProperty_(key, {
947
+ configurable: globalState.safeDescriptors ? adm.isPlainObject_ : true,
948
+ set: createAction(key.toString(), descriptor.set)
949
+ }, proxyTrap);
950
+ } // other -> observable
951
+ // if function respect autoBind option
952
+
953
+
954
+ if (typeof descriptor.value === "function" && ((_this$options_5 = this.options_) == null ? void 0 : _this$options_5.autoBind)) {
955
+ var _adm$proxy_2;
956
+
957
+ descriptor.value = descriptor.value.bind((_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_);
918
958
  }
959
+
960
+ var observableAnnotation = ((_this$options_6 = this.options_) == null ? void 0 : _this$options_6.deep) === false ? observable.ref : observable;
961
+ return observableAnnotation.extend_(adm, key, descriptor, proxyTrap);
919
962
  }
920
963
 
921
964
  // in the majority of cases
@@ -945,7 +988,9 @@
945
988
  return options.deep === true ? deepEnhancer : options.deep === false ? referenceEnhancer : getEnhancerFromAnnotation(options.defaultDecorator);
946
989
  }
947
990
  function getAnnotationFromOptions(options) {
948
- return options ? options.deep === true ? observableAnnotation : options.deep === false ? observableRefAnnotation : options.defaultDecorator : undefined;
991
+ var _options$defaultDecor;
992
+
993
+ return options ? (_options$defaultDecor = options.defaultDecorator) != null ? _options$defaultDecor : createAutoAnnotation(options) : undefined;
949
994
  }
950
995
  function getEnhancerFromAnnotation(annotation) {
951
996
  var _annotation$options_$, _annotation$options_;
@@ -2129,8 +2174,16 @@
2129
2174
  if (observable.lowestObserverState_ === IDerivationState_.STALE_) return;
2130
2175
  observable.lowestObserverState_ = IDerivationState_.STALE_;
2131
2176
  observable.observers_.forEach(function (d) {
2132
- if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) d.dependenciesState_ = IDerivationState_.STALE_;else if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_ // this happens during computing of `d`, just keep lowestObserverState up to date.
2133
- ) observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
2177
+ if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
2178
+ d.dependenciesState_ = IDerivationState_.STALE_;
2179
+
2180
+ if ( d.isTracing_ !== TraceMode.NONE) {
2181
+ logTraceInfo(d, observable);
2182
+ }
2183
+ } else if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_ // this happens during computing of `d`, just keep lowestObserverState up to date.
2184
+ ) {
2185
+ observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
2186
+ }
2134
2187
  }); // invariantLOS(observable, "confirmed end");
2135
2188
  } // Used by computed when its dependency changed, but we don't wan't to immediately recompute.
2136
2189
 
@@ -2141,11 +2194,6 @@
2141
2194
  observable.observers_.forEach(function (d) {
2142
2195
  if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
2143
2196
  d.dependenciesState_ = IDerivationState_.POSSIBLY_STALE_;
2144
-
2145
- if ( d.isTracing_ !== TraceMode.NONE) {
2146
- logTraceInfo(d, observable);
2147
- }
2148
-
2149
2197
  d.onBecomeStale_();
2150
2198
  }
2151
2199
  }); // invariantLOS(observable, "maybe end");
@@ -2775,6 +2823,9 @@
2775
2823
  return error instanceof FlowCancellationError;
2776
2824
  }
2777
2825
  var flowAnnotation = /*#__PURE__*/createFlowAnnotation("flow");
2826
+ var flowBoundAnnotation = /*#__PURE__*/createFlowAnnotation("flow.bound", {
2827
+ bound: true
2828
+ });
2778
2829
  var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
2779
2830
  // @flow
2780
2831
  if (isStringish(arg2)) {
@@ -2860,6 +2911,7 @@
2860
2911
  res.isMobXFlow = true;
2861
2912
  return res;
2862
2913
  }, flowAnnotation);
2914
+ flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
2863
2915
 
2864
2916
  function cancelPromise(promise) {
2865
2917
  if (isFunction(promise.cancel)) promise.cancel();
@@ -3084,6 +3136,20 @@
3084
3136
 
3085
3137
  die(11);
3086
3138
  }
3139
+ function apiDefineProperty(obj, key, descriptor) {
3140
+ if (isObservableObject(obj)) {
3141
+ return obj[$mobx].defineProperty_(key, descriptor);
3142
+ }
3143
+
3144
+ die(39);
3145
+ }
3146
+ function apiOwnKeys(obj) {
3147
+ if (isObservableObject(obj)) {
3148
+ return obj[$mobx].ownKeys_();
3149
+ }
3150
+
3151
+ die(38);
3152
+ }
3087
3153
 
3088
3154
  function observe(thing, propOrCb, cbOrFire, fireImmediately) {
3089
3155
  if (isFunction(cbOrFire)) return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);else return observeObservable(thing, propOrCb, cbOrFire);
@@ -3104,7 +3170,7 @@
3104
3170
 
3105
3171
  function toJSHelper(source, __alreadySeen) {
3106
3172
  if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) return source;
3107
- if (isObservableValue(source)) return toJSHelper(source.get(), __alreadySeen);
3173
+ if (isObservableValue(source) || isComputedValue(source)) return toJSHelper(source.get(), __alreadySeen);
3108
3174
 
3109
3175
  if (__alreadySeen.has(source)) {
3110
3176
  return __alreadySeen.get(source);
@@ -3136,12 +3202,12 @@
3136
3202
  return _res2;
3137
3203
  } else {
3138
3204
  // must be observable object
3139
- keys(source); // make sure keys are observed
3140
-
3141
3205
  var _res3 = cache(__alreadySeen, source, {});
3142
3206
 
3143
- getPlainObjectKeys(source).forEach(function (key) {
3144
- _res3[key] = toJSHelper(source[key], __alreadySeen);
3207
+ apiOwnKeys(source).forEach(function (key) {
3208
+ if (objectPrototype.propertyIsEnumerable.call(source, key)) {
3209
+ _res3[key] = toJSHelper(source[key], __alreadySeen);
3210
+ }
3145
3211
  });
3146
3212
  return _res3;
3147
3213
  }
@@ -3311,7 +3377,7 @@
3311
3377
  return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
3312
3378
  },
3313
3379
  ownKeys: function ownKeys(target) {
3314
- if ( globalState.trackingDerivation) warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use `keys` from 'mobx' instead.");
3380
+ if ( globalState.trackingDerivation) warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
3315
3381
  return getAdm(target).ownKeys_();
3316
3382
  },
3317
3383
  preventExtensions: function preventExtensions(target) {
@@ -3398,57 +3464,39 @@
3398
3464
  }
3399
3465
 
3400
3466
  return target;
3401
- }
3467
+ } // proto[keysSymbol] = new Set<PropertyKey>()
3468
+
3469
+ var keysSymbol = /*#__PURE__*/Symbol("mobx-keys");
3402
3470
  function makeAutoObservable(target, overrides, options) {
3403
3471
  {
3404
3472
  if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) die("'makeAutoObservable' can only be used for classes that don't have a superclass");
3405
3473
  if (isObservableObject(target)) die("makeAutoObservable can only be used on objects not already made observable");
3406
- } // Optimization (avoids visiting protos)
3407
- // assumes that annotation.make_/.extend_ works the same for plain objects
3474
+ } // Optimization: avoid visiting protos
3475
+ // Assumes that annotation.make_/.extend_ works the same for plain objects
3408
3476
 
3409
3477
 
3410
3478
  if (isPlainObject(target)) {
3411
3479
  return extendObservable(target, target, overrides, options);
3412
3480
  }
3413
3481
 
3414
- var adm = asObservableObject(target, options)[$mobx];
3415
- startBatch();
3416
-
3417
- try {
3418
- // Use cached inferred annotations if available (only in classes)
3419
- if (target[inferredAnnotationsSymbol]) {
3420
- target[inferredAnnotationsSymbol].forEach(function (value, key) {
3421
- return adm.make_(key, value);
3422
- }); // Overrides are not cached, unless `true`, see #2832
3423
-
3424
- if (overrides) {
3425
- ownKeys(overrides).forEach(function (key) {
3426
- var annotation = overrides[key];
3427
-
3428
- if (annotation !== true) {
3429
- adm.make_(key, annotation);
3430
- }
3431
- });
3432
- }
3433
- } else {
3434
- var _ignoreKeys;
3435
-
3436
- var ignoreKeys = (_ignoreKeys = {}, _ignoreKeys[$mobx] = 1, _ignoreKeys[inferredAnnotationsSymbol] = 1, _ignoreKeys.constructor = 1, _ignoreKeys);
3482
+ var adm = asObservableObject(target, options)[$mobx]; // Optimization: cache keys on proto
3483
+ // Assumes makeAutoObservable can be called only once per object and can't be used in subclass
3437
3484
 
3438
- var make = function make(key) {
3439
- if (ignoreKeys[key]) return;
3440
- ignoreKeys[key] = 1;
3441
- adm.make_(key, // must pass "undefined" for { key: undefined }
3442
- !overrides ? true : key in overrides ? overrides[key] : true);
3443
- };
3485
+ if (!target[keysSymbol]) {
3486
+ var proto = Object.getPrototypeOf(target);
3487
+ var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
3488
+ keys["delete"]("constructor");
3489
+ keys["delete"]($mobx);
3490
+ addHiddenProp(proto, keysSymbol, keys);
3491
+ }
3444
3492
 
3445
- var current = target;
3493
+ startBatch();
3446
3494
 
3447
- while (current && current !== objectPrototype) {
3448
- ownKeys(current).forEach(make);
3449
- current = Object.getPrototypeOf(current);
3450
- }
3451
- }
3495
+ try {
3496
+ target[keysSymbol].forEach(function (key) {
3497
+ return adm.make_(key, // must pass "undefined" for { key: undefined }
3498
+ !overrides ? true : key in overrides ? overrides[key] : true);
3499
+ });
3452
3500
  } finally {
3453
3501
  endBatch();
3454
3502
  }
@@ -4654,30 +4702,23 @@
4654
4702
 
4655
4703
  var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
4656
4704
 
4657
- var inferredAnnotationsSymbol = /*#__PURE__*/Symbol("mobx-inferred-annotations");
4658
4705
  var descriptorCache = /*#__PURE__*/Object.create(null);
4659
4706
  var REMOVE = "remove";
4660
4707
  var ObservableObjectAdministration = /*#__PURE__*/function () {
4661
4708
  function ObservableObjectAdministration(target_, values_, name_, // Used anytime annotation is not explicitely provided
4662
- defaultAnnotation_, // Bind automatically inferred actions?
4663
- autoBind_) {
4709
+ defaultAnnotation_) {
4664
4710
  if (values_ === void 0) {
4665
4711
  values_ = new Map();
4666
4712
  }
4667
4713
 
4668
4714
  if (defaultAnnotation_ === void 0) {
4669
- defaultAnnotation_ = observable;
4670
- }
4671
-
4672
- if (autoBind_ === void 0) {
4673
- autoBind_ = false;
4715
+ defaultAnnotation_ = autoAnnotation;
4674
4716
  }
4675
4717
 
4676
4718
  this.target_ = void 0;
4677
4719
  this.values_ = void 0;
4678
4720
  this.name_ = void 0;
4679
4721
  this.defaultAnnotation_ = void 0;
4680
- this.autoBind_ = void 0;
4681
4722
  this.keysAtom_ = void 0;
4682
4723
  this.changeListeners_ = void 0;
4683
4724
  this.interceptors_ = void 0;
@@ -4689,7 +4730,6 @@
4689
4730
  this.values_ = values_;
4690
4731
  this.name_ = name_;
4691
4732
  this.defaultAnnotation_ = defaultAnnotation_;
4692
- this.autoBind_ = autoBind_;
4693
4733
  this.keysAtom_ = new Atom( this.name_ + ".keys" ); // Optimization: we use this frequently
4694
4734
 
4695
4735
  this.isPlainObject_ = isPlainObject(this.target_);
@@ -4698,10 +4738,6 @@
4698
4738
  die("defaultAnnotation must be valid annotation");
4699
4739
  }
4700
4740
 
4701
- if ( typeof this.autoBind_ !== "boolean") {
4702
- die("autoBind must be boolean");
4703
- }
4704
-
4705
4741
  {
4706
4742
  // Prepare structure for tracking which fields were already annotated
4707
4743
  this.appliedAnnotations_ = {};
@@ -4770,7 +4806,7 @@
4770
4806
  /**
4771
4807
  * @param {PropertyKey} key
4772
4808
  * @param {any} value
4773
- * @param {Annotation|boolean} annotation true - infer from descriptor, false - copy as is
4809
+ * @param {Annotation|boolean} annotation true - use default annotation, false - copy as is
4774
4810
  * @param {boolean} proxyTrap whether it's called from proxy trap
4775
4811
  * @returns {boolean|null} true on success, false on failure (proxyTrap + non-configurable), null when cancelled by interceptor
4776
4812
  */
@@ -4825,13 +4861,13 @@
4825
4861
  }
4826
4862
  /**
4827
4863
  * @param {PropertyKey} key
4828
- * @param {Annotation|boolean} annotation true - infer from object or it's prototype, false - ignore
4864
+ * @param {Annotation|boolean} annotation true - use default annotation, false - ignore prop
4829
4865
  */
4830
4866
  ;
4831
4867
 
4832
4868
  _proto.make_ = function make_(key, annotation) {
4833
4869
  if (annotation === true) {
4834
- annotation = this.inferAnnotation_(key);
4870
+ annotation = this.defaultAnnotation_;
4835
4871
  }
4836
4872
 
4837
4873
  if (annotation === false) {
@@ -4839,12 +4875,46 @@
4839
4875
  }
4840
4876
 
4841
4877
  assertAnnotable(this, annotation, key);
4842
- annotation.make_(this, key);
4878
+
4879
+ if (!(key in this.target_)) {
4880
+ var _this$target_$storedA;
4881
+
4882
+ // Throw on missing key, except for decorators:
4883
+ // Decorator annotations are collected from whole prototype chain.
4884
+ // When called from super() some props may not exist yet.
4885
+ // However we don't have to worry about missing prop,
4886
+ // because the decorator must have been applied to something.
4887
+ if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
4888
+ return; // will be annotated by subclass constructor
4889
+ } else {
4890
+ die(1, annotation.annotationType_, this.name_ + "." + key.toString());
4891
+ }
4892
+ }
4893
+
4894
+ var source = this.target_;
4895
+
4896
+ while (source && source !== objectPrototype) {
4897
+ var descriptor = getDescriptor(source, key);
4898
+
4899
+ if (descriptor) {
4900
+ var outcome = annotation.make_(this, key, descriptor, source);
4901
+ if (outcome === 0
4902
+ /* Cancel */
4903
+ ) return;
4904
+ if (outcome === 1
4905
+ /* Break */
4906
+ ) break;
4907
+ }
4908
+
4909
+ source = Object.getPrototypeOf(source);
4910
+ }
4911
+
4912
+ recordAnnotationApplied(this, annotation, key);
4843
4913
  }
4844
4914
  /**
4845
4915
  * @param {PropertyKey} key
4846
4916
  * @param {PropertyDescriptor} descriptor
4847
- * @param {Annotation|boolean} annotation true - infer from descriptor, false - copy as is
4917
+ * @param {Annotation|boolean} annotation true - use default annotation, false - copy as is
4848
4918
  * @param {boolean} proxyTrap whether it's called from proxy trap
4849
4919
  * @returns {boolean|null} true on success, false on failure (proxyTrap + non-configurable), null when cancelled by interceptor
4850
4920
  */
@@ -4856,7 +4926,7 @@
4856
4926
  }
4857
4927
 
4858
4928
  if (annotation === true) {
4859
- annotation = inferAnnotationFromDescriptor(descriptor, this.defaultAnnotation_, this.autoBind_);
4929
+ annotation = this.defaultAnnotation_;
4860
4930
  }
4861
4931
 
4862
4932
  if (annotation === false) {
@@ -4871,46 +4941,6 @@
4871
4941
  }
4872
4942
 
4873
4943
  return outcome;
4874
- };
4875
-
4876
- _proto.inferAnnotation_ = function inferAnnotation_(key) {
4877
- var _this$target_$inferre;
4878
-
4879
- // Inherited is fine - annotation cannot differ in subclass
4880
- var annotation = (_this$target_$inferre = this.target_[inferredAnnotationsSymbol]) == null ? void 0 : _this$target_$inferre.get(key);
4881
- if (annotation) return annotation;
4882
- var current = this.target_;
4883
-
4884
- while (current && current !== objectPrototype) {
4885
- var descriptor = getDescriptor(current, key);
4886
-
4887
- if (descriptor) {
4888
- annotation = inferAnnotationFromDescriptor(descriptor, this.defaultAnnotation_, this.autoBind_);
4889
- break;
4890
- }
4891
-
4892
- current = Object.getPrototypeOf(current);
4893
- } // Not found (false means ignore)
4894
-
4895
-
4896
- if (annotation === undefined) {
4897
- die(1, "true", key);
4898
- } // Cache the annotation.
4899
- // Note we can do this only because annotation and field can't change.
4900
-
4901
-
4902
- if (!this.isPlainObject_) {
4903
- // We could also place it on furthest proto, shoudn't matter
4904
- var closestProto = Object.getPrototypeOf(this.target_);
4905
-
4906
- if (!hasProp(closestProto, inferredAnnotationsSymbol)) {
4907
- addHiddenProp(closestProto, inferredAnnotationsSymbol, new Map());
4908
- }
4909
-
4910
- closestProto[inferredAnnotationsSymbol].set(key, annotation);
4911
- }
4912
-
4913
- return annotation;
4914
4944
  }
4915
4945
  /**
4916
4946
  * @param {PropertyKey} key
@@ -5015,11 +5045,10 @@
5015
5045
  defineProperty(this.target_, key, descriptor);
5016
5046
  }
5017
5047
 
5018
- var _observable = new ObservableValue(value, enhancer, "development" !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key", false);
5019
-
5020
- this.values_.set(key, _observable); // Notify (value possibly changed by ObservableValue)
5048
+ var observable = new ObservableValue(value, enhancer, "development" !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key", false);
5049
+ this.values_.set(key, observable); // Notify (value possibly changed by ObservableValue)
5021
5050
 
5022
- this.notifyPropertyAddition_(key, _observable.value_);
5051
+ this.notifyPropertyAddition_(key, observable.value_);
5023
5052
  } finally {
5024
5053
  endBatch();
5025
5054
  }
@@ -5117,13 +5146,11 @@
5117
5146
  startBatch();
5118
5147
  var notify = hasListeners(this);
5119
5148
  var notifySpy = "development" !== "production" && isSpyEnabled();
5120
-
5121
- var _observable2 = this.values_.get(key); // Value needed for spies/listeners
5122
-
5149
+ var observable = this.values_.get(key); // Value needed for spies/listeners
5123
5150
 
5124
5151
  var value = undefined; // Optimization: don't pull the value unless we will need it
5125
5152
 
5126
- if (!_observable2 && (notify || notifySpy)) {
5153
+ if (!observable && (notify || notifySpy)) {
5127
5154
  var _getDescriptor;
5128
5155
 
5129
5156
  value = (_getDescriptor = getDescriptor(this.target_, key)) == null ? void 0 : _getDescriptor.value;
@@ -5144,15 +5171,15 @@
5144
5171
  } // Clear observable
5145
5172
 
5146
5173
 
5147
- if (_observable2) {
5174
+ if (observable) {
5148
5175
  this.values_["delete"](key); // for computed, value is undefined
5149
5176
 
5150
- if (_observable2 instanceof ObservableValue) {
5151
- value = _observable2.value_;
5177
+ if (observable instanceof ObservableValue) {
5178
+ value = observable.value_;
5152
5179
  } // Notify: autorun(() => obj[key]), see #1796
5153
5180
 
5154
5181
 
5155
- propagateChanged(_observable2);
5182
+ propagateChanged(observable);
5156
5183
  } // Notify "keys/entries/values" observers
5157
5184
 
5158
5185
 
@@ -5256,7 +5283,7 @@
5256
5283
 
5257
5284
  if ( !Object.isExtensible(target)) die("Cannot make the designated object observable; it is not extensible");
5258
5285
  var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() ;
5259
- var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options), options == null ? void 0 : options.autoBind);
5286
+ var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
5260
5287
  addHiddenProp(target, $mobx, adm);
5261
5288
  return target;
5262
5289
  }
@@ -5690,24 +5717,6 @@
5690
5717
  return this;
5691
5718
  }
5692
5719
 
5693
- /**
5694
- * Infers the best fitting annotation from property descriptor or false if the field shoudn't be annotated
5695
- * - getter(+setter) -> computed
5696
- * - setter w/o getter -> false (ignore)
5697
- * - flow -> false (ignore)
5698
- * - generator -> flow
5699
- * - action -> false (ignore)
5700
- * - function -> action (optionally bound)
5701
- * - other -> defaultAnnotation
5702
- */
5703
-
5704
- function inferAnnotationFromDescriptor(desc, defaultAnnotation, autoBind) {
5705
- if (desc.get) return computed;
5706
- if (desc.set) return false; // ignore lone setter
5707
- // If already wrapped in action/flow, don't do that another time, but assume it is already set up properly.
5708
-
5709
- return isFunction(desc.value) ? isGenerator(desc.value) ? isFlow(desc.value) ? false : flow : isAction(desc.value) ? false : autoBind ? autoAction.bound : autoAction : defaultAnnotation;
5710
- }
5711
5720
  function isAnnotation(thing) {
5712
5721
  return (// Can be function
5713
5722
  thing instanceof Object && typeof thing.annotationType_ === "string" && isFunction(thing.make_) && isFunction(thing.extend_)
@@ -5773,6 +5782,7 @@
5773
5782
  exports.computed = computed;
5774
5783
  exports.configure = configure;
5775
5784
  exports.createAtom = createAtom;
5785
+ exports.defineProperty = apiDefineProperty;
5776
5786
  exports.entries = entries;
5777
5787
  exports.extendObservable = extendObservable;
5778
5788
  exports.flow = flow;
@@ -5788,6 +5798,7 @@
5788
5798
  exports.isBoxedObservable = isObservableValue;
5789
5799
  exports.isComputed = isComputed;
5790
5800
  exports.isComputedProp = isComputedProp;
5801
+ exports.isFlow = isFlow;
5791
5802
  exports.isFlowCancellationError = isFlowCancellationError;
5792
5803
  exports.isObservable = isObservable;
5793
5804
  exports.isObservableArray = isObservableArray;
@@ -5804,6 +5815,7 @@
5804
5815
  exports.onBecomeUnobserved = onBecomeUnobserved;
5805
5816
  exports.onReactionError = onReactionError;
5806
5817
  exports.override = override;
5818
+ exports.ownKeys = apiOwnKeys;
5807
5819
  exports.reaction = reaction;
5808
5820
  exports.remove = remove;
5809
5821
  exports.runInAction = runInAction;