3
3
*
4
4
* This source code is licensed under the MIT license found in the
5
5
* LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
6
8
*/
7
9
8
10
/* eslint valid-typeof: 0 */
9
11
10
12
import getEventCharCode from './getEventCharCode' ;
11
13
14
+ type EventInterfaceType = {
15
+ [ propName : string ] : 0 | ( ( event : { [ propName : string ] : mixed } ) => mixed ) ,
16
+ } ;
17
+
12
18
/**
13
19
* @interface Event
14
20
* @see http://www.w3.org/TR/DOM-Level-3-Events/
15
21
*/
16
- const EventInterface = {
22
+ const EventInterface : EventInterfaceType = {
17
23
eventPhase : 0 ,
18
24
bubbles : 0 ,
19
25
cancelable : 0 ,
@@ -46,12 +52,12 @@ function functionThatReturnsFalse() {
46
52
* DOM interface; custom application-specific events can also subclass this.
47
53
*/
48
54
export function SyntheticEvent (
49
- reactName ,
50
- reactEventType ,
51
- targetInst ,
52
- nativeEvent ,
53
- nativeEventTarget ,
54
- Interface = EventInterface ,
55
+ reactName : string | null ,
56
+ reactEventType : string ,
57
+ targetInst : Fiber ,
58
+ nativeEvent : { [ propName : string ] : mixed } ,
59
+ nativeEventTarget : null | EventTarget ,
60
+ Interface : EventInterfaceType = EventInterface ,
55
61
) {
56
62
this. _reactName = reactName ;
57
63
this . _targetInst = targetInst ;
@@ -95,6 +101,7 @@ Object.assign(SyntheticEvent.prototype, {
95
101
96
102
if ( event . preventDefault ) {
97
103
event . preventDefault ( ) ;
104
+ // $FlowFixMe - flow is not aware of `unknown` in IE
98
105
} else if ( typeof event . returnValue !== 'unknown' ) {
99
106
event . returnValue = false ;
100
107
}
@@ -109,6 +116,7 @@ Object.assign(SyntheticEvent.prototype, {
109
116
110
117
if ( event . stopPropagation ) {
111
118
event . stopPropagation ( ) ;
119
+ // $FlowFixMe - flow is not aware of `unknown` in IE
112
120
} else if ( typeof event . cancelBubble !== 'unknown' ) {
113
121
// The ChangeEventPlugin registers a "propertychange" event for
114
122
// IE. This event does not support bubbling or cancelling, and
@@ -138,7 +146,7 @@ Object.assign(SyntheticEvent.prototype, {
138
146
isPersistent : functionThatReturnsTrue ,
139
147
} ) ;
140
148
141
- export const UIEventInterface = {
149
+ export const UIEventInterface : EventInterfaceType = {
142
150
...EventInterface ,
143
151
view : 0 ,
144
152
detail : 0 ,
@@ -154,7 +162,7 @@ let isMovementYSet = false;
154
162
* @interface MouseEvent
155
163
* @see http://www.w3.org/TR/DOM-Level-3-Events/
156
164
*/
157
- export const MouseEventInterface = {
165
+ export const MouseEventInterface : EventInterfaceType = {
158
166
...UIEventInterface ,
159
167
screenX : 0 ,
160
168
screenY : 0 ,
@@ -213,7 +221,7 @@ export const MouseEventInterface = {
213
221
* @interface DragEvent
214
222
* @see http://www.w3.org/TR/DOM-Level-3-Events/
215
223
*/
216
- export const DragEventInterface = {
224
+ export const DragEventInterface : EventInterfaceType = {
217
225
...MouseEventInterface ,
218
226
dataTransfer : 0 ,
219
227
} ;
@@ -222,7 +230,7 @@ export const DragEventInterface = {
222
230
* @interface FocusEvent
223
231
* @see http://www.w3.org/TR/DOM-Level-3-Events/
224
232
*/
225
- export const FocusEventInterface = {
233
+ export const FocusEventInterface : EventInterfaceType = {
226
234
...UIEventInterface ,
227
235
relatedTarget : 0 ,
228
236
} ;
@@ -232,7 +240,7 @@ export const FocusEventInterface = {
232
240
* @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
233
241
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
234
242
*/
235
- export const AnimationEventInterface = {
243
+ export const AnimationEventInterface : EventInterfaceType = {
236
244
...EventInterface ,
237
245
animationName : 0 ,
238
246
elapsedTime : 0 ,
@@ -243,7 +251,7 @@ export const AnimationEventInterface = {
243
251
* @interface Event
244
252
* @see http://www.w3.org/TR/clipboard-apis/
245
253
*/
246
- export const ClipboardEventInterface = {
254
+ export const ClipboardEventInterface : EventInterfaceType = {
247
255
...EventInterface ,
248
256
clipboardData : function ( event ) {
249
257
return 'clipboardData' in event
@@ -256,7 +264,7 @@ export const ClipboardEventInterface = {
256
264
* @interface Event
257
265
* @see http://www.w3.org/TR/DOM-Level-3-Events/#events-compositionevents
258
266
*/
259
- export const CompositionEventInterface = {
267
+ export const CompositionEventInterface : EventInterfaceType = {
260
268
...EventInterface ,
261
269
data : 0 ,
262
270
} ;
@@ -267,7 +275,7 @@ export const CompositionEventInterface = {
267
275
* /#events-inputevents
268
276
*/
269
277
// Happens to share the same list for now.
270
- export const InputEventInterface = CompositionEventInterface ;
278
+ export const InputEventInterface : EventInterfaceType = CompositionEventInterface ;
271
279
272
280
/**
273
281
* Normalization of deprecated HTML5 `key` values
0 commit comments