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
package/dist/mobx.esm.js
CHANGED
|
@@ -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 = process.env.NODE_ENV !== "production" ? niceErrors : {};
|
|
65
79
|
function die(error) {
|
|
@@ -524,6 +538,15 @@ function deepEnhancer(v, _, name) {
|
|
|
524
538
|
if (isES6Set(v)) return observable.set(v, {
|
|
525
539
|
name: name
|
|
526
540
|
});
|
|
541
|
+
|
|
542
|
+
if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
|
|
543
|
+
if (isGenerator(v)) {
|
|
544
|
+
return flow(v);
|
|
545
|
+
} else {
|
|
546
|
+
return autoAction(name, v);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
527
550
|
return v;
|
|
528
551
|
}
|
|
529
552
|
function shallowEnhancer(v, _, name) {
|
|
@@ -577,6 +600,10 @@ function make_(adm, key) {
|
|
|
577
600
|
if (process.env.NODE_ENV !== "production" && !hasProp(adm.appliedAnnotations_, key)) {
|
|
578
601
|
die("'" + adm.name_ + "." + key.toString() + "' is annotated with '" + this.annotationType_ + "', " + "but no such annotated member was found on prototype.");
|
|
579
602
|
}
|
|
603
|
+
|
|
604
|
+
return 0
|
|
605
|
+
/* Cancel */
|
|
606
|
+
;
|
|
580
607
|
}
|
|
581
608
|
|
|
582
609
|
function extend_(adm, key, descriptor, proxyTrap) {
|
|
@@ -592,65 +619,41 @@ function createActionAnnotation(name, options) {
|
|
|
592
619
|
};
|
|
593
620
|
}
|
|
594
621
|
|
|
595
|
-
function make_$1(adm, key) {
|
|
596
|
-
var _this$options_
|
|
622
|
+
function make_$1(adm, key, descriptor, source) {
|
|
623
|
+
var _this$options_;
|
|
597
624
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
625
|
+
// bound
|
|
626
|
+
if ((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) {
|
|
627
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
628
|
+
/* Cancel */
|
|
629
|
+
: 1
|
|
630
|
+
/* Break */
|
|
631
|
+
;
|
|
632
|
+
} // own
|
|
601
633
|
|
|
602
|
-
while (source && source !== objectPrototype) {
|
|
603
|
-
var descriptor = getDescriptor(source, key);
|
|
604
634
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
635
|
+
if (source === adm.target_) {
|
|
636
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
637
|
+
/* Cancel */
|
|
638
|
+
: 2
|
|
639
|
+
/* Continue */
|
|
640
|
+
;
|
|
641
|
+
} // prototype
|
|
612
642
|
|
|
613
|
-
if (!definePropertyOutcome) {
|
|
614
|
-
// Intercepted
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
annotated = true; // Don't annotate protos if bound
|
|
619
|
-
|
|
620
|
-
if (bound) {
|
|
621
|
-
break;
|
|
622
|
-
}
|
|
623
|
-
} // Prototype
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
if (source !== adm.target_) {
|
|
627
|
-
if (isAction(descriptor.value)) {
|
|
628
|
-
// A prototype could have been annotated already by other constructor,
|
|
629
|
-
// rest of the proto chain must be annotated already
|
|
630
|
-
annotated = true;
|
|
631
|
-
break;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
var _actionDescriptor = createActionDescriptor(adm, this, key, descriptor, false);
|
|
635
|
-
|
|
636
|
-
defineProperty(source, key, _actionDescriptor);
|
|
637
|
-
annotated = true;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
643
|
|
|
641
|
-
|
|
644
|
+
if (isAction(descriptor.value)) {
|
|
645
|
+
// A prototype could have been annotated already by other constructor,
|
|
646
|
+
// rest of the proto chain must be annotated already
|
|
647
|
+
return 1
|
|
648
|
+
/* Break */
|
|
649
|
+
;
|
|
642
650
|
}
|
|
643
651
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
// When called from super() some props may not exist yet.
|
|
650
|
-
// However we don't have to worry about missing prop,
|
|
651
|
-
// because the decorator must have been applied to something.
|
|
652
|
-
die(1, this.annotationType_, adm.name_ + "." + key.toString());
|
|
653
|
-
}
|
|
652
|
+
var actionDescriptor = createActionDescriptor(adm, this, key, descriptor, false);
|
|
653
|
+
defineProperty(source, key, actionDescriptor);
|
|
654
|
+
return 2
|
|
655
|
+
/* Continue */
|
|
656
|
+
;
|
|
654
657
|
}
|
|
655
658
|
|
|
656
659
|
function extend_$1(adm, key, descriptor, proxyTrap) {
|
|
@@ -706,58 +709,45 @@ function createFlowAnnotation(name, options) {
|
|
|
706
709
|
};
|
|
707
710
|
}
|
|
708
711
|
|
|
709
|
-
function make_$2(adm, key) {
|
|
710
|
-
var
|
|
711
|
-
|
|
712
|
-
var annotated = false;
|
|
713
|
-
var source = adm.target_;
|
|
714
|
-
|
|
715
|
-
while (source && source !== objectPrototype) {
|
|
716
|
-
var descriptor = getDescriptor(source, key);
|
|
717
|
-
|
|
718
|
-
if (descriptor) {
|
|
719
|
-
if (source !== adm.target_) {
|
|
720
|
-
// Prototype
|
|
721
|
-
if (isFlow(descriptor.value)) {
|
|
722
|
-
// A prototype could have been annotated already by other constructor,
|
|
723
|
-
// rest of the proto chain must be annotated already
|
|
724
|
-
annotated = true;
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false);
|
|
729
|
-
defineProperty(source, key, flowDescriptor);
|
|
730
|
-
} else {
|
|
731
|
-
var _flowDescriptor = createFlowDescriptor(adm, this, key, descriptor);
|
|
732
|
-
|
|
733
|
-
var definePropertyOutcome = adm.defineProperty_(key, _flowDescriptor);
|
|
712
|
+
function make_$2(adm, key, descriptor, source) {
|
|
713
|
+
var _this$options_;
|
|
734
714
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
715
|
+
// own
|
|
716
|
+
if (source === adm.target_) {
|
|
717
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
718
|
+
/* Cancel */
|
|
719
|
+
: 2
|
|
720
|
+
/* Continue */
|
|
721
|
+
;
|
|
722
|
+
} // prototype
|
|
723
|
+
// bound - must annotate protos to support super.flow()
|
|
740
724
|
|
|
741
|
-
annotated = true;
|
|
742
|
-
}
|
|
743
725
|
|
|
744
|
-
|
|
726
|
+
if (((_this$options_ = this.options_) == null ? void 0 : _this$options_.bound) && !isFlow(adm.target_[key])) {
|
|
727
|
+
if (this.extend_(adm, key, descriptor, false) === null) return 0
|
|
728
|
+
/* Cancel */
|
|
729
|
+
;
|
|
745
730
|
}
|
|
746
731
|
|
|
747
|
-
if (
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
// However we don't have to worry about missing prop,
|
|
754
|
-
// because the decorator must have been applied to something.
|
|
755
|
-
die(1, this.annotationType_, adm.name_ + "." + key.toString());
|
|
732
|
+
if (isFlow(descriptor.value)) {
|
|
733
|
+
// A prototype could have been annotated already by other constructor,
|
|
734
|
+
// rest of the proto chain must be annotated already
|
|
735
|
+
return 1
|
|
736
|
+
/* Break */
|
|
737
|
+
;
|
|
756
738
|
}
|
|
739
|
+
|
|
740
|
+
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false, false);
|
|
741
|
+
defineProperty(source, key, flowDescriptor);
|
|
742
|
+
return 2
|
|
743
|
+
/* Continue */
|
|
744
|
+
;
|
|
757
745
|
}
|
|
758
746
|
|
|
759
747
|
function extend_$2(adm, key, descriptor, proxyTrap) {
|
|
760
|
-
var
|
|
748
|
+
var _this$options_2;
|
|
749
|
+
|
|
750
|
+
var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, (_this$options_2 = this.options_) == null ? void 0 : _this$options_2.bound);
|
|
761
751
|
return adm.defineProperty_(key, flowDescriptor, proxyTrap);
|
|
762
752
|
}
|
|
763
753
|
|
|
@@ -770,15 +760,23 @@ function assertFlowDescriptor(adm, _ref, key, _ref2) {
|
|
|
770
760
|
}
|
|
771
761
|
}
|
|
772
762
|
|
|
773
|
-
function createFlowDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
|
|
763
|
+
function createFlowDescriptor(adm, annotation, key, descriptor, bound, // provides ability to disable safeDescriptors for prototypes
|
|
774
764
|
safeDescriptors) {
|
|
775
765
|
if (safeDescriptors === void 0) {
|
|
776
766
|
safeDescriptors = globalState.safeDescriptors;
|
|
777
767
|
}
|
|
778
768
|
|
|
779
769
|
assertFlowDescriptor(adm, annotation, key, descriptor);
|
|
770
|
+
var value = descriptor.value;
|
|
771
|
+
|
|
772
|
+
if (bound) {
|
|
773
|
+
var _adm$proxy_;
|
|
774
|
+
|
|
775
|
+
value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
|
776
|
+
}
|
|
777
|
+
|
|
780
778
|
return {
|
|
781
|
-
value: flow(
|
|
779
|
+
value: flow(value),
|
|
782
780
|
// Non-configurable for classes
|
|
783
781
|
// prevents accidental field redefinition in subclass
|
|
784
782
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -799,41 +797,12 @@ function createComputedAnnotation(name, options) {
|
|
|
799
797
|
};
|
|
800
798
|
}
|
|
801
799
|
|
|
802
|
-
function make_$3(adm, key) {
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
var descriptor = getDescriptor(source, key);
|
|
809
|
-
|
|
810
|
-
if (descriptor) {
|
|
811
|
-
assertComputedDescriptor(adm, this, key, descriptor);
|
|
812
|
-
var definePropertyOutcome = adm.defineComputedProperty_(key, _extends({}, this.options_, {
|
|
813
|
-
get: descriptor.get,
|
|
814
|
-
set: descriptor.set
|
|
815
|
-
}));
|
|
816
|
-
|
|
817
|
-
if (!definePropertyOutcome) {
|
|
818
|
-
// Intercepted
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
recordAnnotationApplied(adm, this, key);
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
source = Object.getPrototypeOf(source);
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
if (!((_adm$target_$storedAn = adm.target_[storedAnnotationsSymbol]) == null ? void 0 : _adm$target_$storedAn[key])) {
|
|
830
|
-
// Throw on missing key, except for decorators:
|
|
831
|
-
// Decorator annotations are collected from whole prototype chain.
|
|
832
|
-
// When called from super() some props may not exist yet.
|
|
833
|
-
// However we don't have to worry about missing prop,
|
|
834
|
-
// because the decorator must have been applied to something.
|
|
835
|
-
die(1, this.annotationType_, adm.name_ + "." + key.toString());
|
|
836
|
-
}
|
|
800
|
+
function make_$3(adm, key, descriptor) {
|
|
801
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
802
|
+
/* Cancel */
|
|
803
|
+
: 1
|
|
804
|
+
/* Break */
|
|
805
|
+
;
|
|
837
806
|
}
|
|
838
807
|
|
|
839
808
|
function extend_$3(adm, key, descriptor, proxyTrap) {
|
|
@@ -862,56 +831,130 @@ function createObservableAnnotation(name, options) {
|
|
|
862
831
|
};
|
|
863
832
|
}
|
|
864
833
|
|
|
865
|
-
function make_$4(adm, key) {
|
|
866
|
-
|
|
834
|
+
function make_$4(adm, key, descriptor) {
|
|
835
|
+
return this.extend_(adm, key, descriptor, false) === null ? 0
|
|
836
|
+
/* Cancel */
|
|
837
|
+
: 1
|
|
838
|
+
/* Break */
|
|
839
|
+
;
|
|
840
|
+
}
|
|
867
841
|
|
|
868
|
-
|
|
869
|
-
|
|
842
|
+
function extend_$4(adm, key, descriptor, proxyTrap) {
|
|
843
|
+
var _this$options_$enhanc, _this$options_;
|
|
844
|
+
|
|
845
|
+
assertObservableDescriptor(adm, this, key, descriptor);
|
|
846
|
+
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);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
function assertObservableDescriptor(adm, _ref, key, descriptor) {
|
|
850
|
+
var annotationType_ = _ref.annotationType_;
|
|
851
|
+
|
|
852
|
+
if (process.env.NODE_ENV !== "production" && !("value" in descriptor)) {
|
|
853
|
+
die("Cannot apply '" + annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + annotationType_ + "' cannot be used on getter/setter properties"));
|
|
854
|
+
}
|
|
855
|
+
}
|
|
870
856
|
|
|
871
|
-
|
|
872
|
-
|
|
857
|
+
var AUTO = "true";
|
|
858
|
+
var autoAnnotation = /*#__PURE__*/createAutoAnnotation();
|
|
859
|
+
function createAutoAnnotation(options) {
|
|
860
|
+
return {
|
|
861
|
+
annotationType_: AUTO,
|
|
862
|
+
options_: options,
|
|
863
|
+
make_: make_$5,
|
|
864
|
+
extend_: extend_$5
|
|
865
|
+
};
|
|
866
|
+
}
|
|
873
867
|
|
|
874
|
-
|
|
875
|
-
|
|
868
|
+
function make_$5(adm, key, descriptor, source) {
|
|
869
|
+
var _this$options_3, _this$options_4;
|
|
876
870
|
|
|
877
|
-
|
|
878
|
-
|
|
871
|
+
// getter -> computed
|
|
872
|
+
if (descriptor.get) {
|
|
873
|
+
return computed.make_(adm, key, descriptor, source);
|
|
874
|
+
} // lone setter -> action setter
|
|
879
875
|
|
|
880
|
-
if (!definePropertyOutcome) {
|
|
881
|
-
// Intercepted
|
|
882
|
-
return;
|
|
883
|
-
}
|
|
884
876
|
|
|
885
|
-
|
|
886
|
-
|
|
877
|
+
if (descriptor.set) {
|
|
878
|
+
// TODO make action applicable to setter and delegate to action.make_
|
|
879
|
+
var set = createAction(key.toString(), descriptor.set); // own
|
|
880
|
+
|
|
881
|
+
if (source === adm.target_) {
|
|
882
|
+
return adm.defineProperty_(key, {
|
|
883
|
+
configurable: globalState.safeDescriptors ? adm.isPlainObject_ : true,
|
|
884
|
+
set: set
|
|
885
|
+
}) === null ? 0
|
|
886
|
+
/* Cancel */
|
|
887
|
+
: 2
|
|
888
|
+
/* Continue */
|
|
889
|
+
;
|
|
890
|
+
} // proto
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
defineProperty(source, key, {
|
|
894
|
+
configurable: true,
|
|
895
|
+
set: set
|
|
896
|
+
});
|
|
897
|
+
return 2
|
|
898
|
+
/* Continue */
|
|
899
|
+
;
|
|
900
|
+
} // function on proto -> autoAction/flow
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
if (source !== adm.target_ && typeof descriptor.value === "function") {
|
|
904
|
+
var _this$options_2;
|
|
905
|
+
|
|
906
|
+
if (isGenerator(descriptor.value)) {
|
|
907
|
+
var _this$options_;
|
|
908
|
+
|
|
909
|
+
var flowAnnotation = ((_this$options_ = this.options_) == null ? void 0 : _this$options_.autoBind) ? flow.bound : flow;
|
|
910
|
+
return flowAnnotation.make_(adm, key, descriptor, source);
|
|
887
911
|
}
|
|
888
912
|
|
|
889
|
-
|
|
890
|
-
|
|
913
|
+
var actionAnnotation = ((_this$options_2 = this.options_) == null ? void 0 : _this$options_2.autoBind) ? autoAction.bound : autoAction;
|
|
914
|
+
return actionAnnotation.make_(adm, key, descriptor, source);
|
|
915
|
+
} // other -> observable
|
|
916
|
+
// Copy props from proto as well, see test:
|
|
917
|
+
// "decorate should work with Object.create"
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
var observableAnnotation = ((_this$options_3 = this.options_) == null ? void 0 : _this$options_3.deep) === false ? observable.ref : observable; // if function respect autoBind option
|
|
891
921
|
|
|
892
|
-
if (
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
// However we don't have to worry about missing prop,
|
|
897
|
-
// because the decorator must have been applied to something.
|
|
898
|
-
die(1, this.annotationType_, adm.name_ + "." + key.toString());
|
|
922
|
+
if (typeof descriptor.value === "function" && ((_this$options_4 = this.options_) == null ? void 0 : _this$options_4.autoBind)) {
|
|
923
|
+
var _adm$proxy_;
|
|
924
|
+
|
|
925
|
+
descriptor.value = descriptor.value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
|
899
926
|
}
|
|
927
|
+
|
|
928
|
+
return observableAnnotation.make_(adm, key, descriptor, source);
|
|
900
929
|
}
|
|
901
930
|
|
|
902
|
-
function extend_$
|
|
903
|
-
var _this$
|
|
931
|
+
function extend_$5(adm, key, descriptor, proxyTrap) {
|
|
932
|
+
var _this$options_5, _this$options_6;
|
|
904
933
|
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
934
|
+
// getter -> computed
|
|
935
|
+
if (descriptor.get) {
|
|
936
|
+
return computed.extend_(adm, key, descriptor, proxyTrap);
|
|
937
|
+
} // lone setter -> action setter
|
|
908
938
|
|
|
909
|
-
function assertObservableDescriptor(adm, _ref, key, descriptor) {
|
|
910
|
-
var annotationType_ = _ref.annotationType_;
|
|
911
939
|
|
|
912
|
-
if (
|
|
913
|
-
|
|
940
|
+
if (descriptor.set) {
|
|
941
|
+
// TODO make action applicable to setter and delegate to action.extend_
|
|
942
|
+
return adm.defineProperty_(key, {
|
|
943
|
+
configurable: globalState.safeDescriptors ? adm.isPlainObject_ : true,
|
|
944
|
+
set: createAction(key.toString(), descriptor.set)
|
|
945
|
+
}, proxyTrap);
|
|
946
|
+
} // other -> observable
|
|
947
|
+
// if function respect autoBind option
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
if (typeof descriptor.value === "function" && ((_this$options_5 = this.options_) == null ? void 0 : _this$options_5.autoBind)) {
|
|
951
|
+
var _adm$proxy_2;
|
|
952
|
+
|
|
953
|
+
descriptor.value = descriptor.value.bind((_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_);
|
|
914
954
|
}
|
|
955
|
+
|
|
956
|
+
var observableAnnotation = ((_this$options_6 = this.options_) == null ? void 0 : _this$options_6.deep) === false ? observable.ref : observable;
|
|
957
|
+
return observableAnnotation.extend_(adm, key, descriptor, proxyTrap);
|
|
915
958
|
}
|
|
916
959
|
|
|
917
960
|
// in the majority of cases
|
|
@@ -941,7 +984,9 @@ function getEnhancerFromOptions(options) {
|
|
|
941
984
|
return options.deep === true ? deepEnhancer : options.deep === false ? referenceEnhancer : getEnhancerFromAnnotation(options.defaultDecorator);
|
|
942
985
|
}
|
|
943
986
|
function getAnnotationFromOptions(options) {
|
|
944
|
-
|
|
987
|
+
var _options$defaultDecor;
|
|
988
|
+
|
|
989
|
+
return options ? (_options$defaultDecor = options.defaultDecorator) != null ? _options$defaultDecor : createAutoAnnotation(options) : undefined;
|
|
945
990
|
}
|
|
946
991
|
function getEnhancerFromAnnotation(annotation) {
|
|
947
992
|
var _annotation$options_$, _annotation$options_;
|
|
@@ -2130,8 +2175,16 @@ function propagateChangeConfirmed(observable) {
|
|
|
2130
2175
|
if (observable.lowestObserverState_ === IDerivationState_.STALE_) return;
|
|
2131
2176
|
observable.lowestObserverState_ = IDerivationState_.STALE_;
|
|
2132
2177
|
observable.observers_.forEach(function (d) {
|
|
2133
|
-
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_)
|
|
2134
|
-
|
|
2178
|
+
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
|
|
2179
|
+
d.dependenciesState_ = IDerivationState_.STALE_;
|
|
2180
|
+
|
|
2181
|
+
if (process.env.NODE_ENV !== "production" && d.isTracing_ !== TraceMode.NONE) {
|
|
2182
|
+
logTraceInfo(d, observable);
|
|
2183
|
+
}
|
|
2184
|
+
} else if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_ // this happens during computing of `d`, just keep lowestObserverState up to date.
|
|
2185
|
+
) {
|
|
2186
|
+
observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
|
|
2187
|
+
}
|
|
2135
2188
|
}); // invariantLOS(observable, "confirmed end");
|
|
2136
2189
|
} // Used by computed when its dependency changed, but we don't wan't to immediately recompute.
|
|
2137
2190
|
|
|
@@ -2142,11 +2195,6 @@ function propagateMaybeChanged(observable) {
|
|
|
2142
2195
|
observable.observers_.forEach(function (d) {
|
|
2143
2196
|
if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
2144
2197
|
d.dependenciesState_ = IDerivationState_.POSSIBLY_STALE_;
|
|
2145
|
-
|
|
2146
|
-
if (process.env.NODE_ENV !== "production" && d.isTracing_ !== TraceMode.NONE) {
|
|
2147
|
-
logTraceInfo(d, observable);
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
2198
|
d.onBecomeStale_();
|
|
2151
2199
|
}
|
|
2152
2200
|
}); // invariantLOS(observable, "maybe end");
|
|
@@ -2782,6 +2830,9 @@ function isFlowCancellationError(error) {
|
|
|
2782
2830
|
return error instanceof FlowCancellationError;
|
|
2783
2831
|
}
|
|
2784
2832
|
var flowAnnotation = /*#__PURE__*/createFlowAnnotation("flow");
|
|
2833
|
+
var flowBoundAnnotation = /*#__PURE__*/createFlowAnnotation("flow.bound", {
|
|
2834
|
+
bound: true
|
|
2835
|
+
});
|
|
2785
2836
|
var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
2786
2837
|
// @flow
|
|
2787
2838
|
if (isStringish(arg2)) {
|
|
@@ -2867,6 +2918,7 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2867
2918
|
res.isMobXFlow = true;
|
|
2868
2919
|
return res;
|
|
2869
2920
|
}, flowAnnotation);
|
|
2921
|
+
flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
|
|
2870
2922
|
|
|
2871
2923
|
function cancelPromise(promise) {
|
|
2872
2924
|
if (isFunction(promise.cancel)) promise.cancel();
|
|
@@ -3091,6 +3143,20 @@ function get(obj, key) {
|
|
|
3091
3143
|
|
|
3092
3144
|
die(11);
|
|
3093
3145
|
}
|
|
3146
|
+
function apiDefineProperty(obj, key, descriptor) {
|
|
3147
|
+
if (isObservableObject(obj)) {
|
|
3148
|
+
return obj[$mobx].defineProperty_(key, descriptor);
|
|
3149
|
+
}
|
|
3150
|
+
|
|
3151
|
+
die(39);
|
|
3152
|
+
}
|
|
3153
|
+
function apiOwnKeys(obj) {
|
|
3154
|
+
if (isObservableObject(obj)) {
|
|
3155
|
+
return obj[$mobx].ownKeys_();
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
die(38);
|
|
3159
|
+
}
|
|
3094
3160
|
|
|
3095
3161
|
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
3096
3162
|
if (isFunction(cbOrFire)) return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);else return observeObservable(thing, propOrCb, cbOrFire);
|
|
@@ -3111,7 +3177,7 @@ function cache(map, key, value) {
|
|
|
3111
3177
|
|
|
3112
3178
|
function toJSHelper(source, __alreadySeen) {
|
|
3113
3179
|
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) return source;
|
|
3114
|
-
if (isObservableValue(source)) return toJSHelper(source.get(), __alreadySeen);
|
|
3180
|
+
if (isObservableValue(source) || isComputedValue(source)) return toJSHelper(source.get(), __alreadySeen);
|
|
3115
3181
|
|
|
3116
3182
|
if (__alreadySeen.has(source)) {
|
|
3117
3183
|
return __alreadySeen.get(source);
|
|
@@ -3143,12 +3209,12 @@ function toJSHelper(source, __alreadySeen) {
|
|
|
3143
3209
|
return _res2;
|
|
3144
3210
|
} else {
|
|
3145
3211
|
// must be observable object
|
|
3146
|
-
keys(source); // make sure keys are observed
|
|
3147
|
-
|
|
3148
3212
|
var _res3 = cache(__alreadySeen, source, {});
|
|
3149
3213
|
|
|
3150
|
-
|
|
3151
|
-
|
|
3214
|
+
apiOwnKeys(source).forEach(function (key) {
|
|
3215
|
+
if (objectPrototype.propertyIsEnumerable.call(source, key)) {
|
|
3216
|
+
_res3[key] = toJSHelper(source[key], __alreadySeen);
|
|
3217
|
+
}
|
|
3152
3218
|
});
|
|
3153
3219
|
return _res3;
|
|
3154
3220
|
}
|
|
@@ -3319,7 +3385,7 @@ var objectProxyTraps = {
|
|
|
3319
3385
|
return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
|
3320
3386
|
},
|
|
3321
3387
|
ownKeys: function ownKeys(target) {
|
|
3322
|
-
if (process.env.NODE_ENV !== "production" && globalState.trackingDerivation) warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use
|
|
3388
|
+
if (process.env.NODE_ENV !== "production" && globalState.trackingDerivation) warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
|
3323
3389
|
return getAdm(target).ownKeys_();
|
|
3324
3390
|
},
|
|
3325
3391
|
preventExtensions: function preventExtensions(target) {
|
|
@@ -3406,57 +3472,39 @@ function makeObservable(target, annotations, options) {
|
|
|
3406
3472
|
}
|
|
3407
3473
|
|
|
3408
3474
|
return target;
|
|
3409
|
-
}
|
|
3475
|
+
} // proto[keysSymbol] = new Set<PropertyKey>()
|
|
3476
|
+
|
|
3477
|
+
var keysSymbol = /*#__PURE__*/Symbol("mobx-keys");
|
|
3410
3478
|
function makeAutoObservable(target, overrides, options) {
|
|
3411
3479
|
if (process.env.NODE_ENV !== "production") {
|
|
3412
3480
|
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) die("'makeAutoObservable' can only be used for classes that don't have a superclass");
|
|
3413
3481
|
if (isObservableObject(target)) die("makeAutoObservable can only be used on objects not already made observable");
|
|
3414
|
-
} // Optimization
|
|
3415
|
-
//
|
|
3482
|
+
} // Optimization: avoid visiting protos
|
|
3483
|
+
// Assumes that annotation.make_/.extend_ works the same for plain objects
|
|
3416
3484
|
|
|
3417
3485
|
|
|
3418
3486
|
if (isPlainObject(target)) {
|
|
3419
3487
|
return extendObservable(target, target, overrides, options);
|
|
3420
3488
|
}
|
|
3421
3489
|
|
|
3422
|
-
var adm = asObservableObject(target, options)[$mobx];
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
try {
|
|
3426
|
-
// Use cached inferred annotations if available (only in classes)
|
|
3427
|
-
if (target[inferredAnnotationsSymbol]) {
|
|
3428
|
-
target[inferredAnnotationsSymbol].forEach(function (value, key) {
|
|
3429
|
-
return adm.make_(key, value);
|
|
3430
|
-
}); // Overrides are not cached, unless `true`, see #2832
|
|
3431
|
-
|
|
3432
|
-
if (overrides) {
|
|
3433
|
-
ownKeys(overrides).forEach(function (key) {
|
|
3434
|
-
var annotation = overrides[key];
|
|
3435
|
-
|
|
3436
|
-
if (annotation !== true) {
|
|
3437
|
-
adm.make_(key, annotation);
|
|
3438
|
-
}
|
|
3439
|
-
});
|
|
3440
|
-
}
|
|
3441
|
-
} else {
|
|
3442
|
-
var _ignoreKeys;
|
|
3443
|
-
|
|
3444
|
-
var ignoreKeys = (_ignoreKeys = {}, _ignoreKeys[$mobx] = 1, _ignoreKeys[inferredAnnotationsSymbol] = 1, _ignoreKeys.constructor = 1, _ignoreKeys);
|
|
3490
|
+
var adm = asObservableObject(target, options)[$mobx]; // Optimization: cache keys on proto
|
|
3491
|
+
// Assumes makeAutoObservable can be called only once per object and can't be used in subclass
|
|
3445
3492
|
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3493
|
+
if (!target[keysSymbol]) {
|
|
3494
|
+
var proto = Object.getPrototypeOf(target);
|
|
3495
|
+
var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
|
|
3496
|
+
keys["delete"]("constructor");
|
|
3497
|
+
keys["delete"]($mobx);
|
|
3498
|
+
addHiddenProp(proto, keysSymbol, keys);
|
|
3499
|
+
}
|
|
3452
3500
|
|
|
3453
|
-
|
|
3501
|
+
startBatch();
|
|
3454
3502
|
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
}
|
|
3503
|
+
try {
|
|
3504
|
+
target[keysSymbol].forEach(function (key) {
|
|
3505
|
+
return adm.make_(key, // must pass "undefined" for { key: undefined }
|
|
3506
|
+
!overrides ? true : key in overrides ? overrides[key] : true);
|
|
3507
|
+
});
|
|
3460
3508
|
} finally {
|
|
3461
3509
|
endBatch();
|
|
3462
3510
|
}
|
|
@@ -4662,30 +4710,23 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4662
4710
|
|
|
4663
4711
|
var isObservableSet = /*#__PURE__*/createInstanceofPredicate("ObservableSet", ObservableSet);
|
|
4664
4712
|
|
|
4665
|
-
var inferredAnnotationsSymbol = /*#__PURE__*/Symbol("mobx-inferred-annotations");
|
|
4666
4713
|
var descriptorCache = /*#__PURE__*/Object.create(null);
|
|
4667
4714
|
var REMOVE = "remove";
|
|
4668
4715
|
var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
4669
4716
|
function ObservableObjectAdministration(target_, values_, name_, // Used anytime annotation is not explicitely provided
|
|
4670
|
-
defaultAnnotation_
|
|
4671
|
-
autoBind_) {
|
|
4717
|
+
defaultAnnotation_) {
|
|
4672
4718
|
if (values_ === void 0) {
|
|
4673
4719
|
values_ = new Map();
|
|
4674
4720
|
}
|
|
4675
4721
|
|
|
4676
4722
|
if (defaultAnnotation_ === void 0) {
|
|
4677
|
-
defaultAnnotation_ =
|
|
4678
|
-
}
|
|
4679
|
-
|
|
4680
|
-
if (autoBind_ === void 0) {
|
|
4681
|
-
autoBind_ = false;
|
|
4723
|
+
defaultAnnotation_ = autoAnnotation;
|
|
4682
4724
|
}
|
|
4683
4725
|
|
|
4684
4726
|
this.target_ = void 0;
|
|
4685
4727
|
this.values_ = void 0;
|
|
4686
4728
|
this.name_ = void 0;
|
|
4687
4729
|
this.defaultAnnotation_ = void 0;
|
|
4688
|
-
this.autoBind_ = void 0;
|
|
4689
4730
|
this.keysAtom_ = void 0;
|
|
4690
4731
|
this.changeListeners_ = void 0;
|
|
4691
4732
|
this.interceptors_ = void 0;
|
|
@@ -4697,7 +4738,6 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4697
4738
|
this.values_ = values_;
|
|
4698
4739
|
this.name_ = name_;
|
|
4699
4740
|
this.defaultAnnotation_ = defaultAnnotation_;
|
|
4700
|
-
this.autoBind_ = autoBind_;
|
|
4701
4741
|
this.keysAtom_ = new Atom(process.env.NODE_ENV !== "production" ? this.name_ + ".keys" : "ObservableObject.keys"); // Optimization: we use this frequently
|
|
4702
4742
|
|
|
4703
4743
|
this.isPlainObject_ = isPlainObject(this.target_);
|
|
@@ -4706,10 +4746,6 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4706
4746
|
die("defaultAnnotation must be valid annotation");
|
|
4707
4747
|
}
|
|
4708
4748
|
|
|
4709
|
-
if (process.env.NODE_ENV !== "production" && typeof this.autoBind_ !== "boolean") {
|
|
4710
|
-
die("autoBind must be boolean");
|
|
4711
|
-
}
|
|
4712
|
-
|
|
4713
4749
|
if (process.env.NODE_ENV !== "production") {
|
|
4714
4750
|
// Prepare structure for tracking which fields were already annotated
|
|
4715
4751
|
this.appliedAnnotations_ = {};
|
|
@@ -4778,7 +4814,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4778
4814
|
/**
|
|
4779
4815
|
* @param {PropertyKey} key
|
|
4780
4816
|
* @param {any} value
|
|
4781
|
-
* @param {Annotation|boolean} annotation true -
|
|
4817
|
+
* @param {Annotation|boolean} annotation true - use default annotation, false - copy as is
|
|
4782
4818
|
* @param {boolean} proxyTrap whether it's called from proxy trap
|
|
4783
4819
|
* @returns {boolean|null} true on success, false on failure (proxyTrap + non-configurable), null when cancelled by interceptor
|
|
4784
4820
|
*/
|
|
@@ -4833,13 +4869,13 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4833
4869
|
}
|
|
4834
4870
|
/**
|
|
4835
4871
|
* @param {PropertyKey} key
|
|
4836
|
-
* @param {Annotation|boolean} annotation true -
|
|
4872
|
+
* @param {Annotation|boolean} annotation true - use default annotation, false - ignore prop
|
|
4837
4873
|
*/
|
|
4838
4874
|
;
|
|
4839
4875
|
|
|
4840
4876
|
_proto.make_ = function make_(key, annotation) {
|
|
4841
4877
|
if (annotation === true) {
|
|
4842
|
-
annotation = this.
|
|
4878
|
+
annotation = this.defaultAnnotation_;
|
|
4843
4879
|
}
|
|
4844
4880
|
|
|
4845
4881
|
if (annotation === false) {
|
|
@@ -4847,12 +4883,46 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4847
4883
|
}
|
|
4848
4884
|
|
|
4849
4885
|
assertAnnotable(this, annotation, key);
|
|
4850
|
-
|
|
4886
|
+
|
|
4887
|
+
if (!(key in this.target_)) {
|
|
4888
|
+
var _this$target_$storedA;
|
|
4889
|
+
|
|
4890
|
+
// Throw on missing key, except for decorators:
|
|
4891
|
+
// Decorator annotations are collected from whole prototype chain.
|
|
4892
|
+
// When called from super() some props may not exist yet.
|
|
4893
|
+
// However we don't have to worry about missing prop,
|
|
4894
|
+
// because the decorator must have been applied to something.
|
|
4895
|
+
if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) == null ? void 0 : _this$target_$storedA[key]) {
|
|
4896
|
+
return; // will be annotated by subclass constructor
|
|
4897
|
+
} else {
|
|
4898
|
+
die(1, annotation.annotationType_, this.name_ + "." + key.toString());
|
|
4899
|
+
}
|
|
4900
|
+
}
|
|
4901
|
+
|
|
4902
|
+
var source = this.target_;
|
|
4903
|
+
|
|
4904
|
+
while (source && source !== objectPrototype) {
|
|
4905
|
+
var descriptor = getDescriptor(source, key);
|
|
4906
|
+
|
|
4907
|
+
if (descriptor) {
|
|
4908
|
+
var outcome = annotation.make_(this, key, descriptor, source);
|
|
4909
|
+
if (outcome === 0
|
|
4910
|
+
/* Cancel */
|
|
4911
|
+
) return;
|
|
4912
|
+
if (outcome === 1
|
|
4913
|
+
/* Break */
|
|
4914
|
+
) break;
|
|
4915
|
+
}
|
|
4916
|
+
|
|
4917
|
+
source = Object.getPrototypeOf(source);
|
|
4918
|
+
}
|
|
4919
|
+
|
|
4920
|
+
recordAnnotationApplied(this, annotation, key);
|
|
4851
4921
|
}
|
|
4852
4922
|
/**
|
|
4853
4923
|
* @param {PropertyKey} key
|
|
4854
4924
|
* @param {PropertyDescriptor} descriptor
|
|
4855
|
-
* @param {Annotation|boolean} annotation true -
|
|
4925
|
+
* @param {Annotation|boolean} annotation true - use default annotation, false - copy as is
|
|
4856
4926
|
* @param {boolean} proxyTrap whether it's called from proxy trap
|
|
4857
4927
|
* @returns {boolean|null} true on success, false on failure (proxyTrap + non-configurable), null when cancelled by interceptor
|
|
4858
4928
|
*/
|
|
@@ -4864,7 +4934,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4864
4934
|
}
|
|
4865
4935
|
|
|
4866
4936
|
if (annotation === true) {
|
|
4867
|
-
annotation =
|
|
4937
|
+
annotation = this.defaultAnnotation_;
|
|
4868
4938
|
}
|
|
4869
4939
|
|
|
4870
4940
|
if (annotation === false) {
|
|
@@ -4879,46 +4949,6 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4879
4949
|
}
|
|
4880
4950
|
|
|
4881
4951
|
return outcome;
|
|
4882
|
-
};
|
|
4883
|
-
|
|
4884
|
-
_proto.inferAnnotation_ = function inferAnnotation_(key) {
|
|
4885
|
-
var _this$target_$inferre;
|
|
4886
|
-
|
|
4887
|
-
// Inherited is fine - annotation cannot differ in subclass
|
|
4888
|
-
var annotation = (_this$target_$inferre = this.target_[inferredAnnotationsSymbol]) == null ? void 0 : _this$target_$inferre.get(key);
|
|
4889
|
-
if (annotation) return annotation;
|
|
4890
|
-
var current = this.target_;
|
|
4891
|
-
|
|
4892
|
-
while (current && current !== objectPrototype) {
|
|
4893
|
-
var descriptor = getDescriptor(current, key);
|
|
4894
|
-
|
|
4895
|
-
if (descriptor) {
|
|
4896
|
-
annotation = inferAnnotationFromDescriptor(descriptor, this.defaultAnnotation_, this.autoBind_);
|
|
4897
|
-
break;
|
|
4898
|
-
}
|
|
4899
|
-
|
|
4900
|
-
current = Object.getPrototypeOf(current);
|
|
4901
|
-
} // Not found (false means ignore)
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
if (annotation === undefined) {
|
|
4905
|
-
die(1, "true", key);
|
|
4906
|
-
} // Cache the annotation.
|
|
4907
|
-
// Note we can do this only because annotation and field can't change.
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
if (!this.isPlainObject_) {
|
|
4911
|
-
// We could also place it on furthest proto, shoudn't matter
|
|
4912
|
-
var closestProto = Object.getPrototypeOf(this.target_);
|
|
4913
|
-
|
|
4914
|
-
if (!hasProp(closestProto, inferredAnnotationsSymbol)) {
|
|
4915
|
-
addHiddenProp(closestProto, inferredAnnotationsSymbol, new Map());
|
|
4916
|
-
}
|
|
4917
|
-
|
|
4918
|
-
closestProto[inferredAnnotationsSymbol].set(key, annotation);
|
|
4919
|
-
}
|
|
4920
|
-
|
|
4921
|
-
return annotation;
|
|
4922
4952
|
}
|
|
4923
4953
|
/**
|
|
4924
4954
|
* @param {PropertyKey} key
|
|
@@ -5023,11 +5053,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5023
5053
|
defineProperty(this.target_, key, descriptor);
|
|
5024
5054
|
}
|
|
5025
5055
|
|
|
5026
|
-
var
|
|
5027
|
-
|
|
5028
|
-
this.values_.set(key, _observable); // Notify (value possibly changed by ObservableValue)
|
|
5056
|
+
var observable = new ObservableValue(value, enhancer, process.env.NODE_ENV !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key", false);
|
|
5057
|
+
this.values_.set(key, observable); // Notify (value possibly changed by ObservableValue)
|
|
5029
5058
|
|
|
5030
|
-
this.notifyPropertyAddition_(key,
|
|
5059
|
+
this.notifyPropertyAddition_(key, observable.value_);
|
|
5031
5060
|
} finally {
|
|
5032
5061
|
endBatch();
|
|
5033
5062
|
}
|
|
@@ -5125,13 +5154,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5125
5154
|
startBatch();
|
|
5126
5155
|
var notify = hasListeners(this);
|
|
5127
5156
|
var notifySpy = process.env.NODE_ENV !== "production" && isSpyEnabled();
|
|
5128
|
-
|
|
5129
|
-
var _observable2 = this.values_.get(key); // Value needed for spies/listeners
|
|
5130
|
-
|
|
5157
|
+
var observable = this.values_.get(key); // Value needed for spies/listeners
|
|
5131
5158
|
|
|
5132
5159
|
var value = undefined; // Optimization: don't pull the value unless we will need it
|
|
5133
5160
|
|
|
5134
|
-
if (!
|
|
5161
|
+
if (!observable && (notify || notifySpy)) {
|
|
5135
5162
|
var _getDescriptor;
|
|
5136
5163
|
|
|
5137
5164
|
value = (_getDescriptor = getDescriptor(this.target_, key)) == null ? void 0 : _getDescriptor.value;
|
|
@@ -5152,15 +5179,15 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5152
5179
|
} // Clear observable
|
|
5153
5180
|
|
|
5154
5181
|
|
|
5155
|
-
if (
|
|
5182
|
+
if (observable) {
|
|
5156
5183
|
this.values_["delete"](key); // for computed, value is undefined
|
|
5157
5184
|
|
|
5158
|
-
if (
|
|
5159
|
-
value =
|
|
5185
|
+
if (observable instanceof ObservableValue) {
|
|
5186
|
+
value = observable.value_;
|
|
5160
5187
|
} // Notify: autorun(() => obj[key]), see #1796
|
|
5161
5188
|
|
|
5162
5189
|
|
|
5163
|
-
propagateChanged(
|
|
5190
|
+
propagateChanged(observable);
|
|
5164
5191
|
} // Notify "keys/entries/values" observers
|
|
5165
5192
|
|
|
5166
5193
|
|
|
@@ -5264,7 +5291,7 @@ function asObservableObject(target, options) {
|
|
|
5264
5291
|
|
|
5265
5292
|
if (process.env.NODE_ENV !== "production" && !Object.isExtensible(target)) die("Cannot make the designated object observable; it is not extensible");
|
|
5266
5293
|
var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : process.env.NODE_ENV !== "production" ? (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() : "ObservableObject";
|
|
5267
|
-
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options)
|
|
5294
|
+
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
|
|
5268
5295
|
addHiddenProp(target, $mobx, adm);
|
|
5269
5296
|
return target;
|
|
5270
5297
|
}
|
|
@@ -5698,24 +5725,6 @@ function getSelf() {
|
|
|
5698
5725
|
return this;
|
|
5699
5726
|
}
|
|
5700
5727
|
|
|
5701
|
-
/**
|
|
5702
|
-
* Infers the best fitting annotation from property descriptor or false if the field shoudn't be annotated
|
|
5703
|
-
* - getter(+setter) -> computed
|
|
5704
|
-
* - setter w/o getter -> false (ignore)
|
|
5705
|
-
* - flow -> false (ignore)
|
|
5706
|
-
* - generator -> flow
|
|
5707
|
-
* - action -> false (ignore)
|
|
5708
|
-
* - function -> action (optionally bound)
|
|
5709
|
-
* - other -> defaultAnnotation
|
|
5710
|
-
*/
|
|
5711
|
-
|
|
5712
|
-
function inferAnnotationFromDescriptor(desc, defaultAnnotation, autoBind) {
|
|
5713
|
-
if (desc.get) return computed;
|
|
5714
|
-
if (desc.set) return false; // ignore lone setter
|
|
5715
|
-
// If already wrapped in action/flow, don't do that another time, but assume it is already set up properly.
|
|
5716
|
-
|
|
5717
|
-
return isFunction(desc.value) ? isGenerator(desc.value) ? isFlow(desc.value) ? false : flow : isAction(desc.value) ? false : autoBind ? autoAction.bound : autoAction : defaultAnnotation;
|
|
5718
|
-
}
|
|
5719
5728
|
function isAnnotation(thing) {
|
|
5720
5729
|
return (// Can be function
|
|
5721
5730
|
thing instanceof Object && typeof thing.annotationType_ === "string" && isFunction(thing.make_) && isFunction(thing.extend_)
|
|
@@ -5758,5 +5767,5 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
|
|
|
5758
5767
|
});
|
|
5759
5768
|
}
|
|
5760
5769
|
|
|
5761
|
-
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 };
|
|
5770
|
+
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 };
|
|
5762
5771
|
//# sourceMappingURL=mobx.esm.js.map
|