@samitouri / QOS-React-2 / commits / a210b5b440

Revert "Do not bind topLevelType to dispatch" (#13674)

* Revert "Do not bind topLevelType to dispatch (#13618)" This reverts commit 0c9c591bfb4c280d69bc9c1dd692ab0028bb0f8e.

Dan Abramov committed Sep 17, 2018 at 18:43 UTC a210b5b44016c086f83008cd03146d5acdacd12c
4 files changed +31 -23
packages/events/PluginModuleType.js
+1 -1
@@ -16,7 +16,7 @@ import type {TopLevelType} from './TopLevelEventTypes';
16
17 export type EventTypes = {[key: string]: DispatchConfig};
18
19 -export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
19 +export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;
20
21 export type PluginName = string;
22
packages/events/ReactGenericBatching.js
+4 -4
@@ -20,8 +20,8 @@ import {
20 let _batchedUpdatesImpl = function(fn, bookkeeping) {
21 return fn(bookkeeping);
22 };
23 -let _interactiveUpdatesImpl = function(fn, a) {
24 - return fn(a);
23 +let _interactiveUpdatesImpl = function(fn, a, b) {
24 + return fn(a, b);
25 };
26 let _flushInteractiveUpdatesImpl = function() {};
27
@@ -52,8 +52,8 @@ export function batchedUpdates(fn, bookkeeping) {
52 }
53 }
54
55 -export function interactiveUpdates(fn, a) {
56 - return _interactiveUpdatesImpl(fn, a);
55 +export function interactiveUpdates(fn, a, b) {
56 + return _interactiveUpdatesImpl(fn, a, b);
57 }
58
59 export function flushInteractiveUpdates() {
packages/react-dom/src/events/ReactDOMEventListener.js
+24 -14
@@ -21,7 +21,6 @@ import getEventTarget from './getEventTarget';
21 import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
22 import SimpleEventPlugin from './SimpleEventPlugin';
23 import {getRawEventName} from './DOMTopLevelEventTypes';
24 -import {unsafeCastStringToDOMTopLevelType} from 'events/TopLevelEventTypes';
24
25 const {isInteractiveTopLevelEventType} = SimpleEventPlugin;
26
@@ -49,6 +48,7 @@ function findRootContainerNode(inst) {
48
49 // Used to store ancestor hierarchy in top level callback
50 function getTopLevelCallbackBookKeeping(
51 + topLevelType,
52 nativeEvent,
53 targetInst,
54 ): {
@@ -57,9 +57,6 @@ function getTopLevelCallbackBookKeeping(
57 targetInst: Fiber | null,
58 ancestors: Array<Fiber>,
59 } {
60 - // This is safe because DOMTopLevelTypes are always native event type strings
61 - const topLevelType = unsafeCastStringToDOMTopLevelType(nativeEvent.type);
62 -
60 if (callbackBookkeepingPool.length) {
61 const instance = callbackBookkeepingPool.pop();
62 instance.topLevelType = topLevelType;
@@ -144,13 +141,16 @@ export function trapBubbledEvent(
141 if (!element) {
142 return null;
143 }
147 -
148 - // Check if interactive and wrap in interactiveUpdates
144 const dispatch = isInteractiveTopLevelEventType(topLevelType)
145 ? dispatchInteractiveEvent
146 : dispatchEvent;
147
153 - addEventBubbleListener(element, getRawEventName(topLevelType), dispatch);
148 + addEventBubbleListener(
149 + element,
150 + getRawEventName(topLevelType),
151 + // Check if interactive and wrap in interactiveUpdates
152 + dispatch.bind(null, topLevelType),
153 + );
154 }
155
156 /**
@@ -169,20 +169,26 @@ export function trapCapturedEvent(
169 if (!element) {
170 return null;
171 }
172 -
173 - // Check if interactive and wrap in interactiveUpdates
172 const dispatch = isInteractiveTopLevelEventType(topLevelType)
173 ? dispatchInteractiveEvent
174 : dispatchEvent;
175
178 - addEventCaptureListener(element, getRawEventName(topLevelType), dispatch);
176 + addEventCaptureListener(
177 + element,
178 + getRawEventName(topLevelType),
179 + // Check if interactive and wrap in interactiveUpdates
180 + dispatch.bind(null, topLevelType),
181 + );
182 }
183
181 -function dispatchInteractiveEvent(nativeEvent) {
182 - interactiveUpdates(dispatchEvent, nativeEvent);
184 +function dispatchInteractiveEvent(topLevelType, nativeEvent) {
185 + interactiveUpdates(dispatchEvent, topLevelType, nativeEvent);
186 }
187
185 -export function dispatchEvent(nativeEvent: AnyNativeEvent) {
188 +export function dispatchEvent(
189 + topLevelType: DOMTopLevelEventType,
190 + nativeEvent: AnyNativeEvent,
191 +) {
192 if (!_enabled) {
193 return;
194 }
@@ -201,7 +207,11 @@ export function dispatchEvent(nativeEvent: AnyNativeEvent) {
207 targetInst = null;
208 }
209
204 - const bookKeeping = getTopLevelCallbackBookKeeping(nativeEvent, targetInst);
210 + const bookKeeping = getTopLevelCallbackBookKeeping(
211 + topLevelType,
212 + nativeEvent,
213 + targetInst,
214 + );
215
216 try {
217 // Event queue being processed in the same cycle allows
packages/react-dom/src/test-utils/ReactTestUtils.js
+2 -4
@@ -42,9 +42,7 @@ const [
42 runEventsInBatch,
43 ] = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
44
45 -function Event(type) {
46 - this.type = type;
47 -}
45 +function Event(suffix) {}
46
47 let hasWarnedAboutDeprecatedMockComponent = false;
48
@@ -61,7 +59,7 @@ let hasWarnedAboutDeprecatedMockComponent = false;
59 */
60 function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) {
61 fakeNativeEvent.target = node;
64 - dispatchEvent(fakeNativeEvent);
62 + dispatchEvent(topLevelType, fakeNativeEvent);
63 }
64
65 /**