@@ -156,9 +156,7 @@ The constructor logic is as follows:
156
156
* Pulls out all statics defined on ` statics ` plus the few special cased
157
157
statics like ` propTypes ` , ` childContextTypes ` , ` contextTypes ` , and
158
158
` displayName ` and transforms them to ` static ` properties at the very top.
159
- like ` static displayName = 'Counter'; `
160
- * TODO do we bind stuff in the ` static ` object?
161
- * Takes ` getDefaultProps ` and inlines it as a static ` defaultProps ` .
159
+ * Takes ` getDefaultProps ` and inlines it as ` static defaultProps = ...; ` .
162
160
If ` getDefaultProps ` is defined as a function with a single statement that
163
161
returns an object, it optimizes and transforms
164
162
` getDefaultProps() { return {foo: 'bar'}; } ` into
@@ -168,34 +166,20 @@ The constructor logic is as follows:
168
166
will be executed only a single time per app-lifetime. In practice this
169
167
hasn't caused any issues – ` getDefaultProps ` should not contain any
170
168
side-effects.
169
+ * If there exists references to ` this.props ` in ` getInitialState ` then it creates
170
+ a constructor and converts ` getInitialState ` to an assignment to ` this.state ` ;
171
+ Otherwise it lifts ` getInitialState ` to a property initializer (` state = ...; ` ).
171
172
* Transforms class methods to arrow functions as class property initializers
172
173
(i.e., to bind them) if methods are referenced without being
173
174
called directly. It checks for ` this.foo ` but also traces variable
174
175
assignments like ` var self = this; self.foo ` . It does not bind functions
175
176
from the React API (lifecycle methods) and ignores functions that are being
176
177
called directly (unless it is both called directly and passed around to
177
- somewhere else)
178
- * TODO how do we handle ` getInitialState ` ?
179
- * If we reference ` this.props ` in ` getInitialState ` then it
180
- has to be in the constructor
181
- * Otherwise it's simple and just make it a property initializer
182
- * TODO [ ???] When ` --no-super-class ` is passed it only optionally extends
178
+ somewhere else).
179
+ * TODO When ` --no-super-class ` is passed it only optionally extends
183
180
` React.Component ` when ` setState ` or ` forceUpdate ` are used within the
184
181
class.
185
182
186
- The constructor logic is as follows:
187
-
188
- * Call ` super(props, context) ` if the base class needs to be extended.
189
- * Bind all functions that are passed around,
190
- like ` this.foo = this.foo.bind(this) `
191
- * Inline ` getInitialState ` (and remove ` getInitialState ` from the spec). It
192
- also updates access of ` this.props.foo ` to ` props.foo ` and adds ` props ` as
193
- argument to the constructor. This is necessary in the case when the base
194
- class does not need to be extended where ` this.props ` will only be set by
195
- React after the constructor has been run.
196
- * Changes ` return StateObject ` from ` getInitialState ` to assign ` this.state `
197
- directly.
198
-
199
183
### Recast Options
200
184
201
185
Options to [ recast] ( https://github.com/benjamn/recast ) 's printer can be provided
0 commit comments