@@ -117,44 +117,56 @@ if (__DEV__) {
117
117
}
118
118
}
119
119
120
- /**
121
- * Base class helpers for the updating state of a component.
122
- */
120
+ function ComponentDummy ( ) { }
121
+ ComponentDummy . prototype = Component . prototype ;
122
+
123
+ function configurePrototype ( ComponentSubclass , prototypeProperties ) {
124
+ const prototype = ( ComponentSubclass . prototype = new ComponentDummy ( ) ) ;
125
+ prototype . constructor = ComponentSubclass ;
126
+
127
+ // Avoid an extra prototype jump for these methods.
128
+ Object . assign ( prototype , Component . prototype ) ;
129
+
130
+ // Mixin additional properties
131
+ Object . assign ( prototype , prototypeProperties ) ;
132
+ }
133
+
134
+ // Convenience component with default shallow equality check for sCU.
123
135
function PureComponent ( props , context , updater ) {
124
- // Duplicated from Component.
125
136
this . props = props ;
126
137
this . context = context ;
127
138
this . refs = emptyObject ;
128
- // We initialize the default updater but the real one gets injected by the
129
- // renderer.
130
139
this . updater = updater || ReactNoopUpdateQueue ;
131
140
}
141
+ configurePrototype ( PureComponent , { isPureReactComponent : true } ) ;
132
142
133
- function ComponentDummy ( ) { }
134
- ComponentDummy . prototype = Component . prototype ;
135
- const pureComponentPrototype = ( PureComponent . prototype = new ComponentDummy ( ) ) ;
136
- pureComponentPrototype . constructor = PureComponent ;
137
- // Avoid an extra prototype jump for these methods.
138
- Object . assign ( pureComponentPrototype , Component . prototype ) ;
139
- pureComponentPrototype . isPureReactComponent = true ;
140
-
143
+ // Special component type that opts subtree into async rendering mode.
141
144
function AsyncComponent ( props , context , updater ) {
142
- // Duplicated from Component.
143
145
this . props = props ;
144
146
this . context = context ;
145
147
this . refs = emptyObject ;
146
- // We initialize the default updater but the real one gets injected by the
147
- // renderer.
148
148
this . updater = updater || ReactNoopUpdateQueue ;
149
149
}
150
+ configurePrototype ( AsyncComponent , {
151
+ unstable_isAsyncReactComponent : true ,
152
+ render : function render ( ) {
153
+ return this . props . children ;
154
+ } ,
155
+ } ) ;
150
156
151
- const asyncComponentPrototype = ( AsyncComponent . prototype = new ComponentDummy ( ) ) ;
152
- asyncComponentPrototype . constructor = AsyncComponent ;
153
- // Avoid an extra prototype jump for these methods.
154
- Object . assign ( asyncComponentPrototype , Component . prototype ) ;
155
- asyncComponentPrototype . unstable_isAsyncReactComponent = true ;
156
- asyncComponentPrototype . render = function ( ) {
157
- return this . props . children ;
158
- } ;
157
+ // Special component type that enables async rendering dev warnings.
158
+ // This helps detect unsafe lifecycles without enabling actual async behavior.
159
+ function PreAsyncComponent ( props , context , updater ) {
160
+ this . props = props ;
161
+ this . context = context ;
162
+ this . refs = emptyObject ;
163
+ this . updater = updater || ReactNoopUpdateQueue ;
164
+ }
165
+ configurePrototype ( PreAsyncComponent , {
166
+ unstable_isPreAsyncReactComponent : true ,
167
+ render : function render ( ) {
168
+ return this . props . children ;
169
+ } ,
170
+ } ) ;
159
171
160
- export { Component , PureComponent , AsyncComponent } ;
172
+ export { Component , PureComponent , AsyncComponent , PreAsyncComponent } ;
0 commit comments