@@ -14,20 +14,15 @@ import getEventCharCode from './getEventCharCode';
14
14
* @see http://www.w3.org/TR/DOM-Level-3-Events/
15
15
*/
16
16
const EventInterface = {
17
- type : null ,
18
- target : null ,
19
- // currentTarget is set when dispatching; no use in copying it here
20
- currentTarget : function ( ) {
21
- return null ;
22
- } ,
23
- eventPhase : null ,
24
- bubbles : null ,
25
- cancelable : null ,
17
+ type : 0 ,
18
+ eventPhase : 0 ,
19
+ bubbles : 0 ,
20
+ cancelable : 0 ,
26
21
timeStamp : function ( event ) {
27
22
return event . timeStamp || Date . now ( ) ;
28
23
} ,
29
- defaultPrevented : null ,
30
- isTrusted : null ,
24
+ defaultPrevented : 0 ,
25
+ isTrusted : 0 ,
31
26
} ;
32
27
33
28
function functionThatReturnsTrue ( ) {
@@ -56,12 +51,14 @@ export function SyntheticEvent(
56
51
targetInst ,
57
52
nativeEvent ,
58
53
nativeEventTarget ,
54
+ Interface = EventInterface ,
59
55
) {
60
56
this . _reactName = reactName ;
61
57
this . _targetInst = targetInst ;
62
58
this . nativeEvent = nativeEvent ;
59
+ this . target = nativeEventTarget ;
60
+ this . currentTarget = null ;
63
61
64
- const Interface = this . constructor . Interface ;
65
62
for ( const propName in Interface ) {
66
63
if ( ! Interface . hasOwnProperty ( propName ) ) {
67
64
continue ;
@@ -70,11 +67,7 @@ export function SyntheticEvent(
70
67
if ( normalize ) {
71
68
this [ propName ] = normalize ( nativeEvent ) ;
72
69
} else {
73
- if ( propName === 'target' ) {
74
- this . target = nativeEventTarget ;
75
- } else {
76
- this [ propName ] = nativeEvent [ propName ] ;
77
- }
70
+ this [ propName ] = nativeEvent [ propName ] ;
78
71
}
79
72
}
80
73
@@ -144,36 +137,12 @@ Object.assign(SyntheticEvent.prototype, {
144
137
isPersistent : functionThatReturnsTrue ,
145
138
} ) ;
146
139
147
- SyntheticEvent . Interface = EventInterface ;
148
-
149
- /**
150
- * Helper to reduce boilerplate when creating subclasses.
151
- */
152
- SyntheticEvent . extend = function ( Interface ) {
153
- const Super = this ;
154
-
155
- const E = function ( ) { } ;
156
- E . prototype = Super . prototype ;
157
- const prototype = new E ( ) ;
158
-
159
- function Class ( ) {
160
- return Super . apply ( this , arguments ) ;
161
- }
162
- Object . assign ( prototype , Class . prototype ) ;
163
- Class . prototype = prototype ;
164
- Class . prototype . constructor = Class ;
165
-
166
- Class . Interface = Object . assign ( { } , Super . Interface , Interface ) ;
167
- Class . extend = Super . extend ;
168
-
169
- return Class ;
140
+ export const UIEventInterface = {
141
+ ...EventInterface ,
142
+ view : 0 ,
143
+ detail : 0 ,
170
144
} ;
171
145
172
- export const SyntheticUIEvent = SyntheticEvent . extend ( {
173
- view : null ,
174
- detail : null ,
175
- } ) ;
176
-
177
146
let previousScreenX = 0 ;
178
147
let previousScreenY = 0 ;
179
148
// Use flags to signal movementX/Y has already been set
@@ -184,20 +153,21 @@ let isMovementYSet = false;
184
153
* @interface MouseEvent
185
154
* @see http://www.w3.org/TR/DOM-Level-3-Events/
186
155
*/
187
- export const SyntheticMouseEvent = SyntheticUIEvent . extend ( {
188
- screenX : null ,
189
- screenY : null ,
190
- clientX : null ,
191
- clientY : null ,
192
- pageX : null ,
193
- pageY : null ,
194
- ctrlKey : null ,
195
- shiftKey : null ,
196
- altKey : null ,
197
- metaKey : null ,
156
+ export const MouseEventInterface = {
157
+ ...UIEventInterface ,
158
+ screenX : 0 ,
159
+ screenY : 0 ,
160
+ clientX : 0 ,
161
+ clientY : 0 ,
162
+ pageX : 0 ,
163
+ pageY : 0 ,
164
+ ctrlKey : 0 ,
165
+ shiftKey : 0 ,
166
+ altKey : 0 ,
167
+ metaKey : 0 ,
198
168
getModifierState : getEventModifierState ,
199
- button : null ,
200
- buttons : null ,
169
+ button : 0 ,
170
+ buttons : 0 ,
201
171
relatedTarget : function ( event ) {
202
172
return (
203
173
event . relatedTarget ||
@@ -236,63 +206,67 @@ export const SyntheticMouseEvent = SyntheticUIEvent.extend({
236
206
237
207
return event . type === 'mousemove' ? event . screenY - screenY : 0 ;
238
208
} ,
239
- } ) ;
209
+ } ;
240
210
241
211
/**
242
212
* @interface DragEvent
243
213
* @see http://www.w3.org/TR/DOM-Level-3-Events/
244
214
*/
245
- export const SyntheticDragEvent = SyntheticMouseEvent . extend ( {
246
- dataTransfer : null ,
247
- } ) ;
215
+ export const DragEventInterface = {
216
+ ...MouseEventInterface ,
217
+ dataTransfer : 0 ,
218
+ } ;
248
219
249
220
/**
250
221
* @interface FocusEvent
251
222
* @see http://www.w3.org/TR/DOM-Level-3-Events/
252
223
*/
253
- export const SyntheticFocusEvent = SyntheticUIEvent . extend ( {
254
- relatedTarget : null ,
255
- } ) ;
224
+ export const FocusEventInterface = {
225
+ ...UIEventInterface ,
226
+ relatedTarget : 0 ,
227
+ } ;
256
228
257
229
/**
258
230
* @interface Event
259
231
* @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
260
232
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
261
233
*/
262
- export const SyntheticAnimationEvent = SyntheticEvent . extend ( {
263
- animationName : null ,
264
- elapsedTime : null ,
265
- pseudoElement : null ,
266
- } ) ;
234
+ export const AnimationEventInterface = {
235
+ ...EventInterface ,
236
+ animationName : 0 ,
237
+ elapsedTime : 0 ,
238
+ pseudoElement : 0 ,
239
+ } ;
267
240
268
241
/**
269
242
* @interface Event
270
243
* @see http://www.w3.org/TR/clipboard-apis/
271
244
*/
272
- export const SyntheticClipboardEvent = SyntheticEvent . extend ( {
245
+ export const ClipboardEventInterface = {
246
+ ...EventInterface ,
273
247
clipboardData : function ( event ) {
274
248
return 'clipboardData' in event
275
249
? event . clipboardData
276
250
: window . clipboardData ;
277
251
} ,
278
- } ) ;
252
+ } ;
279
253
280
254
/**
281
255
* @interface Event
282
256
* @see http://www.w3.org/TR/DOM-Level-3-Events/#events-compositionevents
283
257
*/
284
- export const SyntheticCompositionEvent = SyntheticEvent . extend ( {
285
- data : null ,
286
- } ) ;
258
+ export const CompositionEventInterface = {
259
+ ...EventInterface ,
260
+ data : 0 ,
261
+ } ;
287
262
288
263
/**
289
264
* @interface Event
290
265
* @see http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105
291
266
* /#events-inputevents
292
267
*/
293
- export const SyntheticInputEvent = SyntheticEvent . extend ( {
294
- data : null ,
295
- } ) ;
268
+ // Happens to share the same list for now.
269
+ export const InputEventInterface = CompositionEventInterface ;
296
270
297
271
/**
298
272
* Normalization of deprecated HTML5 `key` values
@@ -422,16 +396,17 @@ function getEventModifierState(nativeEvent) {
422
396
* @interface KeyboardEvent
423
397
* @see http://www.w3.org/TR/DOM-Level-3-Events/
424
398
*/
425
- export const SyntheticKeyboardEvent = SyntheticUIEvent . extend ( {
399
+ export const KeyboardEventInterface = {
400
+ ...UIEventInterface ,
426
401
key : getEventKey ,
427
- code : null ,
428
- location : null ,
429
- ctrlKey : null ,
430
- shiftKey : null ,
431
- altKey : null ,
432
- metaKey : null ,
433
- repeat : null ,
434
- locale : null ,
402
+ code : 0 ,
403
+ location : 0 ,
404
+ ctrlKey : 0 ,
405
+ shiftKey : 0 ,
406
+ altKey : 0 ,
407
+ metaKey : 0 ,
408
+ repeat : 0 ,
409
+ locale : 0 ,
435
410
getModifierState : getEventModifierState ,
436
411
// Legacy Interface
437
412
charCode : function ( event ) {
@@ -469,56 +444,60 @@ export const SyntheticKeyboardEvent = SyntheticUIEvent.extend({
469
444
}
470
445
return 0 ;
471
446
} ,
472
- } ) ;
447
+ } ;
473
448
474
449
/**
475
450
* @interface PointerEvent
476
451
* @see http://www.w3.org/TR/pointerevents/
477
452
*/
478
- export const SyntheticPointerEvent = SyntheticMouseEvent . extend ( {
479
- pointerId : null ,
480
- width : null ,
481
- height : null ,
482
- pressure : null ,
483
- tangentialPressure : null ,
484
- tiltX : null ,
485
- tiltY : null ,
486
- twist : null ,
487
- pointerType : null ,
488
- isPrimary : null ,
489
- } ) ;
453
+ export const PointerEventInterface = {
454
+ ...MouseEventInterface ,
455
+ pointerId : 0 ,
456
+ width : 0 ,
457
+ height : 0 ,
458
+ pressure : 0 ,
459
+ tangentialPressure : 0 ,
460
+ tiltX : 0 ,
461
+ tiltY : 0 ,
462
+ twist : 0 ,
463
+ pointerType : 0 ,
464
+ isPrimary : 0 ,
465
+ } ;
490
466
491
467
/**
492
468
* @interface TouchEvent
493
469
* @see http://www.w3.org/TR/touch-events/
494
470
*/
495
- export const SyntheticTouchEvent = SyntheticUIEvent . extend ( {
496
- touches : null ,
497
- targetTouches : null ,
498
- changedTouches : null ,
499
- altKey : null ,
500
- metaKey : null ,
501
- ctrlKey : null ,
502
- shiftKey : null ,
471
+ export const TouchEventInterface = {
472
+ ...UIEventInterface ,
473
+ touches : 0 ,
474
+ targetTouches : 0 ,
475
+ changedTouches : 0 ,
476
+ altKey : 0 ,
477
+ metaKey : 0 ,
478
+ ctrlKey : 0 ,
479
+ shiftKey : 0 ,
503
480
getModifierState : getEventModifierState ,
504
- } ) ;
481
+ } ;
505
482
506
483
/**
507
484
* @interface Event
508
485
* @see http://www.w3.org/TR/2009/WD-css3-transitions-20090320/#transition-events-
509
486
* @see https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent
510
487
*/
511
- export const SyntheticTransitionEvent = SyntheticEvent . extend ( {
512
- propertyName : null ,
513
- elapsedTime : null ,
514
- pseudoElement : null ,
515
- } ) ;
488
+ export const TransitionEventInterface = {
489
+ ...EventInterface ,
490
+ propertyName : 0 ,
491
+ elapsedTime : 0 ,
492
+ pseudoElement : 0 ,
493
+ } ;
516
494
517
495
/**
518
496
* @interface WheelEvent
519
497
* @see http://www.w3.org/TR/DOM-Level-3-Events/
520
498
*/
521
- export const SyntheticWheelEvent = SyntheticMouseEvent . extend ( {
499
+ export const WheelEventInterface = {
500
+ ...MouseEventInterface ,
522
501
deltaX ( event ) {
523
502
return 'deltaX' in event
524
503
? event . deltaX
@@ -538,11 +517,11 @@ export const SyntheticWheelEvent = SyntheticMouseEvent.extend({
538
517
? - event . wheelDelta
539
518
: 0 ;
540
519
} ,
541
- deltaZ : null ,
520
+ deltaZ : 0 ,
542
521
543
522
// Browsers without "deltaMode" is reporting in raw wheel delta where one
544
523
// notch on the scroll is always +/- 120, roughly equivalent to pixels.
545
524
// A good approximation of DOM_DELTA_LINE (1) is 5% of viewport size or
546
525
// ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
547
- deltaMode : null ,
548
- } ) ;
526
+ deltaMode : 0 ,
527
+ } ;
0 commit comments