24
var { isMounted } = require('ReactFiberTreeReflection');
25
var ReactInstanceMap = require('ReactInstanceMap');
26
var shallowEqual = require('shallowEqual');
27
+var warning = require('warning');
28
+var invariant = require('invariant');
29
+
30
+
31
+const isArray = Array.isArray;
32
33
module.exports = function(scheduleUpdate : (fiber: Fiber) => void) {
34
96
return true;
97
}
98
99
+ function getName(workInProgress: Fiber, inst: any): string {
100
+ const type = workInProgress.type;
101
+ const constructor = inst && inst.constructor;
102
+ return (
103
+ type.displayName || (constructor && constructor.displayName) ||
104
+ type.name || (constructor && constructor.name) ||
105
+ 'A Component'
106
+ );
107
+ }
108
+
109
+ function checkClassInstance(workInProgress: Fiber, inst: any) {
110
+ if (__DEV__) {
111
+ const name = getName(workInProgress, inst);
112
+ const renderPresent = inst.render;
113
+ warning(
114
+ renderPresent,
115
+ '%s(...): No `render` method found on the returned component ' +
116
+ 'instance: you may have forgotten to define `render`.',
117
+ name
118
+ );
119
+ const noGetInitialStateOnES6 = (
120
+ !inst.getInitialState ||
121
+ inst.getInitialState.isReactClassApproved
122
+ );
123
+ warning(
124
+ noGetInitialStateOnES6,
125
+ 'getInitialState was defined on %s, a plain JavaScript class. ' +
126
+ 'This is only supported for classes created using React.createClass. ' +
127
+ 'Did you mean to define a state property instead?',
128
+ name
129
+ );
130
+ const noGetDefaultPropsOnES6 = (
131
+ !inst.getDefaultProps ||
132
+ inst.getDefaultProps.isReactClassApproved
133
+ );
134
+ warning(
135
+ noGetDefaultPropsOnES6,
136
+ 'getDefaultProps was defined on %s, a plain JavaScript class. ' +
137
+ 'This is only supported for classes created using React.createClass. ' +
138
+ 'Use a static property to define defaultProps instead.',
139
+ name
140
+ );
141
+ const noInstancePropTypes = !inst.propTypes;
142
+ warning(
143
+ noInstancePropTypes,
144
+ 'propTypes was defined as an instance property on %s. Use a static ' +
145
+ 'property to define propTypes instead.',
146
+ name,
147
+ );
148
+ const noInstanceContextTypes = !inst.contextTypes;
149
+ warning(
150
+ noInstanceContextTypes,
151
+ 'contextTypes was defined as an instance property on %s. Use a static ' +
152
+ 'property to define contextTypes instead.',
153
+ name,
154
+ );
155
+ const noComponentShouldUpdate = typeof inst.componentShouldUpdate !== 'function';
156
+ warning(
157
+ noComponentShouldUpdate,
158
+ '%s has a method called ' +
159
+ 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
160
+ 'The name is phrased as a question because the function is ' +
161
+ 'expected to return a value.',
162
+ name
163
+ );
164
+ const noComponentDidUnmount = typeof inst.componentDidUnmount !== 'function';
165
+ warning(
166
+ noComponentDidUnmount,
167
+ '%s has a method called ' +
168
+ 'componentDidUnmount(). But there is no such lifecycle method. ' +
169
+ 'Did you mean componentWillUnmount()?',
170
+ name
171
+ );
172
+ const noComponentWillRecieveProps = typeof inst.componentWillRecieveProps !== 'function';
173
+ warning(
174
+ noComponentWillRecieveProps,
175
+ '%s has a method called ' +
176
+ 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?',
177
+ name
178
+ );
179
+ }
180
+
181
+ const instanceState = inst.state;
182
+ if (instanceState && (typeof instanceState !== 'object' || isArray(instanceState))) {
183
+ invariant(
184
+ false,
185
+ '%s.state: must be set to an object or null',
186
+ getName(workInProgress, inst)
187
+ );
188
+ }
189
+ }
190
+
191
function adoptClassInstance(workInProgress : Fiber, instance : any) : void {
192
instance.updater = updater;
193
workInProgress.stateNode = instance;
199
const ctor = workInProgress.type;
200
const props = workInProgress.pendingProps;
201
const instance = new ctor(props);
202
+ checkClassInstance(workInProgress, instance);
203
adoptClassInstance(workInProgress, instance);
204
return instance;
205
}