@@ -157,73 +157,79 @@ Object.assign(SyntheticEvent.prototype, {
157
157
* won't be added back into the pool.
158
158
*/
159
159
persist : function ( ) {
160
- this . isPersistent = functionThatReturnsTrue ;
160
+ // Modern event system doesn't use pooling.
161
+ if ( ! enableModernEventSystem ) {
162
+ this . isPersistent = functionThatReturnsTrue ;
163
+ }
161
164
} ,
162
165
163
166
/**
164
167
* Checks if this event should be released back into the pool.
165
168
*
166
169
* @return {boolean } True if this should not be released, false otherwise.
167
170
*/
168
- isPersistent : functionThatReturnsFalse ,
171
+ isPersistent : enableModernEventSystem
172
+ ? functionThatReturnsTrue
173
+ : functionThatReturnsFalse ,
169
174
170
175
/**
171
176
* `PooledClass` looks for `destructor` on each instance it releases.
172
177
*/
173
178
destructor : function ( ) {
174
- const Interface = this . constructor . Interface ;
175
- for ( const propName in Interface ) {
179
+ // Modern event system doesn't use pooling.
180
+ if ( ! enableModernEventSystem ) {
181
+ const Interface = this . constructor . Interface ;
182
+ for ( const propName in Interface ) {
183
+ if ( __DEV__ ) {
184
+ Object . defineProperty (
185
+ this ,
186
+ propName ,
187
+ getPooledWarningPropertyDefinition ( propName , Interface [ propName ] ) ,
188
+ ) ;
189
+ } else {
190
+ this [ propName ] = null ;
191
+ }
192
+ }
193
+ this . dispatchConfig = null ;
194
+ this . _targetInst = null ;
195
+ this . nativeEvent = null ;
196
+ this . isDefaultPrevented = functionThatReturnsFalse ;
197
+ this . isPropagationStopped = functionThatReturnsFalse ;
198
+ this . _dispatchListeners = null ;
199
+ this . _dispatchInstances = null ;
176
200
if ( __DEV__ ) {
177
201
Object . defineProperty (
178
202
this ,
179
- propName ,
180
- getPooledWarningPropertyDefinition ( propName , Interface [ propName ] ) ,
203
+ 'nativeEvent' ,
204
+ getPooledWarningPropertyDefinition ( 'nativeEvent' , null ) ,
181
205
) ;
182
- } else {
183
- this [ propName ] = null ;
184
- }
185
- }
186
- this . dispatchConfig = null ;
187
- this . _targetInst = null ;
188
- this . nativeEvent = null ;
189
- this . isDefaultPrevented = functionThatReturnsFalse ;
190
- this . isPropagationStopped = functionThatReturnsFalse ;
191
- if ( ! enableModernEventSystem ) {
192
- this . _dispatchListeners = null ;
193
- this . _dispatchInstances = null ;
194
- }
195
- if ( __DEV__ ) {
196
- Object . defineProperty (
197
- this ,
198
- 'nativeEvent' ,
199
- getPooledWarningPropertyDefinition ( 'nativeEvent' , null ) ,
200
- ) ;
201
- Object . defineProperty (
202
- this ,
203
- 'isDefaultPrevented' ,
204
- getPooledWarningPropertyDefinition (
206
+ Object . defineProperty (
207
+ this ,
205
208
'isDefaultPrevented' ,
206
- functionThatReturnsFalse ,
207
- ) ,
208
- ) ;
209
- Object . defineProperty (
210
- this ,
211
- 'isPropagationStopped' ,
212
- getPooledWarningPropertyDefinition (
209
+ getPooledWarningPropertyDefinition (
210
+ 'isDefaultPrevented' ,
211
+ functionThatReturnsFalse ,
212
+ ) ,
213
+ ) ;
214
+ Object . defineProperty (
215
+ this ,
213
216
'isPropagationStopped' ,
214
- functionThatReturnsFalse ,
215
- ) ,
216
- ) ;
217
- Object . defineProperty (
218
- this ,
219
- 'preventDefault' ,
220
- getPooledWarningPropertyDefinition ( 'preventDefault' , ( ) => { } ) ,
221
- ) ;
222
- Object . defineProperty (
223
- this ,
224
- 'stopPropagation' ,
225
- getPooledWarningPropertyDefinition ( 'stopPropagation' , ( ) => { } ) ,
226
- ) ;
217
+ getPooledWarningPropertyDefinition (
218
+ 'isPropagationStopped' ,
219
+ functionThatReturnsFalse ,
220
+ ) ,
221
+ ) ;
222
+ Object . defineProperty (
223
+ this ,
224
+ 'preventDefault' ,
225
+ getPooledWarningPropertyDefinition ( 'preventDefault' , ( ) => { } ) ,
226
+ ) ;
227
+ Object . defineProperty (
228
+ this ,
229
+ 'stopPropagation' ,
230
+ getPooledWarningPropertyDefinition ( 'stopPropagation' , ( ) => { } ) ,
231
+ ) ;
232
+ }
227
233
}
228
234
} ,
229
235
} ) ;
@@ -303,18 +309,26 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
303
309
}
304
310
}
305
311
306
- function getPooledEvent ( dispatchConfig , targetInst , nativeEvent , nativeInst ) {
312
+ function createOrGetPooledEvent (
313
+ dispatchConfig ,
314
+ targetInst ,
315
+ nativeEvent ,
316
+ nativeInst ,
317
+ ) {
307
318
const EventConstructor = this ;
308
- if ( EventConstructor . eventPool . length ) {
309
- const instance = EventConstructor . eventPool . pop ( ) ;
310
- EventConstructor . call (
311
- instance ,
312
- dispatchConfig ,
313
- targetInst ,
314
- nativeEvent ,
315
- nativeInst ,
316
- ) ;
317
- return instance ;
319
+ // Modern event system doesn't use pooling.
320
+ if ( ! enableModernEventSystem ) {
321
+ if ( EventConstructor . eventPool . length ) {
322
+ const instance = EventConstructor . eventPool . pop ( ) ;
323
+ EventConstructor . call (
324
+ instance ,
325
+ dispatchConfig ,
326
+ targetInst ,
327
+ nativeEvent ,
328
+ nativeInst ,
329
+ ) ;
330
+ return instance ;
331
+ }
318
332
}
319
333
return new EventConstructor (
320
334
dispatchConfig ,
@@ -325,21 +339,28 @@ function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
325
339
}
326
340
327
341
function releasePooledEvent ( event ) {
328
- const EventConstructor = this ;
329
- invariant (
330
- event instanceof EventConstructor ,
331
- 'Trying to release an event instance into a pool of a different type.' ,
332
- ) ;
333
- event . destructor ( ) ;
334
- if ( EventConstructor . eventPool . length < EVENT_POOL_SIZE ) {
335
- EventConstructor . eventPool . push ( event ) ;
342
+ // Modern event system doesn't use pooling.
343
+ if ( ! enableModernEventSystem ) {
344
+ const EventConstructor = this ;
345
+ invariant (
346
+ event instanceof EventConstructor ,
347
+ 'Trying to release an event instance into a pool of a different type.' ,
348
+ ) ;
349
+ event . destructor ( ) ;
350
+ if ( EventConstructor . eventPool . length < EVENT_POOL_SIZE ) {
351
+ EventConstructor . eventPool . push ( event ) ;
352
+ }
336
353
}
337
354
}
338
355
339
356
function addEventPoolingTo ( EventConstructor ) {
340
- EventConstructor . eventPool = [ ] ;
341
- EventConstructor . getPooled = getPooledEvent ;
342
- EventConstructor . release = releasePooledEvent ;
357
+ EventConstructor . getPooled = createOrGetPooledEvent ;
358
+
359
+ // Modern event system doesn't use pooling.
360
+ if ( ! enableModernEventSystem ) {
361
+ EventConstructor . eventPool = [ ] ;
362
+ EventConstructor . release = releasePooledEvent ;
363
+ }
343
364
}
344
365
345
366
export default SyntheticEvent ;
0 commit comments