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
- import SyntheticEvent from '../../events/SyntheticEvent' ;
10
+ import type { TopLevelType } from '../TopLevelEventTypes' ;
11
+ import type { DispatchQueue } from '../PluginModuleType' ;
12
+ import type { EventSystemFlags } from '../EventSystemFlags' ;
13
+
14
+ import SyntheticEvent from '../SyntheticEvent' ;
9
15
import isTextInputElement from '../isTextInputElement' ;
10
16
import { canUseDOM } from 'shared/ExecutionEnvironment' ;
11
17
@@ -66,9 +72,8 @@ function createAndAccumulateChangeEvent(
66
72
) ;
67
73
event . type = 'change' ;
68
74
// Flag this event loop as needing state restore.
69
- enqueueStateRestore ( target ) ;
75
+ enqueueStateRestore ( ( ( target : any ) : Node ) ) ;
70
76
accumulateTwoPhaseListeners ( inst , dispatchQueue , event ) ;
71
- return event ;
72
77
}
73
78
/**
74
79
* For IE shims
@@ -82,12 +87,15 @@ let activeElementInst = null;
82
87
function shouldUseChangeEvent ( elem ) {
83
88
const nodeName = elem . nodeName && elem . nodeName . toLowerCase ( ) ;
84
89
return (
85
- nodeName === 'select' || ( nodeName === 'input' && elem . type === 'file' )
90
+ nodeName === 'select' ||
91
+ ( nodeName === 'input' && ( elem : any ) . type === 'file' )
86
92
) ;
87
93
}
88
94
89
95
function manualDispatchChangeEvent ( nativeEvent ) {
90
- const event = createAndAccumulateChangeEvent (
96
+ const dispatchQueue = [ ] ;
97
+ createAndAccumulateChangeEvent (
98
+ dispatchQueue ,
91
99
activeElementInst ,
92
100
nativeEvent ,
93
101
getEventTarget ( nativeEvent ) ,
@@ -104,16 +112,16 @@ function manualDispatchChangeEvent(nativeEvent) {
104
112
// components don't work properly in conjunction with event bubbling because
105
113
// the component is rerendered and the value reverted before all the event
106
114
// handlers can run. See https://github.com/facebook/react/issues/708.
107
- batchedUpdates ( runEventInBatch , event ) ;
115
+ batchedUpdates ( runEventInBatch , dispatchQueue ) ;
108
116
}
109
117
110
- function runEventInBatch ( event ) {
111
- dispatchEventsInBatch ( [ event ] ) ;
118
+ function runEventInBatch ( dispatchQueue ) {
119
+ dispatchEventsInBatch ( dispatchQueue ) ;
112
120
}
113
121
114
- function getInstIfValueChanged ( targetInst ) {
122
+ function getInstIfValueChanged ( targetInst : Object ) {
115
123
const targetNode = getNodeFromInstance ( targetInst ) ;
116
- if ( updateValueIfChanged ( targetNode ) ) {
124
+ if ( updateValueIfChanged ( ( ( targetNode : any ) : HTMLInputElement ) ) ) {
117
125
return targetInst ;
118
126
}
119
127
}
@@ -144,7 +152,7 @@ if (canUseDOM) {
144
152
function startWatchingForValueChange ( target , targetInst ) {
145
153
activeElement = target ;
146
154
activeElementInst = targetInst ;
147
- activeElement . attachEvent ( 'onpropertychange' , handlePropertyChange ) ;
155
+ ( activeElement : any ) . attachEvent ( 'onpropertychange' , handlePropertyChange ) ;
148
156
}
149
157
150
158
/**
@@ -155,7 +163,7 @@ function stopWatchingForValueChange() {
155
163
if ( ! activeElement ) {
156
164
return ;
157
165
}
158
- activeElement . detachEvent ( 'onpropertychange' , handlePropertyChange ) ;
166
+ ( activeElement : any ) . detachEvent ( 'onpropertychange' , handlePropertyChange ) ;
159
167
activeElement = null ;
160
168
activeElementInst = null ;
161
169
}
@@ -240,16 +248,16 @@ function getTargetInstForInputOrChangeEvent(topLevelType, targetInst) {
240
248
}
241
249
}
242
250
243
- function handleControlledInputBlur ( node ) {
244
- const state = node . _wrapperState ;
251
+ function handleControlledInputBlur ( node : HTMLInputElement ) {
252
+ const state = ( node : any ) . _wrapperState ;
245
253
246
254
if ( ! state || ! state . controlled || node . type !== 'number' ) {
247
255
return ;
248
256
}
249
257
250
258
if ( ! disableInputAttributeSyncing ) {
251
259
// If controlled, assign the value attribute to the current value on blur
252
- setDefaultValue ( node , 'number' , node . value ) ;
260
+ setDefaultValue ( ( node : any ) , 'number' , ( node : any ) . value ) ;
253
261
}
254
262
}
255
263
@@ -269,20 +277,20 @@ const ChangeEventPlugin = {
269
277
_isInputEventSupported : isInputEventSupported ,
270
278
271
279
extractEvents : function (
272
- dispatchQueue ,
273
- topLevelType ,
274
- targetInst ,
275
- nativeEvent ,
276
- nativeEventTarget ,
277
- eventSystemFlags ,
278
- container ,
280
+ dispatchQueue : DispatchQueue ,
281
+ topLevelType : TopLevelType ,
282
+ targetInst : null | Fiber ,
283
+ nativeEvent : MouseEvent ,
284
+ nativeEventTarget : null | EventTarget ,
285
+ eventSystemFlags : EventSystemFlags ,
286
+ targetContainer : null | EventTarget ,
279
287
) {
280
288
const targetNode = targetInst ? getNodeFromInstance ( targetInst ) : window ;
281
289
282
290
let getTargetInstFunc, handleEventFunc ;
283
291
if ( shouldUseChangeEvent ( targetNode ) ) {
284
292
getTargetInstFunc = getTargetInstForChangeEvent ;
285
- } else if ( isTextInputElement ( targetNode ) ) {
293
+ } else if ( isTextInputElement ( ( ( targetNode : any ) : HTMLElement ) ) ) {
286
294
if ( isInputEventSupported ) {
287
295
getTargetInstFunc = getTargetInstForInputOrChangeEvent ;
288
296
} else {
@@ -312,7 +320,7 @@ const ChangeEventPlugin = {
312
320
313
321
// When blurring, set the value attribute for number inputs
314
322
if ( topLevelType === TOP_BLUR ) {
315
- handleControlledInputBlur ( targetNode ) ;
323
+ handleControlledInputBlur ( ( ( targetNode : any ) : HTMLInputElement ) ) ;
316
324
}
317
325
} ,
318
326
} ;
0 commit comments