mobx-react 5.4.2 → 5.4.3
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/.browserlistrc +6 -6
- package/.editorconfig +6 -6
- package/.prettierrc +4 -4
- package/.travis.yml +9 -9
- package/CHANGELOG.md +518 -514
- package/LICENSE +21 -21
- package/README.md +517 -517
- package/custom.d.ts +140 -140
- package/custom.js +75 -87
- package/custom.module.js +72 -84
- package/empty.js +3 -3
- package/index.d.ts +140 -140
- package/index.js +75 -87
- package/index.min.js +1 -1
- package/index.module.js +72 -84
- package/native.d.ts +140 -140
- package/native.js +72 -84
- package/package.json +4 -4
- package/yarn.lock +5886 -5863
package/index.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React__default, { Component, createElement, PureComponent, forwardRef, Children } from 'react';
|
|
2
1
|
import { isObservableArray, isObservableObject, isObservableMap, untracked, createAtom, Reaction, _allowStateChanges, $mobx, spy, configure, getDebugName } from 'mobx';
|
|
2
|
+
import React__default, { Component, createElement, PureComponent, forwardRef, Children } from 'react';
|
|
3
3
|
import { findDOMNode, unstable_batchedUpdates } from 'react-dom';
|
|
4
4
|
|
|
5
5
|
function _typeof(obj) {
|
|
@@ -53,25 +53,6 @@ function _defineProperty(obj, key, value) {
|
|
|
53
53
|
return obj;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function _objectSpread(target) {
|
|
57
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
58
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
59
|
-
var ownKeys = Object.keys(source);
|
|
60
|
-
|
|
61
|
-
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
62
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
|
63
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
ownKeys.forEach(function (key) {
|
|
68
|
-
_defineProperty(target, key, source[key]);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return target;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
56
|
function _inherits(subClass, superClass) {
|
|
76
57
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
77
58
|
throw new TypeError("Super expression must either be null or a function");
|
|
@@ -131,33 +112,35 @@ function createCommonjsModule(fn, module) {
|
|
|
131
112
|
|
|
132
113
|
var reactIs_production_min = createCommonjsModule(function (module, exports) {
|
|
133
114
|
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
134
|
-
var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.forward_ref"):60112,
|
|
135
|
-
function
|
|
136
|
-
exports.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===
|
|
137
|
-
exports.isForwardRef=function(a){return
|
|
115
|
+
var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,r=b?Symbol.for("react.memo"):
|
|
116
|
+
60115,t=b?Symbol.for("react.lazy"):60116;function u(a){if("object"===typeof a&&null!==a){var q=a.$$typeof;switch(q){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:return a;default:switch(a=a&&a.$$typeof,a){case k:case n:case h:return a;default:return q}}case d:return q}}}function v(a){return u(a)===m}exports.typeOf=u;exports.AsyncMode=l;exports.ConcurrentMode=m;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=n;exports.Fragment=e;
|
|
117
|
+
exports.Profiler=g;exports.Portal=d;exports.StrictMode=f;exports.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k||a.$$typeof===n)};exports.isAsyncMode=function(a){return v(a)||u(a)===l};exports.isConcurrentMode=v;exports.isContextConsumer=function(a){return u(a)===k};exports.isContextProvider=function(a){return u(a)===h};
|
|
118
|
+
exports.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};exports.isForwardRef=function(a){return u(a)===n};exports.isFragment=function(a){return u(a)===e};exports.isProfiler=function(a){return u(a)===g};exports.isPortal=function(a){return u(a)===d};exports.isStrictMode=function(a){return u(a)===f};
|
|
138
119
|
});
|
|
139
120
|
|
|
140
121
|
unwrapExports(reactIs_production_min);
|
|
141
122
|
var reactIs_production_min_1 = reactIs_production_min.typeOf;
|
|
142
123
|
var reactIs_production_min_2 = reactIs_production_min.AsyncMode;
|
|
143
|
-
var reactIs_production_min_3 = reactIs_production_min.
|
|
144
|
-
var reactIs_production_min_4 = reactIs_production_min.
|
|
145
|
-
var reactIs_production_min_5 = reactIs_production_min.
|
|
146
|
-
var reactIs_production_min_6 = reactIs_production_min.
|
|
147
|
-
var reactIs_production_min_7 = reactIs_production_min.
|
|
148
|
-
var reactIs_production_min_8 = reactIs_production_min.
|
|
149
|
-
var reactIs_production_min_9 = reactIs_production_min.
|
|
150
|
-
var reactIs_production_min_10 = reactIs_production_min.
|
|
151
|
-
var reactIs_production_min_11 = reactIs_production_min.
|
|
152
|
-
var reactIs_production_min_12 = reactIs_production_min.
|
|
153
|
-
var reactIs_production_min_13 = reactIs_production_min.
|
|
154
|
-
var reactIs_production_min_14 = reactIs_production_min.
|
|
155
|
-
var reactIs_production_min_15 = reactIs_production_min.
|
|
156
|
-
var reactIs_production_min_16 = reactIs_production_min.
|
|
157
|
-
var reactIs_production_min_17 = reactIs_production_min.
|
|
158
|
-
var reactIs_production_min_18 = reactIs_production_min.
|
|
159
|
-
var reactIs_production_min_19 = reactIs_production_min.
|
|
160
|
-
var reactIs_production_min_20 = reactIs_production_min.
|
|
124
|
+
var reactIs_production_min_3 = reactIs_production_min.ConcurrentMode;
|
|
125
|
+
var reactIs_production_min_4 = reactIs_production_min.ContextConsumer;
|
|
126
|
+
var reactIs_production_min_5 = reactIs_production_min.ContextProvider;
|
|
127
|
+
var reactIs_production_min_6 = reactIs_production_min.Element;
|
|
128
|
+
var reactIs_production_min_7 = reactIs_production_min.ForwardRef;
|
|
129
|
+
var reactIs_production_min_8 = reactIs_production_min.Fragment;
|
|
130
|
+
var reactIs_production_min_9 = reactIs_production_min.Profiler;
|
|
131
|
+
var reactIs_production_min_10 = reactIs_production_min.Portal;
|
|
132
|
+
var reactIs_production_min_11 = reactIs_production_min.StrictMode;
|
|
133
|
+
var reactIs_production_min_12 = reactIs_production_min.isValidElementType;
|
|
134
|
+
var reactIs_production_min_13 = reactIs_production_min.isAsyncMode;
|
|
135
|
+
var reactIs_production_min_14 = reactIs_production_min.isConcurrentMode;
|
|
136
|
+
var reactIs_production_min_15 = reactIs_production_min.isContextConsumer;
|
|
137
|
+
var reactIs_production_min_16 = reactIs_production_min.isContextProvider;
|
|
138
|
+
var reactIs_production_min_17 = reactIs_production_min.isElement;
|
|
139
|
+
var reactIs_production_min_18 = reactIs_production_min.isForwardRef;
|
|
140
|
+
var reactIs_production_min_19 = reactIs_production_min.isFragment;
|
|
141
|
+
var reactIs_production_min_20 = reactIs_production_min.isProfiler;
|
|
142
|
+
var reactIs_production_min_21 = reactIs_production_min.isPortal;
|
|
143
|
+
var reactIs_production_min_22 = reactIs_production_min.isStrictMode;
|
|
161
144
|
|
|
162
145
|
var reactIs = createCommonjsModule(function (module) {
|
|
163
146
|
|
|
@@ -166,22 +149,19 @@ var reactIs = createCommonjsModule(function (module) {
|
|
|
166
149
|
}
|
|
167
150
|
});
|
|
168
151
|
|
|
169
|
-
var _ReactIs$ForwardRef;
|
|
170
|
-
|
|
171
|
-
function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
172
|
-
|
|
173
152
|
/**
|
|
174
153
|
* Copyright 2015, Yahoo! Inc.
|
|
175
154
|
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
|
|
176
155
|
*/
|
|
177
156
|
|
|
178
|
-
|
|
179
157
|
var REACT_STATICS = {
|
|
180
158
|
childContextTypes: true,
|
|
159
|
+
contextType: true,
|
|
181
160
|
contextTypes: true,
|
|
182
161
|
defaultProps: true,
|
|
183
162
|
displayName: true,
|
|
184
163
|
getDefaultProps: true,
|
|
164
|
+
getDerivedStateFromError: true,
|
|
185
165
|
getDerivedStateFromProps: true,
|
|
186
166
|
mixins: true,
|
|
187
167
|
propTypes: true,
|
|
@@ -198,7 +178,16 @@ var KNOWN_STATICS = {
|
|
|
198
178
|
arity: true
|
|
199
179
|
};
|
|
200
180
|
|
|
201
|
-
var
|
|
181
|
+
var FORWARD_REF_STATICS = {
|
|
182
|
+
'$$typeof': true,
|
|
183
|
+
render: true,
|
|
184
|
+
defaultProps: true,
|
|
185
|
+
displayName: true,
|
|
186
|
+
propTypes: true
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
var TYPE_STATICS = {};
|
|
190
|
+
TYPE_STATICS[reactIs.ForwardRef] = FORWARD_REF_STATICS;
|
|
202
191
|
|
|
203
192
|
var defineProperty = Object.defineProperty;
|
|
204
193
|
var getOwnPropertyNames = Object.getOwnPropertyNames;
|
|
@@ -582,8 +571,8 @@ var proxiedInjectorProps = {
|
|
|
582
571
|
configurable: true,
|
|
583
572
|
enumerable: true
|
|
584
573
|
}
|
|
585
|
-
/**
|
|
586
|
-
* Store Injection
|
|
574
|
+
/**
|
|
575
|
+
* Store Injection
|
|
587
576
|
*/
|
|
588
577
|
|
|
589
578
|
};
|
|
@@ -667,11 +656,11 @@ function grabStoresByName(storeNames) {
|
|
|
667
656
|
return nextProps;
|
|
668
657
|
};
|
|
669
658
|
}
|
|
670
|
-
/**
|
|
671
|
-
* higher order component that injects stores to a child.
|
|
672
|
-
* takes either a varargs list of strings, which are stores read from the context,
|
|
673
|
-
* or a function that manually maps the available stores from the context to props:
|
|
674
|
-
* storesToProps(mobxStores, props, context) => newProps
|
|
659
|
+
/**
|
|
660
|
+
* higher order component that injects stores to a child.
|
|
661
|
+
* takes either a varargs list of strings, which are stores read from the context,
|
|
662
|
+
* or a function that manually maps the available stores from the context to props:
|
|
663
|
+
* storesToProps(mobxStores, props, context) => newProps
|
|
675
664
|
*/
|
|
676
665
|
|
|
677
666
|
|
|
@@ -709,8 +698,8 @@ function inject()
|
|
|
709
698
|
|
|
710
699
|
var mobxAdminProperty = $mobx || "$mobx";
|
|
711
700
|
var mobxIsUnmounted = newSymbol("isUnmounted");
|
|
712
|
-
/**
|
|
713
|
-
* dev tool support
|
|
701
|
+
/**
|
|
702
|
+
* dev tool support
|
|
714
703
|
*/
|
|
715
704
|
|
|
716
705
|
var isDevtoolsEnabled = false;
|
|
@@ -723,11 +712,11 @@ var skipRenderKey = newSymbol("skipRender");
|
|
|
723
712
|
var isForcingUpdateKey = newSymbol("isForcingUpdate"); // Using react-is had some issues (and operates on elements, not on types), see #608 / #609
|
|
724
713
|
|
|
725
714
|
var ReactForwardRefSymbol = typeof forwardRef === "function" && forwardRef(function (_props, _ref) {})["$$typeof"];
|
|
726
|
-
/**
|
|
727
|
-
* Helper to set `prop` to `this` as non-enumerable (hidden prop)
|
|
728
|
-
* @param target
|
|
729
|
-
* @param prop
|
|
730
|
-
* @param value
|
|
715
|
+
/**
|
|
716
|
+
* Helper to set `prop` to `this` as non-enumerable (hidden prop)
|
|
717
|
+
* @param target
|
|
718
|
+
* @param prop
|
|
719
|
+
* @param value
|
|
731
720
|
*/
|
|
732
721
|
|
|
733
722
|
function setHiddenProp(target, prop, value) {
|
|
@@ -777,13 +766,13 @@ function trackComponents() {
|
|
|
777
766
|
function useStaticRendering(useStaticRendering) {
|
|
778
767
|
isUsingStaticRendering = useStaticRendering;
|
|
779
768
|
}
|
|
780
|
-
/**
|
|
781
|
-
* Errors reporter
|
|
769
|
+
/**
|
|
770
|
+
* Errors reporter
|
|
782
771
|
*/
|
|
783
772
|
|
|
784
773
|
var errorsReporter = new EventEmitter();
|
|
785
|
-
/**
|
|
786
|
-
* Utilities
|
|
774
|
+
/**
|
|
775
|
+
* Utilities
|
|
787
776
|
*/
|
|
788
777
|
|
|
789
778
|
function patch$1(target, funcName) {
|
|
@@ -858,15 +847,15 @@ function makeComponentReactive(render) {
|
|
|
858
847
|
|
|
859
848
|
var initialName = this.displayName || this.name || this.constructor && (this.constructor.displayName || this.constructor.name) || "<component>";
|
|
860
849
|
var rootNodeID = this._reactInternalInstance && this._reactInternalInstance._rootNodeID || this._reactInternalInstance && this._reactInternalInstance._debugID || this._reactInternalFiber && this._reactInternalFiber._debugID;
|
|
861
|
-
/**
|
|
862
|
-
* If props are shallowly modified, react will render anyway,
|
|
863
|
-
* so atom.reportChanged() should not result in yet another re-render
|
|
850
|
+
/**
|
|
851
|
+
* If props are shallowly modified, react will render anyway,
|
|
852
|
+
* so atom.reportChanged() should not result in yet another re-render
|
|
864
853
|
*/
|
|
865
854
|
|
|
866
855
|
setHiddenProp(this, skipRenderKey, false);
|
|
867
|
-
/**
|
|
868
|
-
* forceUpdate will re-assign this.props. We don't want that to cause a loop,
|
|
869
|
-
* so detect these changes
|
|
856
|
+
/**
|
|
857
|
+
* forceUpdate will re-assign this.props. We don't want that to cause a loop,
|
|
858
|
+
* so detect these changes
|
|
870
859
|
*/
|
|
871
860
|
|
|
872
861
|
setHiddenProp(this, isForcingUpdateKey, false); // wire up reactive render
|
|
@@ -903,8 +892,8 @@ function makeComponentReactive(render) {
|
|
|
903
892
|
this.render = reactiveRender;
|
|
904
893
|
return reactiveRender.call(this);
|
|
905
894
|
}
|
|
906
|
-
/**
|
|
907
|
-
* ReactiveMixin
|
|
895
|
+
/**
|
|
896
|
+
* ReactiveMixin
|
|
908
897
|
*/
|
|
909
898
|
|
|
910
899
|
|
|
@@ -987,8 +976,8 @@ function makeObservableProp(target, propName) {
|
|
|
987
976
|
}
|
|
988
977
|
});
|
|
989
978
|
}
|
|
990
|
-
/**
|
|
991
|
-
* Observer function / decorator
|
|
979
|
+
/**
|
|
980
|
+
* Observer function / decorator
|
|
992
981
|
*/
|
|
993
982
|
|
|
994
983
|
|
|
@@ -1030,14 +1019,13 @@ function observer(arg1, arg2) {
|
|
|
1030
1019
|
|
|
1031
1020
|
if (ReactForwardRefSymbol && componentClass["$$typeof"] === ReactForwardRefSymbol) {
|
|
1032
1021
|
var _baseRender = componentClass.render;
|
|
1033
|
-
if (typeof _baseRender !== "function") throw new Error("render property of ForwardRef was not a function");
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
}
|
|
1022
|
+
if (typeof _baseRender !== "function") throw new Error("render property of ForwardRef was not a function"); // TODO: do we need to hoist statics from baseRender to the forward ref?
|
|
1023
|
+
|
|
1024
|
+
return forwardRef(function ObserverForwardRef() {
|
|
1025
|
+
var _arguments = arguments;
|
|
1026
|
+
return React__default.createElement(Observer, null, function () {
|
|
1027
|
+
return _baseRender.apply(undefined, _arguments);
|
|
1028
|
+
});
|
|
1041
1029
|
});
|
|
1042
1030
|
} // Stateless function component:
|
|
1043
1031
|
// If it is function but doesn't seem to be a react class constructor,
|
package/native.d.ts
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Turns a React component or stateless render function into a reactive component.
|
|
3
|
-
*/
|
|
4
|
-
import * as React from "react"
|
|
5
|
-
|
|
6
|
-
export type IReactComponent<P = any> =
|
|
7
|
-
| React.StatelessComponent<P>
|
|
8
|
-
| React.ComponentClass<P>
|
|
9
|
-
| React.ClassicComponentClass<P>
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Observer
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
// Deprecated: observer with with stores (as decorator)
|
|
16
|
-
export function observer(stores: string[]): <T extends IReactComponent>(clazz: T) => void
|
|
17
|
-
// Deprecated: observer with with stores
|
|
18
|
-
export function observer<T extends IReactComponent>(stores: string[], clazz: T): T
|
|
19
|
-
export function observer<T extends IReactComponent>(target: T): T
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Inject
|
|
23
|
-
*/
|
|
24
|
-
export type IValueMap = { [key: string]: any }
|
|
25
|
-
export type IStoresToProps<
|
|
26
|
-
S extends IValueMap = {},
|
|
27
|
-
P extends IValueMap = {},
|
|
28
|
-
I extends IValueMap = {},
|
|
29
|
-
C extends IValueMap = {}
|
|
30
|
-
> = (stores: S, nextProps: P, context: C) => I
|
|
31
|
-
|
|
32
|
-
export type IWrappedComponent<P> = {
|
|
33
|
-
wrappedComponent: IReactComponent<P>
|
|
34
|
-
wrappedInstance: React.ReactInstance | undefined
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Ideally we would want to return React.ComponentClass<Partial<P>>,
|
|
38
|
-
// but TS doesn't allow such things in decorators, like we do in the non-decorator version
|
|
39
|
-
// See also #256
|
|
40
|
-
export function inject(
|
|
41
|
-
...stores: string[]
|
|
42
|
-
): <T extends IReactComponent<any>>(
|
|
43
|
-
target: T
|
|
44
|
-
) => T & (T extends IReactComponent<infer P> ? IWrappedComponent<P> : never)
|
|
45
|
-
export function inject<S, P, I, C>(
|
|
46
|
-
fn: IStoresToProps<S, P, I, C>
|
|
47
|
-
): <T extends IReactComponent>(target: T) => T & IWrappedComponent<P>
|
|
48
|
-
|
|
49
|
-
// Ideal implementation:
|
|
50
|
-
// export function inject
|
|
51
|
-
// (
|
|
52
|
-
// fn: IStoresToProps
|
|
53
|
-
// ):
|
|
54
|
-
// <P>(target: IReactComponent<P>) => IReactComponent<Partial<P>> & IWrappedComponent<IReactComponent<Partial<P>>>
|
|
55
|
-
//
|
|
56
|
-
// Or even better: (but that would require type inference to work other way around)
|
|
57
|
-
// export function inject<P, I>
|
|
58
|
-
// (
|
|
59
|
-
// fn: IStoresToProps<any, P, I>
|
|
60
|
-
// ):
|
|
61
|
-
// <T extends IReactComponent<P & S>(target: T) => IReactComponent<P> & IWrappedComponent<T>
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* disposeOnUnmount
|
|
65
|
-
*/
|
|
66
|
-
type Disposer = () => void
|
|
67
|
-
export function disposeOnUnmount(target: React.Component<any, any>, propertyKey: string): void
|
|
68
|
-
export function disposeOnUnmount<TF extends Disposer | Disposer[]>(
|
|
69
|
-
target: React.Component<any, any>,
|
|
70
|
-
fn: TF
|
|
71
|
-
): TF
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Utilities
|
|
75
|
-
*/
|
|
76
|
-
export function onError(cb: (error: Error) => void): () => void
|
|
77
|
-
|
|
78
|
-
export class Provider extends React.Component<any, {}> {}
|
|
79
|
-
|
|
80
|
-
export class Observer extends React.Component<
|
|
81
|
-
{
|
|
82
|
-
children?: () => React.ReactNode
|
|
83
|
-
render?: () => React.ReactNode
|
|
84
|
-
},
|
|
85
|
-
{}
|
|
86
|
-
> {}
|
|
87
|
-
|
|
88
|
-
export function useStaticRendering(value: boolean): void
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Enable dev tool support, makes sure that renderReport emits events.
|
|
92
|
-
*/
|
|
93
|
-
export function trackComponents(): void
|
|
94
|
-
|
|
95
|
-
export const renderReporter: RenderReporter
|
|
96
|
-
|
|
97
|
-
export interface RenderReporter {
|
|
98
|
-
on(handler: (data: IRenderEvent) => void): void
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface IRenderEvent {
|
|
102
|
-
event: "render" | "destroy"
|
|
103
|
-
renderTime?: number
|
|
104
|
-
totalTime?: number
|
|
105
|
-
component: React.ReactElement<any> // Component instance
|
|
106
|
-
node: any // DOMNode
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* WeakMap DOMNode -> Component instance
|
|
111
|
-
* @deprecated
|
|
112
|
-
*/
|
|
113
|
-
export const componentByNodeRegistery: any
|
|
114
|
-
/**
|
|
115
|
-
* WeakMap DOMNode -> Component instance
|
|
116
|
-
*/
|
|
117
|
-
export const componentByNodeRegistry: any
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @deprecated, use PropTypes instead
|
|
121
|
-
*/
|
|
122
|
-
export const propTypes: {
|
|
123
|
-
observableArray: React.Requireable<any>
|
|
124
|
-
observableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
125
|
-
observableMap: React.Requireable<any>
|
|
126
|
-
observableObject: React.Requireable<any>
|
|
127
|
-
arrayOrObservableArray: React.Requireable<any>
|
|
128
|
-
arrayOrObservableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
129
|
-
objectOrObservableObject: React.Requireable<any>
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export const PropTypes: {
|
|
133
|
-
observableArray: React.Requireable<any>
|
|
134
|
-
observableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
135
|
-
observableMap: React.Requireable<any>
|
|
136
|
-
observableObject: React.Requireable<any>
|
|
137
|
-
arrayOrObservableArray: React.Requireable<any>
|
|
138
|
-
arrayOrObservableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
139
|
-
objectOrObservableObject: React.Requireable<any>
|
|
140
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Turns a React component or stateless render function into a reactive component.
|
|
3
|
+
*/
|
|
4
|
+
import * as React from "react"
|
|
5
|
+
|
|
6
|
+
export type IReactComponent<P = any> =
|
|
7
|
+
| React.StatelessComponent<P>
|
|
8
|
+
| React.ComponentClass<P>
|
|
9
|
+
| React.ClassicComponentClass<P>
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Observer
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// Deprecated: observer with with stores (as decorator)
|
|
16
|
+
export function observer(stores: string[]): <T extends IReactComponent>(clazz: T) => void
|
|
17
|
+
// Deprecated: observer with with stores
|
|
18
|
+
export function observer<T extends IReactComponent>(stores: string[], clazz: T): T
|
|
19
|
+
export function observer<T extends IReactComponent>(target: T): T
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Inject
|
|
23
|
+
*/
|
|
24
|
+
export type IValueMap = { [key: string]: any }
|
|
25
|
+
export type IStoresToProps<
|
|
26
|
+
S extends IValueMap = {},
|
|
27
|
+
P extends IValueMap = {},
|
|
28
|
+
I extends IValueMap = {},
|
|
29
|
+
C extends IValueMap = {}
|
|
30
|
+
> = (stores: S, nextProps: P, context: C) => I
|
|
31
|
+
|
|
32
|
+
export type IWrappedComponent<P> = {
|
|
33
|
+
wrappedComponent: IReactComponent<P>
|
|
34
|
+
wrappedInstance: React.ReactInstance | undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Ideally we would want to return React.ComponentClass<Partial<P>>,
|
|
38
|
+
// but TS doesn't allow such things in decorators, like we do in the non-decorator version
|
|
39
|
+
// See also #256
|
|
40
|
+
export function inject(
|
|
41
|
+
...stores: string[]
|
|
42
|
+
): <T extends IReactComponent<any>>(
|
|
43
|
+
target: T
|
|
44
|
+
) => T & (T extends IReactComponent<infer P> ? IWrappedComponent<P> : never)
|
|
45
|
+
export function inject<S, P, I, C>(
|
|
46
|
+
fn: IStoresToProps<S, P, I, C>
|
|
47
|
+
): <T extends IReactComponent>(target: T) => T & IWrappedComponent<P>
|
|
48
|
+
|
|
49
|
+
// Ideal implementation:
|
|
50
|
+
// export function inject
|
|
51
|
+
// (
|
|
52
|
+
// fn: IStoresToProps
|
|
53
|
+
// ):
|
|
54
|
+
// <P>(target: IReactComponent<P>) => IReactComponent<Partial<P>> & IWrappedComponent<IReactComponent<Partial<P>>>
|
|
55
|
+
//
|
|
56
|
+
// Or even better: (but that would require type inference to work other way around)
|
|
57
|
+
// export function inject<P, I>
|
|
58
|
+
// (
|
|
59
|
+
// fn: IStoresToProps<any, P, I>
|
|
60
|
+
// ):
|
|
61
|
+
// <T extends IReactComponent<P & S>(target: T) => IReactComponent<P> & IWrappedComponent<T>
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* disposeOnUnmount
|
|
65
|
+
*/
|
|
66
|
+
type Disposer = () => void
|
|
67
|
+
export function disposeOnUnmount(target: React.Component<any, any>, propertyKey: string): void
|
|
68
|
+
export function disposeOnUnmount<TF extends Disposer | Disposer[]>(
|
|
69
|
+
target: React.Component<any, any>,
|
|
70
|
+
fn: TF
|
|
71
|
+
): TF
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Utilities
|
|
75
|
+
*/
|
|
76
|
+
export function onError(cb: (error: Error) => void): () => void
|
|
77
|
+
|
|
78
|
+
export class Provider extends React.Component<any, {}> {}
|
|
79
|
+
|
|
80
|
+
export class Observer extends React.Component<
|
|
81
|
+
{
|
|
82
|
+
children?: () => React.ReactNode
|
|
83
|
+
render?: () => React.ReactNode
|
|
84
|
+
},
|
|
85
|
+
{}
|
|
86
|
+
> {}
|
|
87
|
+
|
|
88
|
+
export function useStaticRendering(value: boolean): void
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Enable dev tool support, makes sure that renderReport emits events.
|
|
92
|
+
*/
|
|
93
|
+
export function trackComponents(): void
|
|
94
|
+
|
|
95
|
+
export const renderReporter: RenderReporter
|
|
96
|
+
|
|
97
|
+
export interface RenderReporter {
|
|
98
|
+
on(handler: (data: IRenderEvent) => void): void
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface IRenderEvent {
|
|
102
|
+
event: "render" | "destroy"
|
|
103
|
+
renderTime?: number
|
|
104
|
+
totalTime?: number
|
|
105
|
+
component: React.ReactElement<any> // Component instance
|
|
106
|
+
node: any // DOMNode
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* WeakMap DOMNode -> Component instance
|
|
111
|
+
* @deprecated
|
|
112
|
+
*/
|
|
113
|
+
export const componentByNodeRegistery: any
|
|
114
|
+
/**
|
|
115
|
+
* WeakMap DOMNode -> Component instance
|
|
116
|
+
*/
|
|
117
|
+
export const componentByNodeRegistry: any
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @deprecated, use PropTypes instead
|
|
121
|
+
*/
|
|
122
|
+
export const propTypes: {
|
|
123
|
+
observableArray: React.Requireable<any>
|
|
124
|
+
observableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
125
|
+
observableMap: React.Requireable<any>
|
|
126
|
+
observableObject: React.Requireable<any>
|
|
127
|
+
arrayOrObservableArray: React.Requireable<any>
|
|
128
|
+
arrayOrObservableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
129
|
+
objectOrObservableObject: React.Requireable<any>
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const PropTypes: {
|
|
133
|
+
observableArray: React.Requireable<any>
|
|
134
|
+
observableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
135
|
+
observableMap: React.Requireable<any>
|
|
136
|
+
observableObject: React.Requireable<any>
|
|
137
|
+
arrayOrObservableArray: React.Requireable<any>
|
|
138
|
+
arrayOrObservableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
139
|
+
objectOrObservableObject: React.Requireable<any>
|
|
140
|
+
}
|