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.
- package/CHANGELOG.md +57 -5
- package/README.md +2 -1
- package/dist/api/annotation.d.ts +6 -12
- package/dist/api/flow.d.ts +1 -0
- package/dist/api/object-api.d.ts +2 -0
- package/dist/errors.d.ts +2 -0
- package/dist/internal.d.ts +1 -0
- package/dist/mobx.cjs.development.js +322 -310
- package/dist/mobx.cjs.development.js.map +1 -1
- package/dist/mobx.cjs.production.min.js +1 -1
- package/dist/mobx.cjs.production.min.js.map +1 -1
- package/dist/mobx.d.ts +1 -1
- package/dist/mobx.esm.development.js +320 -311
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +320 -311
- package/dist/mobx.esm.js.map +1 -1
- package/dist/mobx.esm.production.min.js +1 -1
- package/dist/mobx.esm.production.min.js.map +1 -1
- package/dist/mobx.umd.development.js +322 -310
- package/dist/mobx.umd.development.js.map +1 -1
- package/dist/mobx.umd.production.min.js +1 -1
- package/dist/mobx.umd.production.min.js.map +1 -1
- package/dist/types/actionannotation.d.ts +7 -1
- package/dist/types/autoannotation.d.ts +3 -0
- package/dist/types/observableobject.d.ts +4 -7
- package/package.json +1 -1
- package/src/api/annotation.ts +13 -42
- package/src/api/flow.ts +6 -1
- package/src/api/makeObservable.ts +25 -34
- package/src/api/object-api.ts +14 -0
- package/src/api/observable.ts +3 -8
- package/src/api/tojs.ts +10 -7
- package/src/core/observable.ts +7 -6
- package/src/errors.ts +14 -1
- package/src/internal.ts +1 -0
- package/src/mobx.ts +4 -0
- package/src/types/actionannotation.ts +27 -51
- package/src/types/autoannotation.ts +107 -0
- package/src/types/computedannotation.ts +7 -37
- package/src/types/dynamicobject.ts +1 -1
- package/src/types/flowannotation.ts +31 -42
- package/src/types/modifiers.ts +13 -2
- package/src/types/observableannotation.ts +7 -34
- package/src/types/observableobject.ts +34 -63
- package/src/types/overrideannotation.ts +4 -2
|
@@ -3,6 +3,18 @@ var niceErrors = {
|
|
|
3
3
|
1: function _(annotationType, key) {
|
|
4
4
|
return "Cannot apply '" + annotationType + "' to '" + key.toString() + "': Field not found.";
|
|
5
5
|
},
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
2(prop) {
|
|
9
|
+
return `invalid decorator for '${prop.toString()}'`
|
|
10
|
+
},
|
|
11
|
+
3(prop) {
|
|
12
|
+
return `Cannot decorate '${prop.toString()}': action can only be used on properties with a function value.`
|
|
13
|
+
},
|
|
14
|
+
4(prop) {
|
|
15
|
+
return `Cannot decorate '${prop.toString()}': computed can only be used on getter properties.`
|
|
16
|
+
},
|
|
17
|
+
*/
|
|
6
18
|
5: "'keys()' can only be used on observable objects, arrays, sets and maps",
|
|
7
19
|
6: "'values()' can only be used on observable objects, arrays, sets and maps",
|
|
8
20
|
7: "'entries()' can only be used on observable objects, arrays and maps",
|
|
@@ -59,7 +71,9 @@ var niceErrors = {
|
|
|
59
71
|
36: "isolateGlobalState should be called before MobX is running any reactions",
|
|
60
72
|
37: function _(method) {
|
|
61
73
|
return "[mobx] `observableArray." + method + "()` mutates the array in-place, which is not allowed inside a derivation. Use `array.slice()." + method + "()` instead";
|
|
62
|
-
}
|
|
74
|
+
},
|
|
75
|
+
38: "'ownKeys()' can only be used on observable objects",
|
|
76
|
+
39: "'defineProperty()' can only be used on observable objects"
|
|
63
77
|
};
|
|
64
78
|
var errors = niceErrors ;
|
|
65
79
|
function die(error) {
|
|
@@ -522,6 +536,15 @@ function deepEnhancer(v, _, name) {
|
|
|
522
536
|
if (isES6Set(v)) return observable.set(v, {
|
|
523
537
|
name: name
|
|
524
538
|
});
|
|
539
|
+
|
|
540
|
+
if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
|
|
541
|
+
if (isGenerator(v)) {
|
|
542
|
+
return flow(v);
|
|
543
|
+
} else {
|
|
544
|
+
return autoAction(name, v);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
525
548
|
return v;
|
|
526
549
|
}
|
|
527
550
|
function shallowEnhancer(v, _, name) {
|
|
@@ -575,6 +598,10 @@ function make_(adm, key) {
|
|
|
575
598
|
if ( !hasProp(adm.appliedAnnotations_, key)) {
|
|
576
599
|
die("'" + adm.name_ + "." + key.toString() + "' is annotated with '" + this.annotationType_ + "', " + "but no such annotated member was found on prototype.");
|
|
577
600
|
}
|
|
601
|
+
|
|
602
|
+
return 0
|
|
603
|
+
/* Cancel */
|
|
604
|
+
;
|
|
578
605
|
}
|
|
579
606
|
|
|
580
607
|
function extend_(adm, key, descriptor, proxyTrap) {
|
|
@@ -590,65 +617,41 @@ function createActionAnnotation(name, options) {
|
|
|
590
617
|
};
|
|
591
618
|
}
|
|
592
619
|
|
|
593
|
-
function make_$1(adm, key) {
|
|
594
|
-
var _this$options_
|
|
620
|
+
function make_$1(adm, key, descriptor, source) {
|
|
621
|
+
var _this$options_;
|
|
595
622
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
623
|
+
// bound
|
|
624
|
+
if ((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) {
|
|
625
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
626
|
+
/* Cancel */
|
|
627
|
+
: 1
|
|
628
|
+
/* Break */
|
|
629
|
+
;
|
|
630
|
+
} // own
|
|
599
631
|
|
|
600
|
-
while (source && source !== objectPrototype) {
|
|
601
|
-
var descriptor = getDescriptor(source, key);
|
|
602
632
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
633
|
+
if (source === adm.target_) {
|
|
634
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
635
|
+
/* Cancel */
|
|
636
|
+
: 2
|
|
637
|
+
/* Continue */
|
|
638
|
+
;
|
|
639
|
+
} // prototype
|
|
610
640
|
|
|
611
|
-
if (!definePropertyOutcome) {
|
|
612
|
-
// Intercepted
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
annotated = true; // Don't annotate protos if bound
|
|
617
|
-
|
|
618
|
-
if (bound) {
|
|
619
|
-
break;
|
|
620
|
-
}
|
|
621
|
-
} // Prototype
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
if (source !== adm.target_) {
|
|
625
|
-
if (isAction(descriptor.value)) {
|
|
626
|
-
// A prototype could have been annotated already by other constructor,
|
|
627
|
-
// rest of the proto chain must be annotated already
|
|
628
|
-
annotated = true;
|
|
629
|
-
break;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
var _actionDescriptor = createActionDescriptor(adm, this, key, descriptor, false);
|
|
633
|
-
|
|
634
|
-
defineProperty(source, key, _actionDescriptor);
|
|
635
|
-
annotated = true;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
641
|
|
|
639
|
-
|
|
642
|
+
if (isAction(descriptor.value)) {
|
|
643
|
+
// A prototype could have been annotated already by other constructor,
|
|
644
|
+
// rest of the proto chain must be annotated already
|
|
645
|
+
return 1
|
|
646
|
+
/* Break */
|
|
647
|
+
;
|
|
640
648
|
}
|
|
641
649
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
// When called from super() some props may not exist yet.
|
|
648
|
-
// However we don't have to worry about missing prop,
|
|
649
|
-
// because the decorator must have been applied to something.
|
|
650
|
-
die(1, this.annotationType_, adm.name_ + "." + key.toString());
|
|
651
|
-
}
|
|
650
|
+
var actionDescriptor = createActionDescriptor(adm, this, key, descriptor, false);
|
|
651
|
+
defineProperty(source, key, actionDescriptor);
|
|
652
|
+
return 2
|
|
653
|
+
/* Continue */
|
|
654
|
+
;
|
|
652
655
|
}
|
|
653
656
|
|
|
654
657
|
function extend_$1(adm, key, descriptor, proxyTrap) {
|
|
@@ -704,58 +707,45 @@ function createFlowAnnotation(name, options) {
|
|
|
704
707
|
};
|
|
705
708
|
}
|
|
706
709
|
|
|
707
|
-
function make_$2(adm, key) {
|
|
708
|
-
var
|
|
709
|
-
|
|
710
|
-
var annotated = false;
|
|
711
|
-
var source = adm.target_;
|
|
712
|
-
|
|
713
|
-
while (source && source !== objectPrototype) {
|
|
714
|
-
var descriptor = getDescriptor(source, key);
|
|
715
|
-
|
|
716
|
-
if (descriptor) {
|
|
717
|
-
if (source !== adm.target_) {
|
|
718
|
-
// Prototype
|
|
719
|
-
if (isFlow(descriptor.value)) {
|
|
720
|
-
// A prototype could have been annotated already by other constructor,
|
|
721
|
-
// rest of the proto chain must be annotated already
|
|
722
|
-
annotated = true;
|
|
723
|
-
break;
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false);
|
|
727
|
-
defineProperty(source, key, flowDescriptor);
|
|
728
|
-
} else {
|
|
729
|
-
var _flowDescriptor = createFlowDescriptor(adm, this, key, descriptor);
|
|
730
|
-
|
|
731
|
-
var definePropertyOutcome = adm.defineProperty_(key, _flowDescriptor);
|
|
710
|
+
function make_$2(adm, key, descriptor, source) {
|
|
711
|
+
var _this$options_;
|
|
732
712
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
713
|
+
// own
|
|
714
|
+
if (source === adm.target_) {
|
|
715
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
716
|
+
/* Cancel */
|
|
717
|
+
: 2
|
|
718
|
+
/* Continue */
|
|
719
|
+
;
|
|
720
|
+
} // prototype
|
|
721
|
+
// bound - must annotate protos to support super.flow()
|
|
738
722
|
|
|
739
|
-
annotated = true;
|
|
740
|
-
}
|
|
741
723
|
|
|
742
|
-
|
|
724
|
+
if (((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) && !isFlow(adm.target_[key])) {
|
|
725
|
+
if (this.extend_(adm, key, descriptor, false) === null) return 0
|
|
726
|
+
/* Cancel */
|
|
727
|
+
;
|
|
743
728
|
}
|
|
744
729
|
|
|
745
|
-
if (
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
// However we don't have to worry about missing prop,
|
|
752
|
-
// because the decorator must have been applied to something.
|
|
753
|
-
die(1, this.annotationType_, adm.name_ + "." + key.toString());
|
|
730
|
+
if (isFlow(descriptor.value)) {
|
|
731
|
+
// A prototype could have been annotated already by other constructor,
|
|
732
|
+
// rest of the proto chain must be annotated already
|
|
733
|
+
return 1
|
|
734
|
+
/* Break */
|
|
735
|
+
;
|
|
754
736
|
}
|
|
737
|
+
|
|
738
|
+
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false, false);
|
|
739
|
+
defineProperty(source, key, flowDescriptor);
|
|
740
|
+
return 2
|
|
741
|
+
/* Continue */
|
|
742
|
+
;
|
|
755
743
|
}
|
|
756
744
|
|
|
757
745
|
function extend_$2(adm, key, descriptor, proxyTrap) {
|
|
758
|
-
var
|
|
746
|
+
var _this$options_2;
|
|
747
|
+
|
|
748
|
+
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, (_this$options_2 = this.options_) == null ? void 0 : _this$options_2.bound);
|
|
759
749
|
return adm.defineProperty_(key, flowDescriptor, proxyTrap);
|
|
760
750
|
}
|
|
761
751
|
|
|
@@ -768,15 +758,23 @@ function assertFlowDescriptor(adm, _ref, key, _ref2) {
|
|
|
768
758
|
}
|
|
769
759
|
}
|
|
770
760
|
|
|
771
|
-
function createFlowDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
|
|
761
|
+
function createFlowDescriptor(adm, annotation, key, descriptor, bound, // provides ability to disable safeDescriptors for prototypes
|
|
772
762
|
safeDescriptors) {
|
|
773
763
|
if (safeDescriptors === void 0) {
|
|
774
764
|
safeDescriptors = globalState.safeDescriptors;
|
|
775
765
|
}
|
|
776
766
|
|
|
777
767
|
assertFlowDescriptor(adm, annotation, key, descriptor);
|
|
768
|
+
var value = descriptor.value;
|
|
769
|
+
|
|
770
|
+
if (bound) {
|
|
771
|
+
var _adm$proxy_;
|
|
772
|
+
|
|
773
|
+
value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
|
774
|
+
}
|
|
775
|
+
|
|
778
776
|
return {
|
|
779
|
-
value: flow(
|
|
777
|
+
value: flow(value),
|
|
780
778
|
// Non-configurable for classes
|
|
781
779
|
// prevents accidental field redefinition in subclass
|
|
782
780
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -797,41 +795,12 @@ function createComputedAnnotation(name, options) {
|
|
|
797
795
|
};
|
|
798
796
|
}
|
|
799
797
|
|
|
800
|
-
function make_$3(adm, key) {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
var descriptor = getDescriptor(source, key);
|
|
807
|
-
|
|
808
|
-
if (descriptor) {
|
|
809
|
-
assertComputedDescriptor(adm, this, key, descriptor);
|
|
810
|
-
var definePropertyOutcome = adm.defineComputedProperty_(key, _extends({}, this.options_, {
|
|
811
|
-
get: descriptor.get,
|
|
812
|
-
set: descriptor.set
|
|
813
|
-
}));
|
|
814
|
-
|
|
815
|
-
if (!definePropertyOutcome) {
|
|
816
|
-
// Intercepted
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
recordAnnotationApplied(adm, this, key);
|
|
821
|
-
return;
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
source = Object.getPrototypeOf(source);
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
if (!((_adm$target_$storedAn = adm.target_[storedAnnotationsSymbol]) == null ? void 0 : _adm$target_$storedAn[key])) {
|
|
828
|
-
// Throw on missing key, except for decorators:
|
|
829
|
-
// Decorator annotations are collected from whole prototype chain.
|
|
830
|
-
// When called from super() some props may not exist yet.
|
|
831
|
-
// However we don't have to worry about missing prop,
|
|
832
|
-
// because the decorator must have been applied to something.
|
|
833
|
-
die(1, this.annotationType_, adm.name_ + "." + key.toString());
|
|
834
|
-
}
|
|
798
|
+
function make_$3(adm, key, descriptor) {
|
|
799
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
800
|
+
/* Cancel */
|
|
801
|
+
: 1
|
|
802
|
+
/* Break */
|
|
803
|
+
;
|
|
835
804
|
}
|
|
836
805
|
|
|
837
806
|
function extend_$3(adm, key, descriptor, proxyTrap) {
|
|
@@ -860,56 +829,130 @@ function createObservableAnnotation(name, options) {
|
|
|
860
829
|
};
|
|
861
830
|
}
|
|
862
831
|
|
|
863
|
-
function make_$4(adm, key) {
|
|
864
|
-
|
|
832
|
+
function make_$4(adm, key, descriptor) {
|
|
833
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
834
|
+
/* Cancel */
|
|
835
|
+
: 1
|
|
836
|
+
/* Break */
|
|
837
|
+
;
|
|
838
|
+
}
|
|
865
839
|
|
|
866
|
-
|
|
867
|
-
|
|
840
|
+
function extend_$4(adm, key, descriptor, proxyTrap) {
|
|
841
|
+
var _this$options_$enhanc, _this$options_;
|
|
842
|
+
|
|
843
|
+
assertObservableDescriptor(adm, this, key, descriptor);
|
|
844
|
+
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);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function assertObservableDescriptor(adm, _ref, key, descriptor) {
|
|
848
|
+
var annotationType_ = _ref.annotationType_;
|
|
849
|
+
|
|
850
|
+
if ( !("value" in descriptor)) {
|
|
851
|
+
die("Cannot apply '" + annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + annotationType_ + "' cannot be used on getter/setter properties"));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
868
854
|
|
|
869
|
-
|
|
870
|
-
|
|
855
|
+
var AUTO = "true";
|
|
856
|
+
var autoAnnotation = /*#__PURE__*/createAutoAnnotation();
|
|
857
|
+
function createAutoAnnotation(options) {
|
|
858
|
+
return {
|
|
859
|
+
annotationType_: AUTO,
|
|
860
|
+
options_: options,
|
|
861
|
+
make_: make_$5,
|
|
862
|
+
extend_: extend_$5
|
|
863
|
+
};
|
|
864
|
+
}
|
|
871
865
|
|
|
872
|
-
|
|
873
|
-
|
|
866
|
+
function make_$5(adm, key, descriptor, source) {
|
|
867
|
+
var _this$options_3, _this$options_4;
|
|
874
868
|
|
|
875
|
-
|
|
876
|
-
|
|
869
|
+
// getter -> computed
|
|
870
|
+
if (descriptor.get) {
|
|
871
|
+
return computed.make_(adm, key, descriptor, source);
|
|
872
|
+
} // lone setter -> action setter
|
|
877
873
|
|
|
878
|
-
if (!definePropertyOutcome) {
|
|
879
|
-
// Intercepted
|
|
880
|
-
return;
|
|
881
|
-
}
|
|
882
874
|
|
|
883
|
-
|
|
884
|
-
|
|
875
|
+
if (descriptor.set) {
|
|
876
|
+
// TODO make action applicable to setter and delegate to action.make_
|
|
877
|
+
var set = createAction(key.toString(), descriptor.set); // own
|
|
878
|
+
|
|
879
|
+
if (source === adm.target_) {
|
|
880
|
+
return adm.defineProperty_(key, {
|
|
881
|
+
configurable: globalState.safeDescriptors ? adm.isPlainObject_ : true,
|
|
882
|
+
set: set
|
|
883
|
+
}) === null ? 0
|
|
884
|
+
/* Cancel */
|
|
885
|
+
: 2
|
|
886
|
+
/* Continue */
|
|
887
|
+
;
|
|
888
|
+
} // proto
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
defineProperty(source, key, {
|
|
892
|
+
configurable: true,
|
|
893
|
+
set: set
|
|
894
|
+
});
|
|
895
|
+
return 2
|
|
896
|
+
/* Continue */
|
|
897
|
+
;
|
|
898
|
+
} // function on proto -> autoAction/flow
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
if (source !== adm.target_ && typeof descriptor.value === "function") {
|
|
902
|
+
var _this$options_2;
|
|
903
|
+
|
|
904
|
+
if (isGenerator(descriptor.value)) {
|
|
905
|
+
var _this$options_;
|
|
906
|
+
|
|
907
|
+
var flowAnnotation = ((_this$options_ = this.options_) == null ? void 0 : _this$options_.autoBind) ? flow.bound : flow;
|
|
908
|
+
return flowAnnotation.make_(adm, key, descriptor, source);
|
|
885
909
|
}
|
|
886
910
|
|
|
887
|
-
|
|
888
|
-
|
|
911
|
+
var actionAnnotation = ((_this$options_2 = this.options_) == null ? void 0 : _this$options_2.autoBind) ? autoAction.bound : autoAction;
|
|
912
|
+
return actionAnnotation.make_(adm, key, descriptor, source);
|
|
913
|
+
} // other -> observable
|
|
914
|
+
// Copy props from proto as well, see test:
|
|
915
|
+
// "decorate should work with Object.create"
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
var observableAnnotation = ((_this$options_3 = this.options_) == null ? void 0 : _this$options_3.deep) === false ? observable.ref : observable; // if function respect autoBind option
|
|
889
919
|
|
|
890
|
-
if (
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
// However we don't have to worry about missing prop,
|
|
895
|
-
// because the decorator must have been applied to something.
|
|
896
|
-
die(1, this.annotationType_, adm.name_ + "." + key.toString());
|
|
920
|
+
if (typeof descriptor.value === "function" && ((_this$options_4 = this.options_) == null ? void 0 : _this$options_4.autoBind)) {
|
|
921
|
+
var _adm$proxy_;
|
|
922
|
+
|
|
923
|
+
descriptor.value = descriptor.value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
|
897
924
|
}
|
|
925
|
+
|
|
926
|
+
return observableAnnotation.make_(adm, key, descriptor, source);
|
|
898
927
|
}
|
|
899
928
|
|
|
900
|
-
function extend_$
|
|
901
|
-
var _this$
|
|
929
|
+
function extend_$5(adm, key, descriptor, proxyTrap) {
|
|
930
|
+
var _this$options_5, _this$options_6;
|
|
902
931
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
932
|
+
// getter -> computed
|
|
933
|
+
if (descriptor.get) {
|
|
934
|
+
return computed.extend_(adm, key, descriptor, proxyTrap);
|
|
935
|
+
} // lone setter -> action setter
|
|
906
936
|
|
|
907
|
-
function assertObservableDescriptor(adm, _ref, key, descriptor) {
|
|
908
|
-
var annotationType_ = _ref.annotationType_;
|
|
909
937
|
|
|
910
|
-
if (
|
|
911
|
-
|
|
938
|
+
if (descriptor.set) {
|
|
939
|
+
// TODO make action applicable to setter and delegate to action.extend_
|
|
940
|
+
return adm.defineProperty_(key, {
|
|
941
|
+
configurable: globalState.safeDescriptors ? adm.isPlainObject_ : true,
|
|
942
|
+
set: createAction(key.toString(), descriptor.set)
|
|
943
|
+
}, proxyTrap);
|
|
944
|
+
} // other -> observable
|
|
945
|
+
// if function respect autoBind option
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
if (typeof descriptor.value === "function" && ((_this$options_5 = this.options_) == null ? void 0 : _this$options_5.autoBind)) {
|
|
949
|
+
var _adm$proxy_2;
|
|
950
|
+
|
|
951
|
+
descriptor.value = descriptor.value.bind((_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_);
|
|
912
952
|
}
|
|
953
|
+
|
|
954
|
+
var observableAnnotation = ((_this$options_6 = this.options_) == null ? void 0 : _this$options_6.deep) === false ? observable.ref : observable;
|
|
955
|
+
return observableAnnotation.extend_(adm, key, descriptor, proxyTrap);
|
|
913
956
|
}
|
|
914
957
|
|
|
915
958
|
// in the majority of cases
|
|
@@ -939,7 +982,9 @@ function getEnhancerFromOptions(options) {
|
|
|
939
982
|
return options.deep === true ? deepEnhancer : options.deep === false ? referenceEnhancer : getEnhancerFromAnnotation(options.defaultDecorator);
|
|
940
983
|
}
|
|
941
984
|
function getAnnotationFromOptions(options) {
|
|
942
|
-
|
|
985
|
+
var _options$defaultDecor;
|
|
986
|
+
|
|
987
|
+
return options ? (_options$defaultDecor = options.defaultDecorator) != null ? _options$defaultDecor : createAutoAnnotation(options) : undefined;
|
|
943
988
|
}
|
|
944
989
|
function getEnhancerFromAnnotation(annotation) {
|
|
945
990
|
var _annotation$options_$, _annotation$options_;
|
|
@@ -2123,8 +2168,16 @@ function propagateChangeConfirmed(observable) {
|
|
|
2123
2168
|
if (observable.lowestObserverState_ === IDerivationState_.STALE_) return;
|
|
2124
2169
|
observable.lowestObserverState_ = IDerivationState_.STALE_;
|
|
2125
2170
|
observable.observers_.forEach(function (d) {
|
|
2126
|
-
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_)
|
|
2127
|
-
|
|
2171
|
+
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
|
|
2172
|
+
d.dependenciesState_ = IDerivationState_.STALE_;
|
|
2173
|
+
|
|
2174
|
+
if ( d.isTracing_ !== TraceMode.NONE) {
|
|
2175
|
+
logTraceInfo(d, observable);
|
|
2176
|
+
}
|
|
2177
|
+
} else if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_ // this happens during computing of `d`, just keep lowestObserverState up to date.
|
|
2178
|
+
) {
|
|
2179
|
+
observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
|
|
2180
|
+
}
|
|
2128
2181
|
}); // invariantLOS(observable, "confirmed end");
|
|
2129
2182
|
} // Used by computed when its dependency changed, but we don't wan't to immediately recompute.
|
|
2130
2183
|
|
|
@@ -2135,11 +2188,6 @@ function propagateMaybeChanged(observable) {
|
|
|
2135
2188
|
observable.observers_.forEach(function (d) {
|
|
2136
2189
|
if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
2137
2190
|
d.dependenciesState_ = IDerivationState_.POSSIBLY_STALE_;
|
|
2138
|
-
|
|
2139
|
-
if ( d.isTracing_ !== TraceMode.NONE) {
|
|
2140
|
-
logTraceInfo(d, observable);
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
2191
|
d.onBecomeStale_();
|
|
2144
2192
|
}
|
|
2145
2193
|
}); // invariantLOS(observable, "maybe end");
|
|
@@ -2769,6 +2817,9 @@ function isFlowCancellationError(error) {
|
|
|
2769
2817
|
return error instanceof FlowCancellationError;
|
|
2770
2818
|
}
|
|
2771
2819
|
var flowAnnotation = /*#__PURE__*/createFlowAnnotation("flow");
|
|
2820
|
+
var flowBoundAnnotation = /*#__PURE__*/createFlowAnnotation("flow.bound", {
|
|
2821
|
+
bound: true
|
|
2822
|
+
});
|
|
2772
2823
|
var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
2773
2824
|
// @flow
|
|
2774
2825
|
if (isStringish(arg2)) {
|
|
@@ -2854,6 +2905,7 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2854
2905
|
res.isMobXFlow = true;
|
|
2855
2906
|
return res;
|
|
2856
2907
|
}, flowAnnotation);
|
|
2908
|
+
flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
|
|
2857
2909
|
|
|
2858
2910
|
function cancelPromise(promise) {
|
|
2859
2911
|
if (isFunction(promise.cancel)) promise.cancel();
|
|
@@ -3078,6 +3130,20 @@ function get(obj, key) {
|
|
|
3078
3130
|
|
|
3079
3131
|
die(11);
|
|
3080
3132
|
}
|
|
3133
|
+
function apiDefineProperty(obj, key, descriptor) {
|
|
3134
|
+
if (isObservableObject(obj)) {
|
|
3135
|
+
return obj[$mobx].defineProperty_(key, descriptor);
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
die(39);
|
|
3139
|
+
}
|
|
3140
|
+
function apiOwnKeys(obj) {
|
|
3141
|
+
if (isObservableObject(obj)) {
|
|
3142
|
+
return obj[$mobx].ownKeys_();
|
|
3143
|
+
}
|
|
3144
|
+
|
|
3145
|
+
die(38);
|
|
3146
|
+
}
|
|
3081
3147
|
|
|
3082
3148
|
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
3083
3149
|
if (isFunction(cbOrFire)) return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);else return observeObservable(thing, propOrCb, cbOrFire);
|
|
@@ -3098,7 +3164,7 @@ function cache(map, key, value) {
|
|
|
3098
3164
|
|
|
3099
3165
|
function toJSHelper(source, __alreadySeen) {
|
|
3100
3166
|
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) return source;
|
|
3101
|
-
if (isObservableValue(source)) return toJSHelper(source.get(), __alreadySeen);
|
|
3167
|
+
if (isObservableValue(source) || isComputedValue(source)) return toJSHelper(source.get(), __alreadySeen);
|
|
3102
3168
|
|
|
3103
3169
|
if (__alreadySeen.has(source)) {
|
|
3104
3170
|
return __alreadySeen.get(source);
|
|
@@ -3130,12 +3196,12 @@ function toJSHelper(source, __alreadySeen) {
|
|
|
3130
3196
|
return _res2;
|
|
3131
3197
|
} else {
|
|
3132
3198
|
// must be observable object
|
|
3133
|
-
keys(source); // make sure keys are observed
|
|
3134
|
-
|
|
3135
3199
|
var _res3 = cache(__alreadySeen, source, {});
|
|
3136
3200
|
|
|
3137
|
-
|
|
3138
|
-
|
|
3201
|
+
apiOwnKeys(source).forEach(function (key) {
|
|
3202
|
+
if (objectPrototype.propertyIsEnumerable.call(source, key)) {
|
|
3203
|
+
_res3[key] = toJSHelper(source[key], __alreadySeen);
|
|
3204
|
+
}
|
|
3139
3205
|
});
|
|
3140
3206
|
return _res3;
|
|
3141
3207
|
}
|
|
@@ -3305,7 +3371,7 @@ var objectProxyTraps = {
|
|
|
3305
3371
|
return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
|
3306
3372
|
},
|
|
3307
3373
|
ownKeys: function ownKeys(target) {
|
|
3308
|
-
if ( globalState.trackingDerivation) warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use
|
|
3374
|
+
if ( globalState.trackingDerivation) warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
|
3309
3375
|
return getAdm(target).ownKeys_();
|
|
3310
3376
|
},
|
|
3311
3377
|
preventExtensions: function preventExtensions(target) {
|
|
@@ -3392,57 +3458,39 @@ function makeObservable(target, annotations, options) {
|
|
|
3392
3458
|
}
|
|
3393
3459
|
|
|
3394
3460
|
return target;
|
|
3395
|
-
}
|
|
3461
|
+
} // proto[keysSymbol] = new Set<PropertyKey>()
|
|
3462
|
+
|
|
3463
|
+
var keysSymbol = /*#__PURE__*/Symbol("mobx-keys");
|
|
3396
3464
|
function makeAutoObservable(target, overrides, options) {
|
|
3397
3465
|
{
|
|
3398
3466
|
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) die("'makeAutoObservable' can only be used for classes that don't have a superclass");
|
|
3399
3467
|
if (isObservableObject(target)) die("makeAutoObservable can only be used on objects not already made observable");
|
|
3400
|
-
} // Optimization
|
|
3401
|
-
//
|
|
3468
|
+
} // Optimization: avoid visiting protos
|
|
3469
|
+
// Assumes that annotation.make_/.extend_ works the same for plain objects
|
|
3402
3470
|
|
|
3403
3471
|
|
|
3404
3472
|
if (isPlainObject(target)) {
|
|
3405
3473
|
return extendObservable(target, target, overrides, options);
|
|
3406
3474
|
}
|
|
3407
3475
|
|
|
3408
|
-
var adm = asObservableObject(target, options)[$mobx];
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
try {
|
|
3412
|
-
// Use cached inferred annotations if available (only in classes)
|
|
3413
|
-
if (target[inferredAnnotationsSymbol]) {
|
|
3414
|
-
target[inferredAnnotationsSymbol].forEach(function (value, key) {
|
|
3415
|
-
return adm.make_(key, value);
|
|
3416
|
-
}); // Overrides are not cached, unless `true`, see #2832
|
|
3417
|
-
|
|
3418
|
-
if (overrides) {
|
|
3419
|
-
ownKeys(overrides).forEach(function (key) {
|
|
3420
|
-
var annotation = overrides[key];
|
|
3421
|
-
|
|
3422
|
-
if (annotation !== true) {
|
|
3423
|
-
adm.make_(key, annotation);
|
|
3424
|
-
}
|
|
3425
|
-
});
|
|
3426
|
-
}
|
|
3427
|
-
} else {
|
|
3428
|
-
var _ignoreKeys;
|
|
3429
|
-
|
|
3430
|
-
var ignoreKeys = (_ignoreKeys = {}, _ignoreKeys[$mobx] = 1, _ignoreKeys[inferredAnnotationsSymbol] = 1, _ignoreKeys.constructor = 1, _ignoreKeys);
|
|
3476
|
+
var adm = asObservableObject(target, options)[$mobx]; // Optimization: cache keys on proto
|
|
3477
|
+
// Assumes makeAutoObservable can be called only once per object and can't be used in subclass
|
|
3431
3478
|
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3479
|
+
if (!target[keysSymbol]) {
|
|
3480
|
+
var proto = Object.getPrototypeOf(target);
|
|
3481
|
+
var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
|
|
3482
|
+
keys["delete"]("constructor");
|
|
3483
|
+
keys["delete"]($mobx);
|
|
3484
|
+
addHiddenProp(proto, keysSymbol, keys);
|
|
3485
|
+
}
|
|
3438
3486
|
|
|
3439
|
-
|
|
3487
|
+
startBatch();
|
|
3440
3488
|
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
}
|
|
3489
|
+
try {
|
|
3490
|
+
target[keysSymbol].forEach(function (key) {
|
|
3491
|
+
return adm.make_(key, // must pass "undefined" for { key: undefined }
|
|
3492
|
+
!overrides ? true : key in overrides ? overrides[key] : true);
|
|
3493
|
+
});
|
|
3446
3494
|
} finally {
|
|
3447
3495
|
endBatch();
|
|
3448
3496
|
}
|
|
@@ -4648,30 +4696,23 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4648
4696
|
|
|
4649
4697
|
var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
|
|
4650
4698
|
|
|
4651
|
-
var inferredAnnotationsSymbol = /*#__PURE__*/Symbol("mobx-inferred-annotations");
|
|
4652
4699
|
var descriptorCache = /*#__PURE__*/Object.create(null);
|
|
4653
4700
|
var REMOVE = "remove";
|
|
4654
4701
|
var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
4655
4702
|
function ObservableObjectAdministration(target_, values_, name_, // Used anytime annotation is not explicitely provided
|
|
4656
|
-
defaultAnnotation_
|
|
4657
|
-
autoBind_) {
|
|
4703
|
+
defaultAnnotation_) {
|
|
4658
4704
|
if (values_ === void 0) {
|
|
4659
4705
|
values_ = new Map();
|
|
4660
4706
|
}
|
|
4661
4707
|
|
|
4662
4708
|
if (defaultAnnotation_ === void 0) {
|
|
4663
|
-
defaultAnnotation_ =
|
|
4664
|
-
}
|
|
4665
|
-
|
|
4666
|
-
if (autoBind_ === void 0) {
|
|
4667
|
-
autoBind_ = false;
|
|
4709
|
+
defaultAnnotation_ = autoAnnotation;
|
|
4668
4710
|
}
|
|
4669
4711
|
|
|
4670
4712
|
this.target_ = void 0;
|
|
4671
4713
|
this.values_ = void 0;
|
|
4672
4714
|
this.name_ = void 0;
|
|
4673
4715
|
this.defaultAnnotation_ = void 0;
|
|
4674
|
-
this.autoBind_ = void 0;
|
|
4675
4716
|
this.keysAtom_ = void 0;
|
|
4676
4717
|
this.changeListeners_ = void 0;
|
|
4677
4718
|
this.interceptors_ = void 0;
|
|
@@ -4683,7 +4724,6 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4683
4724
|
this.values_ = values_;
|
|
4684
4725
|
this.name_ = name_;
|
|
4685
4726
|
this.defaultAnnotation_ = defaultAnnotation_;
|
|
4686
|
-
this.autoBind_ = autoBind_;
|
|
4687
4727
|
this.keysAtom_ = new Atom( this.name_ + ".keys" ); // Optimization: we use this frequently
|
|
4688
4728
|
|
|
4689
4729
|
this.isPlainObject_ = isPlainObject(this.target_);
|
|
@@ -4692,10 +4732,6 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4692
4732
|
die("defaultAnnotation must be valid annotation");
|
|
4693
4733
|
}
|
|
4694
4734
|
|
|
4695
|
-
if ( typeof this.autoBind_ !== "boolean") {
|
|
4696
|
-
die("autoBind must be boolean");
|
|
4697
|
-
}
|
|
4698
|
-
|
|
4699
4735
|
{
|
|
4700
4736
|
// Prepare structure for tracking which fields were already annotated
|
|
4701
4737
|
this.appliedAnnotations_ = {};
|
|
@@ -4764,7 +4800,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4764
4800
|
/**
|
|
4765
4801
|
* @param {PropertyKey} key
|
|
4766
4802
|
* @param {any} value
|
|
4767
|
-
* @param {Annotation|boolean} annotation true -
|
|
4803
|
+
* @param {Annotation|boolean} annotation true - use default annotation, false - copy as is
|
|
4768
4804
|
* @param {boolean} proxyTrap whether it's called from proxy trap
|
|
4769
4805
|
* @returns {boolean|null} true on success, false on failure (proxyTrap + non-configurable), null when cancelled by interceptor
|
|
4770
4806
|
*/
|
|
@@ -4819,13 +4855,13 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4819
4855
|
}
|
|
4820
4856
|
/**
|
|
4821
4857
|
* @param {PropertyKey} key
|
|
4822
|
-
* @param {Annotation|boolean} annotation true -
|
|
4858
|
+
* @param {Annotation|boolean} annotation true - use default annotation, false - ignore prop
|
|
4823
4859
|
*/
|
|
4824
4860
|
;
|
|
4825
4861
|
|
|
4826
4862
|
_proto.make_ = function make_(key, annotation) {
|
|
4827
4863
|
if (annotation === true) {
|
|
4828
|
-
annotation = this.
|
|
4864
|
+
annotation = this.defaultAnnotation_;
|
|
4829
4865
|
}
|
|
4830
4866
|
|
|
4831
4867
|
if (annotation === false) {
|
|
@@ -4833,12 +4869,46 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4833
4869
|
}
|
|
4834
4870
|
|
|
4835
4871
|
assertAnnotable(this, annotation, key);
|
|
4836
|
-
|
|
4872
|
+
|
|
4873
|
+
if (!(key in this.target_)) {
|
|
4874
|
+
var _this$target_$storedA;
|
|
4875
|
+
|
|
4876
|
+
// Throw on missing key, except for decorators:
|
|
4877
|
+
// Decorator annotations are collected from whole prototype chain.
|
|
4878
|
+
// When called from super() some props may not exist yet.
|
|
4879
|
+
// However we don't have to worry about missing prop,
|
|
4880
|
+
// because the decorator must have been applied to something.
|
|
4881
|
+
if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
|
|
4882
|
+
return; // will be annotated by subclass constructor
|
|
4883
|
+
} else {
|
|
4884
|
+
die(1, annotation.annotationType_, this.name_ + "." + key.toString());
|
|
4885
|
+
}
|
|
4886
|
+
}
|
|
4887
|
+
|
|
4888
|
+
var source = this.target_;
|
|
4889
|
+
|
|
4890
|
+
while (source && source !== objectPrototype) {
|
|
4891
|
+
var descriptor = getDescriptor(source, key);
|
|
4892
|
+
|
|
4893
|
+
if (descriptor) {
|
|
4894
|
+
var outcome = annotation.make_(this, key, descriptor, source);
|
|
4895
|
+
if (outcome === 0
|
|
4896
|
+
/* Cancel */
|
|
4897
|
+
) return;
|
|
4898
|
+
if (outcome === 1
|
|
4899
|
+
/* Break */
|
|
4900
|
+
) break;
|
|
4901
|
+
}
|
|
4902
|
+
|
|
4903
|
+
source = Object.getPrototypeOf(source);
|
|
4904
|
+
}
|
|
4905
|
+
|
|
4906
|
+
recordAnnotationApplied(this, annotation, key);
|
|
4837
4907
|
}
|
|
4838
4908
|
/**
|
|
4839
4909
|
* @param {PropertyKey} key
|
|
4840
4910
|
* @param {PropertyDescriptor} descriptor
|
|
4841
|
-
* @param {Annotation|boolean} annotation true -
|
|
4911
|
+
* @param {Annotation|boolean} annotation true - use default annotation, false - copy as is
|
|
4842
4912
|
* @param {boolean} proxyTrap whether it's called from proxy trap
|
|
4843
4913
|
* @returns {boolean|null} true on success, false on failure (proxyTrap + non-configurable), null when cancelled by interceptor
|
|
4844
4914
|
*/
|
|
@@ -4850,7 +4920,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4850
4920
|
}
|
|
4851
4921
|
|
|
4852
4922
|
if (annotation === true) {
|
|
4853
|
-
annotation =
|
|
4923
|
+
annotation = this.defaultAnnotation_;
|
|
4854
4924
|
}
|
|
4855
4925
|
|
|
4856
4926
|
if (annotation === false) {
|
|
@@ -4865,46 +4935,6 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4865
4935
|
}
|
|
4866
4936
|
|
|
4867
4937
|
return outcome;
|
|
4868
|
-
};
|
|
4869
|
-
|
|
4870
|
-
_proto.inferAnnotation_ = function inferAnnotation_(key) {
|
|
4871
|
-
var _this$target_$inferre;
|
|
4872
|
-
|
|
4873
|
-
// Inherited is fine - annotation cannot differ in subclass
|
|
4874
|
-
var annotation = (_this$target_$inferre = this.target_[inferredAnnotationsSymbol]) == null ? void 0 : _this$target_$inferre.get(key);
|
|
4875
|
-
if (annotation) return annotation;
|
|
4876
|
-
var current = this.target_;
|
|
4877
|
-
|
|
4878
|
-
while (current && current !== objectPrototype) {
|
|
4879
|
-
var descriptor = getDescriptor(current, key);
|
|
4880
|
-
|
|
4881
|
-
if (descriptor) {
|
|
4882
|
-
annotation = inferAnnotationFromDescriptor(descriptor, this.defaultAnnotation_, this.autoBind_);
|
|
4883
|
-
break;
|
|
4884
|
-
}
|
|
4885
|
-
|
|
4886
|
-
current = Object.getPrototypeOf(current);
|
|
4887
|
-
} // Not found (false means ignore)
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
if (annotation === undefined) {
|
|
4891
|
-
die(1, "true", key);
|
|
4892
|
-
} // Cache the annotation.
|
|
4893
|
-
// Note we can do this only because annotation and field can't change.
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
if (!this.isPlainObject_) {
|
|
4897
|
-
// We could also place it on furthest proto, shoudn't matter
|
|
4898
|
-
var closestProto = Object.getPrototypeOf(this.target_);
|
|
4899
|
-
|
|
4900
|
-
if (!hasProp(closestProto, inferredAnnotationsSymbol)) {
|
|
4901
|
-
addHiddenProp(closestProto, inferredAnnotationsSymbol, new Map());
|
|
4902
|
-
}
|
|
4903
|
-
|
|
4904
|
-
closestProto[inferredAnnotationsSymbol].set(key, annotation);
|
|
4905
|
-
}
|
|
4906
|
-
|
|
4907
|
-
return annotation;
|
|
4908
4938
|
}
|
|
4909
4939
|
/**
|
|
4910
4940
|
* @param {PropertyKey} key
|
|
@@ -5009,11 +5039,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5009
5039
|
defineProperty(this.target_, key, descriptor);
|
|
5010
5040
|
}
|
|
5011
5041
|
|
|
5012
|
-
var
|
|
5013
|
-
|
|
5014
|
-
this.values_.set(key, _observable); // Notify (value possibly changed by ObservableValue)
|
|
5042
|
+
var observable = new ObservableValue(value, enhancer, "development" !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key", false);
|
|
5043
|
+
this.values_.set(key, observable); // Notify (value possibly changed by ObservableValue)
|
|
5015
5044
|
|
|
5016
|
-
this.notifyPropertyAddition_(key,
|
|
5045
|
+
this.notifyPropertyAddition_(key, observable.value_);
|
|
5017
5046
|
} finally {
|
|
5018
5047
|
endBatch();
|
|
5019
5048
|
}
|
|
@@ -5111,13 +5140,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5111
5140
|
startBatch();
|
|
5112
5141
|
var notify = hasListeners(this);
|
|
5113
5142
|
var notifySpy = "development" !== "production" && isSpyEnabled();
|
|
5114
|
-
|
|
5115
|
-
var _observable2 = this.values_.get(key); // Value needed for spies/listeners
|
|
5116
|
-
|
|
5143
|
+
var observable = this.values_.get(key); // Value needed for spies/listeners
|
|
5117
5144
|
|
|
5118
5145
|
var value = undefined; // Optimization: don't pull the value unless we will need it
|
|
5119
5146
|
|
|
5120
|
-
if (!
|
|
5147
|
+
if (!observable && (notify || notifySpy)) {
|
|
5121
5148
|
var _getDescriptor;
|
|
5122
5149
|
|
|
5123
5150
|
value = (_getDescriptor = getDescriptor(this.target_, key)) == null ? void 0 : _getDescriptor.value;
|
|
@@ -5138,15 +5165,15 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5138
5165
|
} // Clear observable
|
|
5139
5166
|
|
|
5140
5167
|
|
|
5141
|
-
if (
|
|
5168
|
+
if (observable) {
|
|
5142
5169
|
this.values_["delete"](key); // for computed, value is undefined
|
|
5143
5170
|
|
|
5144
|
-
if (
|
|
5145
|
-
value =
|
|
5171
|
+
if (observable instanceof ObservableValue) {
|
|
5172
|
+
value = observable.value_;
|
|
5146
5173
|
} // Notify: autorun(() => obj[key]), see #1796
|
|
5147
5174
|
|
|
5148
5175
|
|
|
5149
|
-
propagateChanged(
|
|
5176
|
+
propagateChanged(observable);
|
|
5150
5177
|
} // Notify "keys/entries/values" observers
|
|
5151
5178
|
|
|
5152
5179
|
|
|
@@ -5250,7 +5277,7 @@ function asObservableObject(target, options) {
|
|
|
5250
5277
|
|
|
5251
5278
|
if ( !Object.isExtensible(target)) die("Cannot make the designated object observable; it is not extensible");
|
|
5252
5279
|
var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() ;
|
|
5253
|
-
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options)
|
|
5280
|
+
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
|
|
5254
5281
|
addHiddenProp(target, $mobx, adm);
|
|
5255
5282
|
return target;
|
|
5256
5283
|
}
|
|
@@ -5684,24 +5711,6 @@ function getSelf() {
|
|
|
5684
5711
|
return this;
|
|
5685
5712
|
}
|
|
5686
5713
|
|
|
5687
|
-
/**
|
|
5688
|
-
* Infers the best fitting annotation from property descriptor or false if the field shoudn't be annotated
|
|
5689
|
-
* - getter(+setter) -> computed
|
|
5690
|
-
* - setter w/o getter -> false (ignore)
|
|
5691
|
-
* - flow -> false (ignore)
|
|
5692
|
-
* - generator -> flow
|
|
5693
|
-
* - action -> false (ignore)
|
|
5694
|
-
* - function -> action (optionally bound)
|
|
5695
|
-
* - other -> defaultAnnotation
|
|
5696
|
-
*/
|
|
5697
|
-
|
|
5698
|
-
function inferAnnotationFromDescriptor(desc, defaultAnnotation, autoBind) {
|
|
5699
|
-
if (desc.get) return computed;
|
|
5700
|
-
if (desc.set) return false; // ignore lone setter
|
|
5701
|
-
// If already wrapped in action/flow, don't do that another time, but assume it is already set up properly.
|
|
5702
|
-
|
|
5703
|
-
return isFunction(desc.value) ? isGenerator(desc.value) ? isFlow(desc.value) ? false : flow : isAction(desc.value) ? false : autoBind ? autoAction.bound : autoAction : defaultAnnotation;
|
|
5704
|
-
}
|
|
5705
5714
|
function isAnnotation(thing) {
|
|
5706
5715
|
return (// Can be function
|
|
5707
5716
|
thing instanceof Object && typeof thing.annotationType_ === "string" && isFunction(thing.make_) && isFunction(thing.extend_)
|
|
@@ -5744,5 +5753,5 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
|
|
|
5744
5753
|
});
|
|
5745
5754
|
}
|
|
5746
5755
|
|
|
5747
|
-
export { $mobx, FlowCancellationError, ObservableMap, ObservableSet, Reaction, allowStateChanges as _allowStateChanges, runInAction as _allowStateChangesInsideComputed, allowStateReadsEnd as _allowStateReadsEnd, allowStateReadsStart as _allowStateReadsStart, autoAction as _autoAction, _endAction, getAdministration as _getAdministration, getGlobalState as _getGlobalState, interceptReads as _interceptReads, isComputingDerivation as _isComputingDerivation, resetGlobalState as _resetGlobalState, _startAction, action, autorun, comparer, computed, configure, createAtom, entries, extendObservable, flow, flowResult, get, getAtom, getDebugName, getDependencyTree, getObserverTree, has, intercept, isAction, isObservableValue as isBoxedObservable, isComputed, isComputedProp, isFlowCancellationError, isObservable, isObservableArray, isObservableMap, isObservableObject, isObservableProp, isObservableSet, keys, makeAutoObservable, makeObservable, observable, observe, onBecomeObserved, onBecomeUnobserved, onReactionError, override, reaction, remove, runInAction, set, spy, toJS, trace, transaction, untracked, values, when };
|
|
5756
|
+
export { $mobx, FlowCancellationError, ObservableMap, ObservableSet, Reaction, allowStateChanges as _allowStateChanges, runInAction as _allowStateChangesInsideComputed, allowStateReadsEnd as _allowStateReadsEnd, allowStateReadsStart as _allowStateReadsStart, autoAction as _autoAction, _endAction, getAdministration as _getAdministration, getGlobalState as _getGlobalState, interceptReads as _interceptReads, isComputingDerivation as _isComputingDerivation, resetGlobalState as _resetGlobalState, _startAction, action, autorun, comparer, computed, configure, createAtom, apiDefineProperty as defineProperty, entries, extendObservable, flow, flowResult, get, getAtom, getDebugName, getDependencyTree, getObserverTree, has, intercept, isAction, isObservableValue as isBoxedObservable, isComputed, isComputedProp, isFlow, isFlowCancellationError, isObservable, isObservableArray, isObservableMap, isObservableObject, isObservableProp, isObservableSet, keys, makeAutoObservable, makeObservable, observable, observe, onBecomeObserved, onBecomeUnobserved, onReactionError, override, apiOwnKeys as ownKeys, reaction, remove, runInAction, set, spy, toJS, trace, transaction, untracked, values, when };
|
|
5748
5757
|
//# sourceMappingURL=mobx.esm.development.js.map
|