1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | var _prodInvariant = require('./reactProdInvariant'),
|
12 | _assign = require('object-assign');
|
13 |
|
14 | var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue');
|
15 |
|
16 | var canDefineProperty = require('./canDefineProperty');
|
17 | var emptyObject = require('fbjs/lib/emptyObject');
|
18 | var invariant = require('fbjs/lib/invariant');
|
19 | var lowPriorityWarning = require('./lowPriorityWarning');
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function ReactComponent(props, context, updater) {
|
25 | this.props = props;
|
26 | this.context = context;
|
27 | this.refs = emptyObject;
|
28 |
|
29 |
|
30 | this.updater = updater || ReactNoopUpdateQueue;
|
31 | }
|
32 |
|
33 | ReactComponent.prototype.isReactComponent = {};
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | ReactComponent.prototype.setState = function (partialState, callback) {
|
61 | !(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'setState(...): takes an object of state variables to update or a function which returns an object of state variables.') : _prodInvariant('85') : void 0;
|
62 | this.updater.enqueueSetState(this, partialState);
|
63 | if (callback) {
|
64 | this.updater.enqueueCallback(this, callback, 'setState');
|
65 | }
|
66 | };
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | ReactComponent.prototype.forceUpdate = function (callback) {
|
83 | this.updater.enqueueForceUpdate(this);
|
84 | if (callback) {
|
85 | this.updater.enqueueCallback(this, callback, 'forceUpdate');
|
86 | }
|
87 | };
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | if (process.env.NODE_ENV !== 'production') {
|
95 | var deprecatedAPIs = {
|
96 | isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
|
97 | replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).']
|
98 | };
|
99 | var defineDeprecationWarning = function (methodName, info) {
|
100 | if (canDefineProperty) {
|
101 | Object.defineProperty(ReactComponent.prototype, methodName, {
|
102 | get: function () {
|
103 | lowPriorityWarning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]);
|
104 | return undefined;
|
105 | }
|
106 | });
|
107 | }
|
108 | };
|
109 | for (var fnName in deprecatedAPIs) {
|
110 | if (deprecatedAPIs.hasOwnProperty(fnName)) {
|
111 | defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
|
112 | }
|
113 | }
|
114 | }
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | function ReactPureComponent(props, context, updater) {
|
120 |
|
121 | this.props = props;
|
122 | this.context = context;
|
123 | this.refs = emptyObject;
|
124 |
|
125 |
|
126 | this.updater = updater || ReactNoopUpdateQueue;
|
127 | }
|
128 |
|
129 | function ComponentDummy() {}
|
130 | ComponentDummy.prototype = ReactComponent.prototype;
|
131 | ReactPureComponent.prototype = new ComponentDummy();
|
132 | ReactPureComponent.prototype.constructor = ReactPureComponent;
|
133 |
|
134 | _assign(ReactPureComponent.prototype, ReactComponent.prototype);
|
135 | ReactPureComponent.prototype.isPureReactComponent = true;
|
136 |
|
137 | module.exports = {
|
138 | Component: ReactComponent,
|
139 | PureComponent: ReactPureComponent
|
140 | }; |
\ | No newline at end of file |