@@ -13,17 +13,12 @@ import type {
13
13
ReactDOMEventResponder ,
14
14
ReactDOMEventResponderInstance ,
15
15
ReactDOMFundamentalComponentInstance ,
16
- ReactDOMListener ,
17
- ReactDOMListenerEvent ,
18
- ReactDOMListenerMap ,
19
16
} from '../shared/ReactDOMTypes' ;
20
- import type { ReactScopeMethods } from 'shared/ReactTypes' ;
21
17
22
18
import {
23
19
precacheFiberNode ,
24
20
updateFiberProps ,
25
21
getClosestInstanceFromNode ,
26
- getListenersFromTarget ,
27
22
} from './ReactDOMComponentTree' ;
28
23
import {
29
24
createElement ,
@@ -69,32 +64,9 @@ import {
69
64
enableSuspenseServerRenderer ,
70
65
enableDeprecatedFlareAPI ,
71
66
enableFundamentalAPI ,
72
- enableUseEventAPI ,
73
- enableScopeAPI ,
74
67
} from 'shared/ReactFeatureFlags' ;
75
- import {
76
- PLUGIN_EVENT_SYSTEM ,
77
- USE_EVENT_SYSTEM ,
78
- } from '../events/EventSystemFlags' ;
79
- import {
80
- isManagedDOMElement ,
81
- isValidEventTarget ,
82
- listenToTopLevelEvent ,
83
- attachListenerToManagedDOMElement ,
84
- detachListenerFromManagedDOMElement ,
85
- attachTargetEventListener ,
86
- detachTargetEventListener ,
87
- isReactScope ,
88
- attachListenerToReactScope ,
89
- detachListenerFromReactScope ,
90
- } from '../events/DOMModernPluginEventSystem' ;
91
- import { getListenerMapForElement } from '../events/DOMEventListenerMap' ;
92
68
import { TOP_BEFORE_BLUR , TOP_AFTER_BLUR } from '../events/DOMTopLevelEventTypes' ;
93
69
94
- export type ReactListenerEvent = ReactDOMListenerEvent ;
95
- export type ReactListenerMap = ReactDOMListenerMap ;
96
- export type ReactListener = ReactDOMListener ;
97
-
98
70
export type Type = string ;
99
71
export type Props = {
100
72
autoFocus ?: boolean ,
@@ -246,7 +218,7 @@ export function prepareForCommit(containerInfo: Container): Object | null {
246
218
eventsEnabled = ReactBrowserEventEmitterIsEnabled ( ) ;
247
219
selectionInformation = getSelectionInformation ( ) ;
248
220
let activeInstance = null ;
249
- if ( enableDeprecatedFlareAPI || enableUseEventAPI ) {
221
+ if ( enableDeprecatedFlareAPI ) {
250
222
const focusedElem = selectionInformation . focusedElem ;
251
223
if ( focusedElem !== null ) {
252
224
activeInstance = getClosestInstanceFromNode ( focusedElem ) ;
@@ -257,15 +229,15 @@ export function prepareForCommit(containerInfo: Container): Object | null {
257
229
}
258
230
259
231
export function beforeActiveInstanceBlur ( ) : void {
260
- if ( enableDeprecatedFlareAPI || enableUseEventAPI ) {
232
+ if ( enableDeprecatedFlareAPI ) {
261
233
ReactBrowserEventEmitterSetEnabled ( true ) ;
262
234
dispatchBeforeDetachedBlur ( ( selectionInformation : any ) . focusedElem ) ;
263
235
ReactBrowserEventEmitterSetEnabled ( false ) ;
264
236
}
265
237
}
266
238
267
239
export function afterActiveInstanceBlur ( ) : void {
268
- if ( enableDeprecatedFlareAPI || enableUseEventAPI ) {
240
+ if ( enableDeprecatedFlareAPI ) {
269
241
ReactBrowserEventEmitterSetEnabled ( true ) ;
270
242
dispatchAfterDetachedBlur ( ( selectionInformation : any ) . focusedElem ) ;
271
243
ReactBrowserEventEmitterSetEnabled ( false ) ;
@@ -528,7 +500,7 @@ function createEvent(type: TopLevelType): Event {
528
500
}
529
501
530
502
function dispatchBeforeDetachedBlur ( target : HTMLElement ) : void {
531
- if ( enableDeprecatedFlareAPI || enableUseEventAPI ) {
503
+ if ( enableDeprecatedFlareAPI ) {
532
504
const event = createEvent ( TOP_BEFORE_BLUR ) ;
533
505
// Dispatch "beforeblur" directly on the target,
534
506
// so it gets picked up by the event system and
@@ -538,7 +510,7 @@ function dispatchBeforeDetachedBlur(target: HTMLElement): void {
538
510
}
539
511
540
512
function dispatchAfterDetachedBlur ( target : HTMLElement ) : void {
541
- if ( enableDeprecatedFlareAPI || enableUseEventAPI ) {
513
+ if ( enableDeprecatedFlareAPI ) {
542
514
const event = createEvent ( TOP_AFTER_BLUR ) ;
543
515
// So we know what was detached, make the relatedTarget the
544
516
// detached target on the "afterblur" event.
@@ -550,23 +522,8 @@ function dispatchAfterDetachedBlur(target: HTMLElement): void {
550
522
551
523
export function beforeRemoveInstance (
552
524
instance : Instance | TextInstance | SuspenseInstance ,
553
- ) : void {
554
- if ( enableUseEventAPI ) {
555
- // It's unfortunate that we have to do this cleanup, but
556
- // it's necessary otherwise we will leak the host instances
557
- // from the useEvent hook instances Map. We call destroy
558
- // on each listener to ensure we properly remove the instance
559
- // from the instances Map. Note: we have this Map so that we
560
- // can properly unmount instances when the function component
561
- // that the hook is attached to gets unmounted.
562
- const listenersSet = getListenersFromTarget ( instance ) ;
563
- if ( listenersSet !== null ) {
564
- const listeners = Array . from ( listenersSet ) ;
565
- for ( let i = 0 ; i < listeners . length ; i ++ ) {
566
- listeners [ i ] . destroy ( instance ) ;
567
- }
568
- }
569
- }
525
+ ) {
526
+ // TODO for ReactDOM.createEventInstance
570
527
}
571
528
572
529
export function removeChild (
@@ -1141,78 +1098,3 @@ export function makeOpaqueHydratingObject(
1141
1098
valueOf : attemptToReadValue ,
1142
1099
} ;
1143
1100
}
1144
-
1145
- export function registerEvent (
1146
- event : ReactDOMListenerEvent ,
1147
- rootContainerInstance : Container ,
1148
- ) : void {
1149
- const { passive, priority, type} = event ;
1150
- const listenerMap = getListenerMapForElement ( rootContainerInstance ) ;
1151
- // Add the event listener to the target container (falling back to
1152
- // the target if we didn't find one).
1153
- listenToTopLevelEvent (
1154
- type ,
1155
- rootContainerInstance ,
1156
- listenerMap ,
1157
- PLUGIN_EVENT_SYSTEM | USE_EVENT_SYSTEM ,
1158
- passive ,
1159
- priority ,
1160
- ) ;
1161
- }
1162
-
1163
- export function mountEventListener ( listener : ReactDOMListener ) : void {
1164
- if ( enableUseEventAPI ) {
1165
- const { target} = listener ;
1166
- if ( isManagedDOMElement ( target ) ) {
1167
- attachListenerToManagedDOMElement ( listener ) ;
1168
- } else if ( enableScopeAPI && isReactScope ( target ) ) {
1169
- attachListenerToReactScope ( listener ) ;
1170
- } else {
1171
- attachTargetEventListener ( listener ) ;
1172
- }
1173
- }
1174
- }
1175
-
1176
- export function unmountEventListener ( listener : ReactDOMListener ) : void {
1177
- if ( enableUseEventAPI ) {
1178
- const { target } = listener ;
1179
- if ( isManagedDOMElement ( target ) ) {
1180
- detachListenerFromManagedDOMElement ( listener ) ;
1181
- } else if ( enableScopeAPI && isReactScope ( target ) ) {
1182
- detachListenerFromReactScope ( listener ) ;
1183
- } else {
1184
- detachTargetEventListener ( listener ) ;
1185
- }
1186
- }
1187
- }
1188
-
1189
- export function validateEventListenerTarget (
1190
- target : EventTarget | ReactScopeMethods ,
1191
- listener : ?( SyntheticEvent < EventTarget > ) => void ,
1192
- ) : boolean {
1193
- if ( enableUseEventAPI ) {
1194
- if (
1195
- target != null &&
1196
- ( isManagedDOMElement ( target ) ||
1197
- isValidEventTarget ( target ) ||
1198
- isReactScope ( target ) )
1199
- ) {
1200
- if ( listener == null || typeof listener === 'function' ) {
1201
- return true ;
1202
- }
1203
- if ( __DEV__ ) {
1204
- console . warn (
1205
- 'Event listener method setListener() from useEvent() hook requires the second argument' +
1206
- ' to be either a valid function callback or null/undefined.' ,
1207
- ) ;
1208
- }
1209
- }
1210
- if ( __DEV__ ) {
1211
- console . warn (
1212
- 'Event listener method setListener() from useEvent() hook requires the first argument to be ' +
1213
- 'a valid DOM EventTarget. If using a ref, ensure the current value is not null.' ,
1214
- ) ;
1215
- }
1216
- }
1217
- return false ;
1218
- }
0 commit comments