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