mobx-react 5.4.3 → 5.4.4
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 -518
- package/LICENSE +21 -21
- package/README.md +518 -517
- package/custom.d.ts +140 -140
- package/custom.js +47 -29
- package/custom.module.js +47 -29
- package/dist/mobx-react.d.ts +105 -0
- package/dist/mobx-react.js +2 -0
- package/dist/mobx-react.js.map +1 -0
- package/dist/mobx-react.module.js +2 -0
- package/dist/mobx-react.module.js.map +1 -0
- package/dist/mobx-react.rn.module.js +2 -0
- package/dist/mobx-react.umd.js +2 -0
- package/dist/mobx-react.umd.js.map +1 -0
- package/empty.js +3 -3
- package/index.d.ts +140 -140
- package/index.js +47 -29
- package/index.min.js +9 -1
- package/index.module.js +47 -29
- package/native.d.ts +140 -140
- package/native.js +47 -29
- package/package.json +1 -1
- package/yarn.lock +5886 -5886
package/custom.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
|
+
}
|
package/custom.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/** @license mobx-react v5.4.4
|
|
2
|
+
* custom.js
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 Michel Weststrate.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
1
9
|
(function (global, factory) {
|
|
2
10
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('mobx'), require('react')) :
|
|
3
11
|
typeof define === 'function' && define.amd ? define(['exports', 'mobx', 'react'], factory) :
|
|
@@ -446,7 +454,8 @@
|
|
|
446
454
|
return !(component.prototype && component.prototype.render);
|
|
447
455
|
}
|
|
448
456
|
var symbolId = 0;
|
|
449
|
-
|
|
457
|
+
|
|
458
|
+
function createSymbol(name) {
|
|
450
459
|
if (typeof Symbol === "function") {
|
|
451
460
|
return Symbol(name);
|
|
452
461
|
}
|
|
@@ -455,6 +464,15 @@
|
|
|
455
464
|
symbolId++;
|
|
456
465
|
return symbol;
|
|
457
466
|
}
|
|
467
|
+
|
|
468
|
+
var createdSymbols = {};
|
|
469
|
+
function newSymbol(name) {
|
|
470
|
+
if (!createdSymbols[name]) {
|
|
471
|
+
createdSymbols[name] = createSymbol(name);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
return createdSymbols[name];
|
|
475
|
+
}
|
|
458
476
|
var mobxMixins = newSymbol("patchMixins");
|
|
459
477
|
var mobxPatchedDefinition = newSymbol("patchedDefinition");
|
|
460
478
|
|
|
@@ -575,8 +593,8 @@
|
|
|
575
593
|
configurable: true,
|
|
576
594
|
enumerable: true
|
|
577
595
|
}
|
|
578
|
-
/**
|
|
579
|
-
* Store Injection
|
|
596
|
+
/**
|
|
597
|
+
* Store Injection
|
|
580
598
|
*/
|
|
581
599
|
|
|
582
600
|
};
|
|
@@ -660,11 +678,11 @@
|
|
|
660
678
|
return nextProps;
|
|
661
679
|
};
|
|
662
680
|
}
|
|
663
|
-
/**
|
|
664
|
-
* higher order component that injects stores to a child.
|
|
665
|
-
* takes either a varargs list of strings, which are stores read from the context,
|
|
666
|
-
* or a function that manually maps the available stores from the context to props:
|
|
667
|
-
* storesToProps(mobxStores, props, context) => newProps
|
|
681
|
+
/**
|
|
682
|
+
* higher order component that injects stores to a child.
|
|
683
|
+
* takes either a varargs list of strings, which are stores read from the context,
|
|
684
|
+
* or a function that manually maps the available stores from the context to props:
|
|
685
|
+
* storesToProps(mobxStores, props, context) => newProps
|
|
668
686
|
*/
|
|
669
687
|
|
|
670
688
|
|
|
@@ -702,8 +720,8 @@
|
|
|
702
720
|
|
|
703
721
|
var mobxAdminProperty = mobx.$mobx || "$mobx";
|
|
704
722
|
var mobxIsUnmounted = newSymbol("isUnmounted");
|
|
705
|
-
/**
|
|
706
|
-
* dev tool support
|
|
723
|
+
/**
|
|
724
|
+
* dev tool support
|
|
707
725
|
*/
|
|
708
726
|
|
|
709
727
|
var isDevtoolsEnabled = false;
|
|
@@ -716,11 +734,11 @@
|
|
|
716
734
|
var isForcingUpdateKey = newSymbol("isForcingUpdate"); // Using react-is had some issues (and operates on elements, not on types), see #608 / #609
|
|
717
735
|
|
|
718
736
|
var ReactForwardRefSymbol = typeof React.forwardRef === "function" && React.forwardRef(function (_props, _ref) {})["$$typeof"];
|
|
719
|
-
/**
|
|
720
|
-
* Helper to set `prop` to `this` as non-enumerable (hidden prop)
|
|
721
|
-
* @param target
|
|
722
|
-
* @param prop
|
|
723
|
-
* @param value
|
|
737
|
+
/**
|
|
738
|
+
* Helper to set `prop` to `this` as non-enumerable (hidden prop)
|
|
739
|
+
* @param target
|
|
740
|
+
* @param prop
|
|
741
|
+
* @param value
|
|
724
742
|
*/
|
|
725
743
|
|
|
726
744
|
function setHiddenProp(target, prop, value) {
|
|
@@ -760,13 +778,13 @@
|
|
|
760
778
|
function useStaticRendering(useStaticRendering) {
|
|
761
779
|
isUsingStaticRendering = useStaticRendering;
|
|
762
780
|
}
|
|
763
|
-
/**
|
|
764
|
-
* Errors reporter
|
|
781
|
+
/**
|
|
782
|
+
* Errors reporter
|
|
765
783
|
*/
|
|
766
784
|
|
|
767
785
|
var errorsReporter = new EventEmitter();
|
|
768
|
-
/**
|
|
769
|
-
* Utilities
|
|
786
|
+
/**
|
|
787
|
+
* Utilities
|
|
770
788
|
*/
|
|
771
789
|
|
|
772
790
|
function patch$1(target, funcName) {
|
|
@@ -841,15 +859,15 @@
|
|
|
841
859
|
|
|
842
860
|
var initialName = this.displayName || this.name || this.constructor && (this.constructor.displayName || this.constructor.name) || "<component>";
|
|
843
861
|
var rootNodeID = this._reactInternalInstance && this._reactInternalInstance._rootNodeID || this._reactInternalInstance && this._reactInternalInstance._debugID || this._reactInternalFiber && this._reactInternalFiber._debugID;
|
|
844
|
-
/**
|
|
845
|
-
* If props are shallowly modified, react will render anyway,
|
|
846
|
-
* so atom.reportChanged() should not result in yet another re-render
|
|
862
|
+
/**
|
|
863
|
+
* If props are shallowly modified, react will render anyway,
|
|
864
|
+
* so atom.reportChanged() should not result in yet another re-render
|
|
847
865
|
*/
|
|
848
866
|
|
|
849
867
|
setHiddenProp(this, skipRenderKey, false);
|
|
850
|
-
/**
|
|
851
|
-
* forceUpdate will re-assign this.props. We don't want that to cause a loop,
|
|
852
|
-
* so detect these changes
|
|
868
|
+
/**
|
|
869
|
+
* forceUpdate will re-assign this.props. We don't want that to cause a loop,
|
|
870
|
+
* so detect these changes
|
|
853
871
|
*/
|
|
854
872
|
|
|
855
873
|
setHiddenProp(this, isForcingUpdateKey, false); // wire up reactive render
|
|
@@ -886,8 +904,8 @@
|
|
|
886
904
|
this.render = reactiveRender;
|
|
887
905
|
return reactiveRender.call(this);
|
|
888
906
|
}
|
|
889
|
-
/**
|
|
890
|
-
* ReactiveMixin
|
|
907
|
+
/**
|
|
908
|
+
* ReactiveMixin
|
|
891
909
|
*/
|
|
892
910
|
|
|
893
911
|
|
|
@@ -970,8 +988,8 @@
|
|
|
970
988
|
}
|
|
971
989
|
});
|
|
972
990
|
}
|
|
973
|
-
/**
|
|
974
|
-
* Observer function / decorator
|
|
991
|
+
/**
|
|
992
|
+
* Observer function / decorator
|
|
975
993
|
*/
|
|
976
994
|
|
|
977
995
|
|
package/custom.module.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/** @license mobx-react v5.4.4
|
|
2
|
+
* custom.module.js
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 Michel Weststrate.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
1
9
|
import { isObservableArray, isObservableObject, isObservableMap, untracked, createAtom, Reaction, _allowStateChanges, $mobx, spy, getDebugName } from 'mobx';
|
|
2
10
|
import React__default, { Component, createElement, PureComponent, forwardRef, Children } from 'react';
|
|
3
11
|
|
|
@@ -441,7 +449,8 @@ function isStateless(component) {
|
|
|
441
449
|
return !(component.prototype && component.prototype.render);
|
|
442
450
|
}
|
|
443
451
|
var symbolId = 0;
|
|
444
|
-
|
|
452
|
+
|
|
453
|
+
function createSymbol(name) {
|
|
445
454
|
if (typeof Symbol === "function") {
|
|
446
455
|
return Symbol(name);
|
|
447
456
|
}
|
|
@@ -450,6 +459,15 @@ function newSymbol(name) {
|
|
|
450
459
|
symbolId++;
|
|
451
460
|
return symbol;
|
|
452
461
|
}
|
|
462
|
+
|
|
463
|
+
var createdSymbols = {};
|
|
464
|
+
function newSymbol(name) {
|
|
465
|
+
if (!createdSymbols[name]) {
|
|
466
|
+
createdSymbols[name] = createSymbol(name);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return createdSymbols[name];
|
|
470
|
+
}
|
|
453
471
|
var mobxMixins = newSymbol("patchMixins");
|
|
454
472
|
var mobxPatchedDefinition = newSymbol("patchedDefinition");
|
|
455
473
|
|
|
@@ -570,8 +588,8 @@ var proxiedInjectorProps = {
|
|
|
570
588
|
configurable: true,
|
|
571
589
|
enumerable: true
|
|
572
590
|
}
|
|
573
|
-
/**
|
|
574
|
-
* Store Injection
|
|
591
|
+
/**
|
|
592
|
+
* Store Injection
|
|
575
593
|
*/
|
|
576
594
|
|
|
577
595
|
};
|
|
@@ -655,11 +673,11 @@ function grabStoresByName(storeNames) {
|
|
|
655
673
|
return nextProps;
|
|
656
674
|
};
|
|
657
675
|
}
|
|
658
|
-
/**
|
|
659
|
-
* higher order component that injects stores to a child.
|
|
660
|
-
* takes either a varargs list of strings, which are stores read from the context,
|
|
661
|
-
* or a function that manually maps the available stores from the context to props:
|
|
662
|
-
* storesToProps(mobxStores, props, context) => newProps
|
|
676
|
+
/**
|
|
677
|
+
* higher order component that injects stores to a child.
|
|
678
|
+
* takes either a varargs list of strings, which are stores read from the context,
|
|
679
|
+
* or a function that manually maps the available stores from the context to props:
|
|
680
|
+
* storesToProps(mobxStores, props, context) => newProps
|
|
663
681
|
*/
|
|
664
682
|
|
|
665
683
|
|
|
@@ -697,8 +715,8 @@ function inject()
|
|
|
697
715
|
|
|
698
716
|
var mobxAdminProperty = $mobx || "$mobx";
|
|
699
717
|
var mobxIsUnmounted = newSymbol("isUnmounted");
|
|
700
|
-
/**
|
|
701
|
-
* dev tool support
|
|
718
|
+
/**
|
|
719
|
+
* dev tool support
|
|
702
720
|
*/
|
|
703
721
|
|
|
704
722
|
var isDevtoolsEnabled = false;
|
|
@@ -711,11 +729,11 @@ var skipRenderKey = newSymbol("skipRender");
|
|
|
711
729
|
var isForcingUpdateKey = newSymbol("isForcingUpdate"); // Using react-is had some issues (and operates on elements, not on types), see #608 / #609
|
|
712
730
|
|
|
713
731
|
var ReactForwardRefSymbol = typeof forwardRef === "function" && forwardRef(function (_props, _ref) {})["$$typeof"];
|
|
714
|
-
/**
|
|
715
|
-
* Helper to set `prop` to `this` as non-enumerable (hidden prop)
|
|
716
|
-
* @param target
|
|
717
|
-
* @param prop
|
|
718
|
-
* @param value
|
|
732
|
+
/**
|
|
733
|
+
* Helper to set `prop` to `this` as non-enumerable (hidden prop)
|
|
734
|
+
* @param target
|
|
735
|
+
* @param prop
|
|
736
|
+
* @param value
|
|
719
737
|
*/
|
|
720
738
|
|
|
721
739
|
function setHiddenProp(target, prop, value) {
|
|
@@ -755,13 +773,13 @@ function trackComponents() {
|
|
|
755
773
|
function useStaticRendering(useStaticRendering) {
|
|
756
774
|
isUsingStaticRendering = useStaticRendering;
|
|
757
775
|
}
|
|
758
|
-
/**
|
|
759
|
-
* Errors reporter
|
|
776
|
+
/**
|
|
777
|
+
* Errors reporter
|
|
760
778
|
*/
|
|
761
779
|
|
|
762
780
|
var errorsReporter = new EventEmitter();
|
|
763
|
-
/**
|
|
764
|
-
* Utilities
|
|
781
|
+
/**
|
|
782
|
+
* Utilities
|
|
765
783
|
*/
|
|
766
784
|
|
|
767
785
|
function patch$1(target, funcName) {
|
|
@@ -836,15 +854,15 @@ function makeComponentReactive(render) {
|
|
|
836
854
|
|
|
837
855
|
var initialName = this.displayName || this.name || this.constructor && (this.constructor.displayName || this.constructor.name) || "<component>";
|
|
838
856
|
var rootNodeID = this._reactInternalInstance && this._reactInternalInstance._rootNodeID || this._reactInternalInstance && this._reactInternalInstance._debugID || this._reactInternalFiber && this._reactInternalFiber._debugID;
|
|
839
|
-
/**
|
|
840
|
-
* If props are shallowly modified, react will render anyway,
|
|
841
|
-
* so atom.reportChanged() should not result in yet another re-render
|
|
857
|
+
/**
|
|
858
|
+
* If props are shallowly modified, react will render anyway,
|
|
859
|
+
* so atom.reportChanged() should not result in yet another re-render
|
|
842
860
|
*/
|
|
843
861
|
|
|
844
862
|
setHiddenProp(this, skipRenderKey, false);
|
|
845
|
-
/**
|
|
846
|
-
* forceUpdate will re-assign this.props. We don't want that to cause a loop,
|
|
847
|
-
* so detect these changes
|
|
863
|
+
/**
|
|
864
|
+
* forceUpdate will re-assign this.props. We don't want that to cause a loop,
|
|
865
|
+
* so detect these changes
|
|
848
866
|
*/
|
|
849
867
|
|
|
850
868
|
setHiddenProp(this, isForcingUpdateKey, false); // wire up reactive render
|
|
@@ -881,8 +899,8 @@ function makeComponentReactive(render) {
|
|
|
881
899
|
this.render = reactiveRender;
|
|
882
900
|
return reactiveRender.call(this);
|
|
883
901
|
}
|
|
884
|
-
/**
|
|
885
|
-
* ReactiveMixin
|
|
902
|
+
/**
|
|
903
|
+
* ReactiveMixin
|
|
886
904
|
*/
|
|
887
905
|
|
|
888
906
|
|
|
@@ -965,8 +983,8 @@ function makeObservableProp(target, propName) {
|
|
|
965
983
|
}
|
|
966
984
|
});
|
|
967
985
|
}
|
|
968
|
-
/**
|
|
969
|
-
* Observer function / decorator
|
|
986
|
+
/**
|
|
987
|
+
* Observer function / decorator
|
|
970
988
|
*/
|
|
971
989
|
|
|
972
990
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a React component or stateless render function into a reactive component.
|
|
3
|
+
*/
|
|
4
|
+
import * as React from "react"
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
useObservable,
|
|
8
|
+
useComputed,
|
|
9
|
+
useDisposable,
|
|
10
|
+
IObserverOptions,
|
|
11
|
+
useObserver,
|
|
12
|
+
Observer
|
|
13
|
+
} from "mobx-react-lite"
|
|
14
|
+
|
|
15
|
+
export type IReactComponent<P = any> =
|
|
16
|
+
| React.StatelessComponent<P>
|
|
17
|
+
| React.ComponentClass<P>
|
|
18
|
+
| React.ClassicComponentClass<P>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Observer
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function observer<T extends IReactComponent>(target: T): T
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Inject
|
|
28
|
+
*/
|
|
29
|
+
export type IValueMap = { [key: string]: any }
|
|
30
|
+
export type IStoresToProps<
|
|
31
|
+
S extends IValueMap = {},
|
|
32
|
+
P extends IValueMap = {},
|
|
33
|
+
I extends IValueMap = {},
|
|
34
|
+
C extends IValueMap = {}
|
|
35
|
+
> = (stores: S, nextProps: P, context: C) => I
|
|
36
|
+
|
|
37
|
+
export type IWrappedComponent<P> = {
|
|
38
|
+
wrappedComponent: IReactComponent<P>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Ideally we would want to return React.ComponentClass<Partial<P>>,
|
|
42
|
+
// but TS doesn't allow such things in decorators, like we do in the non-decorator version
|
|
43
|
+
// See also #256
|
|
44
|
+
export function inject(
|
|
45
|
+
...stores: string[]
|
|
46
|
+
): <T extends IReactComponent<any>>(
|
|
47
|
+
target: T
|
|
48
|
+
) => T & (T extends IReactComponent<infer P> ? IWrappedComponent<P> : never)
|
|
49
|
+
export function inject<S, P, I, C>(
|
|
50
|
+
fn: IStoresToProps<S, P, I, C>
|
|
51
|
+
): <T extends IReactComponent>(target: T) => T & IWrappedComponent<P>
|
|
52
|
+
|
|
53
|
+
// Ideal implementation:
|
|
54
|
+
// export function inject
|
|
55
|
+
// (
|
|
56
|
+
// fn: IStoresToProps
|
|
57
|
+
// ):
|
|
58
|
+
// <P>(target: IReactComponent<P>) => IReactComponent<Partial<P>> & IWrappedComponent<IReactComponent<Partial<P>>>
|
|
59
|
+
//
|
|
60
|
+
// Or even better: (but that would require type inference to work other way around)
|
|
61
|
+
// export function inject<P, I>
|
|
62
|
+
// (
|
|
63
|
+
// fn: IStoresToProps<any, P, I>
|
|
64
|
+
// ):
|
|
65
|
+
// <T extends IReactComponent<P & S>(target: T) => IReactComponent<P> & IWrappedComponent<T>
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* disposeOnUnmount
|
|
69
|
+
*/
|
|
70
|
+
type Disposer = () => void
|
|
71
|
+
export function disposeOnUnmount(target: React.Component<any, any>, propertyKey: string): void
|
|
72
|
+
export function disposeOnUnmount<TF extends Disposer | Disposer[]>(
|
|
73
|
+
target: React.Component<any, any>,
|
|
74
|
+
fn: TF
|
|
75
|
+
): TF
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Utilities
|
|
79
|
+
*/
|
|
80
|
+
export class Provider extends React.Component<any, {}> {}
|
|
81
|
+
|
|
82
|
+
export function useStaticRendering(value: boolean): void
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated, use PropTypes instead
|
|
86
|
+
*/
|
|
87
|
+
export const propTypes: {
|
|
88
|
+
observableArray: React.Requireable<any>
|
|
89
|
+
observableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
90
|
+
observableMap: React.Requireable<any>
|
|
91
|
+
observableObject: React.Requireable<any>
|
|
92
|
+
arrayOrObservableArray: React.Requireable<any>
|
|
93
|
+
arrayOrObservableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
94
|
+
objectOrObservableObject: React.Requireable<any>
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const PropTypes: {
|
|
98
|
+
observableArray: React.Requireable<any>
|
|
99
|
+
observableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
100
|
+
observableMap: React.Requireable<any>
|
|
101
|
+
observableObject: React.Requireable<any>
|
|
102
|
+
arrayOrObservableArray: React.Requireable<any>
|
|
103
|
+
arrayOrObservableArrayOf: (type: React.Validator<any>) => React.Requireable<any>
|
|
104
|
+
objectOrObservableObject: React.Requireable<any>
|
|
105
|
+
}
|