@samitouri / QOS-React / commits / 2decfe97dc

events: convert var to let/const (#11714)

Raphael Amorim committed Nov 30, 2017 at 10:07 UTC 2decfe97dc74b580f2b6e4b0af38c43708773cc6
14 files changed +244 -242
packages/events/EventPluginHub.js
+10 -10
@@ -30,7 +30,7 @@ import type {AnyNativeEvent} from './PluginModuleType';
30 * Internal queue of events that have accumulated their dispatches and are
31 * waiting to have their dispatches executed.
32 */
33 -var eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
33 +let eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
34
35 /**
36 * Dispatches an event and releases it back into the pool, unless persistent.
@@ -39,7 +39,7 @@ var eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
39 * @param {boolean} simulated If the event is simulated (changes exn behavior)
40 * @private
41 */
42 -var executeDispatchesAndRelease = function(
42 +const executeDispatchesAndRelease = function(
43 event: ReactSyntheticEvent,
44 simulated: boolean,
45 ) {
@@ -51,10 +51,10 @@ var executeDispatchesAndRelease = function(
51 }
52 }
53 };
54 -var executeDispatchesAndReleaseSimulated = function(e) {
54 +const executeDispatchesAndReleaseSimulated = function(e) {
55 return executeDispatchesAndRelease(e, true);
56 };
57 -var executeDispatchesAndReleaseTopLevel = function(e) {
57 +const executeDispatchesAndReleaseTopLevel = function(e) {
58 return executeDispatchesAndRelease(e, false);
59 };
60
@@ -130,7 +130,7 @@ export const injection = {
130 * @return {?function} The stored callback.
131 */
132 export function getListener(inst: Fiber, registrationName: string) {
133 - var listener;
133 + let listener;
134
135 // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
136 // live here; needs to be moved to a better place soon
@@ -170,12 +170,12 @@ export function extractEvents(
170 nativeEvent: AnyNativeEvent,
171 nativeEventTarget: EventTarget,
172 ) {
173 - var events;
174 - for (var i = 0; i < plugins.length; i++) {
173 + let events;
174 + for (let i = 0; i < plugins.length; i++) {
175 // Not every plugin in the ordering may be loaded at runtime.
176 - var possiblePlugin: PluginModule<AnyNativeEvent> = plugins[i];
176 + const possiblePlugin: PluginModule<AnyNativeEvent> = plugins[i];
177 if (possiblePlugin) {
178 - var extractedEvents = possiblePlugin.extractEvents(
178 + const extractedEvents = possiblePlugin.extractEvents(
179 topLevelType,
180 targetInst,
181 nativeEvent,
@@ -212,7 +212,7 @@ export function enqueueEvents(
212 export function processEventQueue(simulated: boolean) {
213 // Set `eventQueue` to null before processing it so that we can tell if more
214 // events get enqueued while processing.
215 - var processingEventQueue = eventQueue;
215 + const processingEventQueue = eventQueue;
216 eventQueue = null;
217
218 if (!processingEventQueue) {
packages/events/EventPluginRegistry.js
+15 -15
@@ -20,17 +20,17 @@ import lowPriorityWarning from 'shared/lowPriorityWarning';
20 type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>};
21 type EventPluginOrder = null | Array<PluginName>;
22
23 -var shouldWarnOnInjection = false;
23 +let shouldWarnOnInjection = false;
24
25 /**
26 * Injectable ordering of event plugins.
27 */
28 -var eventPluginOrder: EventPluginOrder = null;
28 +let eventPluginOrder: EventPluginOrder = null;
29
30 /**
31 * Injectable mapping from names to event plugin modules.
32 */
33 -var namesToPlugins: NamesToPlugins = {};
33 +const namesToPlugins: NamesToPlugins = {};
34
35 export function enableWarningOnInjection() {
36 shouldWarnOnInjection = true;
@@ -46,9 +46,9 @@ function recomputePluginOrdering(): void {
46 // Wait until an `eventPluginOrder` is injected.
47 return;
48 }
49 - for (var pluginName in namesToPlugins) {
50 - var pluginModule = namesToPlugins[pluginName];
51 - var pluginIndex = eventPluginOrder.indexOf(pluginName);
49 + for (const pluginName in namesToPlugins) {
50 + const pluginModule = namesToPlugins[pluginName];
51 + const pluginIndex = eventPluginOrder.indexOf(pluginName);
52 invariant(
53 pluginIndex > -1,
54 'EventPluginRegistry: Cannot inject event plugins that do not exist in ' +
@@ -65,8 +65,8 @@ function recomputePluginOrdering(): void {
65 pluginName,
66 );
67 plugins[pluginIndex] = pluginModule;
68 - var publishedEvents = pluginModule.eventTypes;
69 - for (var eventName in publishedEvents) {
68 + const publishedEvents = pluginModule.eventTypes;
69 + for (const eventName in publishedEvents) {
70 invariant(
71 publishEventForPlugin(
72 publishedEvents[eventName],
@@ -102,11 +102,11 @@ function publishEventForPlugin(
102 );
103 eventNameDispatchConfigs[eventName] = dispatchConfig;
104
105 - var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
105 + const phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
106 if (phasedRegistrationNames) {
107 - for (var phaseName in phasedRegistrationNames) {
107 + for (const phaseName in phasedRegistrationNames) {
108 if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
109 - var phasedRegistrationName = phasedRegistrationNames[phaseName];
109 + const phasedRegistrationName = phasedRegistrationNames[phaseName];
110 publishRegistrationName(
111 phasedRegistrationName,
112 pluginModule,
@@ -149,7 +149,7 @@ function publishRegistrationName(
149 pluginModule.eventTypes[eventName].dependencies;
150
151 if (__DEV__) {
152 - var lowerCasedName = registrationName.toLowerCase();
152 + const lowerCasedName = registrationName.toLowerCase();
153 possibleRegistrationNames[lowerCasedName] = registrationName;
154
155 if (registrationName === 'onDoubleClick') {
@@ -243,12 +243,12 @@ export function injectEventPluginsByName(
243 }
244 }
245
246 - var isOrderingDirty = false;
247 - for (var pluginName in injectedNamesToPlugins) {
246 + let isOrderingDirty = false;
247 + for (const pluginName in injectedNamesToPlugins) {
248 if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
249 continue;
250 }
251 - var pluginModule = injectedNamesToPlugins[pluginName];
251 + const pluginModule = injectedNamesToPlugins[pluginName];
252 if (
253 !namesToPlugins.hasOwnProperty(pluginName) ||
254 namesToPlugins[pluginName] !== pluginModule
packages/events/EventPluginUtils.js
+18 -18
@@ -45,19 +45,19 @@ export function isStartish(topLevelType) {
45 return topLevelType === 'topMouseDown' || topLevelType === 'topTouchStart';
46 }
47
48 -var validateEventDispatches;
48 +let validateEventDispatches;
49 if (__DEV__) {
50 validateEventDispatches = function(event) {
51 - var dispatchListeners = event._dispatchListeners;
52 - var dispatchInstances = event._dispatchInstances;
51 + const dispatchListeners = event._dispatchListeners;
52 + const dispatchInstances = event._dispatchInstances;
53
54 - var listenersIsArr = Array.isArray(dispatchListeners);
55 - var listenersLen = listenersIsArr
54 + const listenersIsArr = Array.isArray(dispatchListeners);
55 + const listenersLen = listenersIsArr
56 ? dispatchListeners.length
57 : dispatchListeners ? 1 : 0;
58
59 - var instancesIsArr = Array.isArray(dispatchInstances);
60 - var instancesLen = instancesIsArr
59 + const instancesIsArr = Array.isArray(dispatchInstances);
60 + const instancesLen = instancesIsArr
61 ? dispatchInstances.length
62 : dispatchInstances ? 1 : 0;
63
@@ -76,7 +76,7 @@ if (__DEV__) {
76 * @param {*} inst Internal component instance
77 */
78 function executeDispatch(event, simulated, listener, inst) {
79 - var type = event.type || 'unknown-event';
79 + const type = event.type || 'unknown-event';
80 event.currentTarget = getNodeFromInstance(inst);
81 ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError(
82 type,
@@ -91,13 +91,13 @@ function executeDispatch(event, simulated, listener, inst) {
91 * Standard/simple iteration through an event's collected dispatches.
92 */
93 export function executeDispatchesInOrder(event, simulated) {
94 - var dispatchListeners = event._dispatchListeners;
95 - var dispatchInstances = event._dispatchInstances;
94 + const dispatchListeners = event._dispatchListeners;
95 + const dispatchInstances = event._dispatchInstances;
96 if (__DEV__) {
97 validateEventDispatches(event);
98 }
99 if (Array.isArray(dispatchListeners)) {
100 - for (var i = 0; i < dispatchListeners.length; i++) {
100 + for (let i = 0; i < dispatchListeners.length; i++) {
101 if (event.isPropagationStopped()) {
102 break;
103 }
@@ -124,13 +124,13 @@ export function executeDispatchesInOrder(event, simulated) {
124 * true, or null if no listener returned true.
125 */
126 function executeDispatchesInOrderStopAtTrueImpl(event) {
127 - var dispatchListeners = event._dispatchListeners;
128 - var dispatchInstances = event._dispatchInstances;
127 + const dispatchListeners = event._dispatchListeners;
128 + const dispatchInstances = event._dispatchInstances;
129 if (__DEV__) {
130 validateEventDispatches(event);
131 }
132 if (Array.isArray(dispatchListeners)) {
133 - for (var i = 0; i < dispatchListeners.length; i++) {
133 + for (let i = 0; i < dispatchListeners.length; i++) {
134 if (event.isPropagationStopped()) {
135 break;
136 }
@@ -151,7 +151,7 @@ function executeDispatchesInOrderStopAtTrueImpl(event) {
151 * @see executeDispatchesInOrderStopAtTrueImpl
152 */
153 export function executeDispatchesInOrderStopAtTrue(event) {
154 - var ret = executeDispatchesInOrderStopAtTrueImpl(event);
154 + const ret = executeDispatchesInOrderStopAtTrueImpl(event);
155 event._dispatchInstances = null;
156 event._dispatchListeners = null;
157 return ret;
@@ -170,8 +170,8 @@ export function executeDirectDispatch(event) {
170 if (__DEV__) {
171 validateEventDispatches(event);
172 }
173 - var dispatchListener = event._dispatchListeners;
174 - var dispatchInstance = event._dispatchInstances;
173 + const dispatchListener = event._dispatchListeners;
174 + const dispatchInstance = event._dispatchInstances;
175 invariant(
176 !Array.isArray(dispatchListener),
177 'executeDirectDispatch(...): Invalid `event`.',
@@ -179,7 +179,7 @@ export function executeDirectDispatch(event) {
179 event.currentTarget = dispatchListener
180 ? getNodeFromInstance(dispatchInstance)
181 : null;
182 - var res = dispatchListener ? dispatchListener(event) : null;
182 + const res = dispatchListener ? dispatchListener(event) : null;
183 event.currentTarget = null;
184 event._dispatchListeners = null;
185 event._dispatchInstances = null;
packages/events/EventPropagators.js
+6 -6
@@ -23,7 +23,7 @@ type PropagationPhases = 'bubbled' | 'captured';
23 * "phases" of propagation. This finds listeners by a given phase.
24 */
25 function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
26 - var registrationName =
26 + const registrationName =
27 event.dispatchConfig.phasedRegistrationNames[propagationPhase];
28 return getListener(inst, registrationName);
29 }
@@ -48,7 +48,7 @@ function accumulateDirectionalDispatches(inst, phase, event) {
48 if (__DEV__) {
49 warning(inst, 'Dispatching inst must not be null');
50 }
51 - var listener = listenerAtPhase(inst, event, phase);
51 + const listener = listenerAtPhase(inst, event, phase);
52 if (listener) {
53 event._dispatchListeners = accumulateInto(
54 event._dispatchListeners,
@@ -76,8 +76,8 @@ function accumulateTwoPhaseDispatchesSingle(event) {
76 */
77 function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
78 if (event && event.dispatchConfig.phasedRegistrationNames) {
79 - var targetInst = event._targetInst;
80 - var parentInst = targetInst ? getParentInstance(targetInst) : null;
79 + const targetInst = event._targetInst;
80 + const parentInst = targetInst ? getParentInstance(targetInst) : null;
81 traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
82 }
83 }
@@ -89,8 +89,8 @@ function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
89 */
90 function accumulateDispatches(inst, ignoredDirection, event) {
91 if (inst && event && event.dispatchConfig.registrationName) {
92 - var registrationName = event.dispatchConfig.registrationName;
93 - var listener = getListener(inst, registrationName);
92 + const registrationName = event.dispatchConfig.registrationName;
93 + const listener = getListener(inst, registrationName);
94 if (listener) {
95 event._dispatchListeners = accumulateInto(
96 event._dispatchListeners,
packages/events/ReactControlledComponent.js
+8 -8
@@ -14,9 +14,9 @@ import {
14
15 // Use to restore controlled state after a change event has fired.
16
17 -var fiberHostComponent = null;
17 +let fiberHostComponent = null;
18
19 -var ReactControlledComponentInjection = {
19 +const ReactControlledComponentInjection = {
20 injectFiberControlledHostComponent: function(hostComponentImpl) {
21 // The fiber implementation doesn't use dynamic dispatch so we need to
22 // inject the implementation.
@@ -24,13 +24,13 @@ var ReactControlledComponentInjection = {
24 },
25 };
26
27 -var restoreTarget = null;
28 -var restoreQueue = null;
27 +let restoreTarget = null;
28 +let restoreQueue = null;
29
30 function restoreStateOfTarget(target) {
31 // We perform this translation at the end of the event loop so that we
32 // always receive the correct fiber here
33 - var internalInstance = getInstanceFromNode(target);
33 + const internalInstance = getInstanceFromNode(target);
34 if (!internalInstance) {
35 // Unmounted
36 return;
@@ -67,14 +67,14 @@ export function restoreStateIfNeeded() {
67 if (!restoreTarget) {
68 return;
69 }
70 - var target = restoreTarget;
71 - var queuedTargets = restoreQueue;
70 + const target = restoreTarget;
71 + const queuedTargets = restoreQueue;
72 restoreTarget = null;
73 restoreQueue = null;
74
75 restoreStateOfTarget(target);
76 if (queuedTargets) {
77 - for (var i = 0; i < queuedTargets.length; i++) {
77 + for (let i = 0; i < queuedTargets.length; i++) {
78 restoreStateOfTarget(queuedTargets[i]);
79 }
80 }
packages/events/ReactEventEmitterMixin.js
+1 -1
@@ -26,7 +26,7 @@ export function handleTopLevel(
26 nativeEvent,
27 nativeEventTarget,
28 ) {
29 - var events = extractEvents(
29 + const events = extractEvents(
30 topLevelType,
31 targetInst,
32 nativeEvent,
packages/events/ReactGenericBatching.js
+3 -3
@@ -14,11 +14,11 @@ import {restoreStateIfNeeded} from './ReactControlledComponent';
14 // scheduled work and instead do synchronous work.
15
16 // Defaults
17 -var fiberBatchedUpdates = function(fn, bookkeeping) {
17 +let fiberBatchedUpdates = function(fn, bookkeeping) {
18 return fn(bookkeeping);
19 };
20
21 -var isNestingBatched = false;
21 +let isNestingBatched = false;
22 export function batchedUpdates(fn, bookkeeping) {
23 if (isNestingBatched) {
24 // If we are currently inside another batch, we need to wait until it
@@ -39,7 +39,7 @@ export function batchedUpdates(fn, bookkeeping) {
39 }
40 }
41
42 -var ReactGenericBatchingInjection = {
42 +const ReactGenericBatchingInjection = {
43 injectFiberBatchedUpdates: function(_batchedUpdates) {
44 fiberBatchedUpdates = _batchedUpdates;
45 },
packages/events/ResponderEventPlugin.js
+35 -35
@@ -29,21 +29,21 @@ import accumulate from './accumulate';
29 * Instance of element that should respond to touch/move types of interactions,
30 * as indicated explicitly by relevant callbacks.
31 */
32 -var responderInst = null;
32 +let responderInst = null;
33
34 /**
35 * Count of current touches. A textInput should become responder iff the
36 * selection changes while there is a touch on the screen.
37 */
38 -var trackedTouchCount = 0;
38 +let trackedTouchCount = 0;
39
40 /**
41 * Last reported number of active touches.
42 */
43 -var previousActiveTouches = 0;
43 +let previousActiveTouches = 0;
44
45 -var changeResponder = function(nextResponderInst, blockHostResponder) {
46 - var oldResponderInst = responderInst;
45 +const changeResponder = function(nextResponderInst, blockHostResponder) {
46 + const oldResponderInst = responderInst;
47 responderInst = nextResponderInst;
48 if (ResponderEventPlugin.GlobalResponderHandler !== null) {
49 ResponderEventPlugin.GlobalResponderHandler.onChange(
@@ -54,7 +54,7 @@ var changeResponder = function(nextResponderInst, blockHostResponder) {
54 }
55 };
56
57 -var eventTypes = {
57 +const eventTypes = {
58 /**
59 * On a `touchStart`/`mouseDown`, is it desired that this element become the
60 * responder?
@@ -318,7 +318,7 @@ function setResponderAndExtractTransfer(
318 nativeEvent,
319 nativeEventTarget,
320 ) {
321 - var shouldSetEventType = isStartish(topLevelType)
321 + const shouldSetEventType = isStartish(topLevelType)
322 ? eventTypes.startShouldSetResponder
323 : isMoveish(topLevelType)
324 ? eventTypes.moveShouldSetResponder
@@ -327,7 +327,7 @@ function setResponderAndExtractTransfer(
327 : eventTypes.scrollShouldSetResponder;
328
329 // TODO: stop one short of the current responder.
330 - var bubbleShouldSetFrom = !responderInst
330 + const bubbleShouldSetFrom = !responderInst
331 ? targetInst
332 : getLowestCommonAncestor(responderInst, targetInst);
333
@@ -335,8 +335,8 @@ function setResponderAndExtractTransfer(
335 // (deepest ID) if it happens to be the current responder. The reasoning:
336 // It's strange to get an `onMoveShouldSetResponder` when you're *already*
337 // the responder.
338 - var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
339 - var shouldSetEvent = ResponderSyntheticEvent.getPooled(
338 + const skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
339 + const shouldSetEvent = ResponderSyntheticEvent.getPooled(
340 shouldSetEventType,
341 bubbleShouldSetFrom,
342 nativeEvent,
@@ -348,7 +348,7 @@ function setResponderAndExtractTransfer(
348 } else {
349 accumulateTwoPhaseDispatches(shouldSetEvent);
350 }
351 - var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
351 + const wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
352 if (!shouldSetEvent.isPersistent()) {
353 shouldSetEvent.constructor.release(shouldSetEvent);
354 }
@@ -356,8 +356,8 @@ function setResponderAndExtractTransfer(
356 if (!wantsResponderInst || wantsResponderInst === responderInst) {
357 return null;
358 }
359 - var extracted;
360 - var grantEvent = ResponderSyntheticEvent.getPooled(
359 + let extracted;
360 + const grantEvent = ResponderSyntheticEvent.getPooled(
361 eventTypes.responderGrant,
362 wantsResponderInst,
363 nativeEvent,
@@ -366,9 +366,9 @@ function setResponderAndExtractTransfer(
366 grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
367
368 accumulateDirectDispatches(grantEvent);
369 - var blockHostResponder = executeDirectDispatch(grantEvent) === true;
369 + const blockHostResponder = executeDirectDispatch(grantEvent) === true;
370 if (responderInst) {
371 - var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
371 + const terminationRequestEvent = ResponderSyntheticEvent.getPooled(
372 eventTypes.responderTerminationRequest,
373 responderInst,
374 nativeEvent,
@@ -377,7 +377,7 @@ function setResponderAndExtractTransfer(
377 terminationRequestEvent.touchHistory =
378 ResponderTouchHistoryStore.touchHistory;
379 accumulateDirectDispatches(terminationRequestEvent);
380 - var shouldSwitch =
380 + const shouldSwitch =
381 !hasDispatches(terminationRequestEvent) ||
382 executeDirectDispatch(terminationRequestEvent);
383 if (!terminationRequestEvent.isPersistent()) {
@@ -385,7 +385,7 @@ function setResponderAndExtractTransfer(
385 }
386
387 if (shouldSwitch) {
388 - var terminateEvent = ResponderSyntheticEvent.getPooled(
388 + const terminateEvent = ResponderSyntheticEvent.getPooled(
389 eventTypes.responderTerminate,
390 responderInst,
391 nativeEvent,
@@ -396,7 +396,7 @@ function setResponderAndExtractTransfer(
396 extracted = accumulate(extracted, [grantEvent, terminateEvent]);
397 changeResponder(wantsResponderInst, blockHostResponder);
398 } else {
399 - var rejectEvent = ResponderSyntheticEvent.getPooled(
399 + const rejectEvent = ResponderSyntheticEvent.getPooled(
400 eventTypes.responderReject,
401 wantsResponderInst,
402 nativeEvent,
@@ -442,16 +442,16 @@ function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
442 * @return {boolean} Whether or not this touch end event ends the responder.
443 */
444 function noResponderTouches(nativeEvent) {
445 - var touches = nativeEvent.touches;
445 + const touches = nativeEvent.touches;
446 if (!touches || touches.length === 0) {
447 return true;
448 }
449 - for (var i = 0; i < touches.length; i++) {
450 - var activeTouch = touches[i];
451 - var target = activeTouch.target;
449 + for (let i = 0; i < touches.length; i++) {
450 + const activeTouch = touches[i];
451 + const target = activeTouch.target;
452 if (target !== null && target !== undefined && target !== 0) {
453 // Is the original touch location inside of the current responder?
454 - var targetInst = getInstanceFromNode(target);
454 + const targetInst = getInstanceFromNode(target);
455 if (isAncestor(responderInst, targetInst)) {
456 return false;
457 }
@@ -460,7 +460,7 @@ function noResponderTouches(nativeEvent) {
460 return true;
461 }
462
463 -var ResponderEventPlugin = {
463 +const ResponderEventPlugin = {
464 /* For unit testing only */
465 _getResponder: function() {
466 return responderInst;
@@ -494,7 +494,7 @@ var ResponderEventPlugin = {
494
495 ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
496
497 - var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)
497 + let extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)
498 ? setResponderAndExtractTransfer(
499 topLevelType,
500 targetInst,
@@ -512,17 +512,17 @@ var ResponderEventPlugin = {
512 // These multiple individual change touch events are are always bookended
513 // by `onResponderGrant`, and one of
514 // (`onResponderRelease/onResponderTerminate`).
515 - var isResponderTouchStart = responderInst && isStartish(topLevelType);
516 - var isResponderTouchMove = responderInst && isMoveish(topLevelType);
517 - var isResponderTouchEnd = responderInst && isEndish(topLevelType);
518 - var incrementalTouch = isResponderTouchStart
515 + const isResponderTouchStart = responderInst && isStartish(topLevelType);
516 + const isResponderTouchMove = responderInst && isMoveish(topLevelType);
517 + const isResponderTouchEnd = responderInst && isEndish(topLevelType);
518 + const incrementalTouch = isResponderTouchStart
519 ? eventTypes.responderStart
520 : isResponderTouchMove
521 ? eventTypes.responderMove
522 : isResponderTouchEnd ? eventTypes.responderEnd : null;
523
524 if (incrementalTouch) {
525 - var gesture = ResponderSyntheticEvent.getPooled(
525 + const gesture = ResponderSyntheticEvent.getPooled(
526 incrementalTouch,
527 responderInst,
528 nativeEvent,
@@ -533,18 +533,18 @@ var ResponderEventPlugin = {
533 extracted = accumulate(extracted, gesture);
534 }
535
536 - var isResponderTerminate =
536 + const isResponderTerminate =
537 responderInst && topLevelType === 'topTouchCancel';
538 - var isResponderRelease =
538 + const isResponderRelease =
539 responderInst &&
540 !isResponderTerminate &&
541 isEndish(topLevelType) &&
542 noResponderTouches(nativeEvent);
543 - var finalTouch = isResponderTerminate
543 + const finalTouch = isResponderTerminate
544 ? eventTypes.responderTerminate
545 : isResponderRelease ? eventTypes.responderRelease : null;
546 if (finalTouch) {
547 - var finalEvent = ResponderSyntheticEvent.getPooled(
547 + const finalEvent = ResponderSyntheticEvent.getPooled(
548 finalTouch,
549 responderInst,
550 nativeEvent,
@@ -556,7 +556,7 @@ var ResponderEventPlugin = {
556 changeResponder(null);
557 }
558
559 - var numberActiveTouches =
559 + const numberActiveTouches =
560 ResponderTouchHistoryStore.touchHistory.numberActiveTouches;
561 if (
562 ResponderEventPlugin.GlobalInteractionHandler &&
packages/events/ResponderSyntheticEvent.js
+1 -1
@@ -12,7 +12,7 @@ import SyntheticEvent from './SyntheticEvent';
12 * interface will ensure that it is cleaned up when pooled/destroyed. The
13 * `ResponderEventPlugin` will populate it appropriately.
14 */
15 -var ResponderEventInterface = {
15 +const ResponderEventInterface = {
16 touchHistory: function(nativeEvent) {
17 return null; // Actually doesn't even look at the native event.
18 },
packages/events/SyntheticEvent.js
+25 -23
@@ -11,11 +11,11 @@ import emptyFunction from 'fbjs/lib/emptyFunction';
11 import invariant from 'fbjs/lib/invariant';
12 import warning from 'fbjs/lib/warning';
13
14 -var didWarnForAddedNewProperty = false;
15 -var isProxySupported = typeof Proxy === 'function';
16 -var EVENT_POOL_SIZE = 10;
14 +let didWarnForAddedNewProperty = false;
15 +const isProxySupported = typeof Proxy === 'function';
16 +const EVENT_POOL_SIZE = 10;
17
18 -var shouldBeReleasedProperties = [
18 +const shouldBeReleasedProperties = [
19 'dispatchConfig',
20 '_targetInst',
21 'nativeEvent',
@@ -29,7 +29,7 @@ var shouldBeReleasedProperties = [
29 * @interface Event
30 * @see http://www.w3.org/TR/DOM-Level-3-Events/
31 */
32 -var EventInterface = {
32 +const EventInterface = {
33 type: null,
34 target: null,
35 // currentTarget is set when dispatching; no use in copying it here
@@ -79,15 +79,15 @@ function SyntheticEvent(
79 this._targetInst = targetInst;
80 this.nativeEvent = nativeEvent;
81
82 - var Interface = this.constructor.Interface;
83 - for (var propName in Interface) {
82 + const Interface = this.constructor.Interface;
83 + for (const propName in Interface) {
84 if (!Interface.hasOwnProperty(propName)) {
85 continue;
86 }
87 if (__DEV__) {
88 delete this[propName]; // this has a getter/setter for warnings
89 }
90 - var normalize = Interface[propName];
90 + const normalize = Interface[propName];
91 if (normalize) {
92 this[propName] = normalize(nativeEvent);
93 } else {
@@ -99,7 +99,7 @@ function SyntheticEvent(
99 }
100 }
101
102 - var defaultPrevented =
102 + const defaultPrevented =
103 nativeEvent.defaultPrevented != null
104 ? nativeEvent.defaultPrevented
105 : nativeEvent.returnValue === false;
@@ -115,7 +115,7 @@ function SyntheticEvent(
115 Object.assign(SyntheticEvent.prototype, {
116 preventDefault: function() {
117 this.defaultPrevented = true;
118 - var event = this.nativeEvent;
118 + const event = this.nativeEvent;
119 if (!event) {
120 return;
121 }
@@ -129,7 +129,7 @@ Object.assign(SyntheticEvent.prototype, {
129 },
130
131 stopPropagation: function() {
132 - var event = this.nativeEvent;
132 + const event = this.nativeEvent;
133 if (!event) {
134 return;
135 }
@@ -168,8 +168,8 @@ Object.assign(SyntheticEvent.prototype, {
168 * `PooledClass` looks for `destructor` on each instance it releases.
169 */
170 destructor: function() {
171 - var Interface = this.constructor.Interface;
172 - for (var propName in Interface) {
171 + const Interface = this.constructor.Interface;
172 + for (const propName in Interface) {
173 if (__DEV__) {
174 Object.defineProperty(
175 this,
@@ -180,7 +180,7 @@ Object.assign(SyntheticEvent.prototype, {
180 this[propName] = null;
181 }
182 }
183 - for (var i = 0; i < shouldBeReleasedProperties.length; i++) {
183 + for (let i = 0; i < shouldBeReleasedProperties.length; i++) {
184 this[shouldBeReleasedProperties[i]] = null;
185 }
186 if (__DEV__) {
@@ -212,11 +212,11 @@ SyntheticEvent.Interface = EventInterface;
212 * @param {?object} Interface
213 */
214 SyntheticEvent.augmentClass = function(Class, Interface) {
215 - var Super = this;
215 + const Super = this;
216
217 - var E = function() {};
217 + const E = function() {};
218 E.prototype = Super.prototype;
219 - var prototype = new E();
219 + const prototype = new E();
220
221 Object.assign(prototype, Class.prototype);
222 Class.prototype = prototype;
@@ -275,7 +275,7 @@ addEventPoolingTo(SyntheticEvent);
275 * @return {object} defineProperty object
276 */
277 function getPooledWarningPropertyDefinition(propName, getVal) {
278 - var isFunction = typeof getVal === 'function';
278 + const isFunction = typeof getVal === 'function';
279 return {
280 configurable: true,
281 set: set,
@@ -283,14 +283,16 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
283 };
284
285 function set(val) {
286 - var action = isFunction ? 'setting the method' : 'setting the property';
286 + const action = isFunction ? 'setting the method' : 'setting the property';
287 warn(action, 'This is effectively a no-op');
288 return val;
289 }
290
291 function get() {
292 - var action = isFunction ? 'accessing the method' : 'accessing the property';
293 - var result = isFunction
292 + const action = isFunction
293 + ? 'accessing the method'
294 + : 'accessing the property';
295 + const result = isFunction
296 ? 'This is a no-op function'
297 : 'This is set to null';
298 warn(action, result);
@@ -298,7 +300,7 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
300 }
301
302 function warn(action, result) {
301 - var warningCondition = false;
303 + const warningCondition = false;
304 warning(
305 warningCondition,
306 "This synthetic event is reused for performance reasons. If you're seeing this, " +
@@ -334,7 +336,7 @@ function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
336 }
337
338 function releasePooledEvent(event) {
337 - var EventConstructor = this;
339 + const EventConstructor = this;
340 invariant(
341 event instanceof EventConstructor,
342 'Trying to release an event instance into a pool of a different type.',
packages/events/TouchHistoryMath.js
+8 -8
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -var TouchHistoryMath = {
8 +const TouchHistoryMath = {
9 /**
10 * This code is optimized and not intended to look beautiful. This allows
11 * computing of touch centroids that have moved after `touchesChangedAfter`
@@ -28,11 +28,11 @@ var TouchHistoryMath = {
28 isXAxis,
29 ofCurrent,
30 ) {
31 - var touchBank = touchHistory.touchBank;
32 - var total = 0;
33 - var count = 0;
31 + const touchBank = touchHistory.touchBank;
32 + let total = 0;
33 + let count = 0;
34
35 - var oneTouchData =
35 + const oneTouchData =
36 touchHistory.numberActiveTouches === 1
37 ? touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch]
38 : null;
@@ -53,15 +53,15 @@ var TouchHistoryMath = {
53 count = 1;
54 }
55 } else {
56 - for (var i = 0; i < touchBank.length; i++) {
57 - var touchTrack = touchBank[i];
56 + for (let i = 0; i < touchBank.length; i++) {
57 + const touchTrack = touchBank[i];
58 if (
59 touchTrack !== null &&
60 touchTrack !== undefined &&
61 touchTrack.touchActive &&
62 touchTrack.currentTimeStamp >= touchesChangedAfter
63 ) {
64 - var toAdd; // Yuck, program temporarily in invalid state.
64 + let toAdd; // Yuck, program temporarily in invalid state.
65 if (ofCurrent && isXAxis) {
66 toAdd = touchTrack.currentPageX;
67 } else if (ofCurrent && !isXAxis) {
packages/events/__tests__/EventPluginRegistry-test.internal.js
+22 -22
@@ -10,8 +10,8 @@
10 'use strict';
11
12 describe('EventPluginRegistry', () => {
13 - var EventPluginRegistry;
14 - var createPlugin;
13 + let EventPluginRegistry;
14 + let createPlugin;
15
16 beforeEach(() => {
17 jest.resetModuleRegistry();
@@ -27,9 +27,9 @@ describe('EventPluginRegistry', () => {
27 });
28
29 it('should be able to inject ordering before plugins', () => {
30 - var OnePlugin = createPlugin();
31 - var TwoPlugin = createPlugin();
32 - var ThreePlugin = createPlugin();
30 + const OnePlugin = createPlugin();
31 + const TwoPlugin = createPlugin();
32 + const ThreePlugin = createPlugin();
33
34 EventPluginRegistry.injectEventPluginOrder(['one', 'two', 'three']);
35 EventPluginRegistry.injectEventPluginsByName({
@@ -47,9 +47,9 @@ describe('EventPluginRegistry', () => {
47 });
48
49 it('should be able to inject plugins before and after ordering', () => {
50 - var OnePlugin = createPlugin();
51 - var TwoPlugin = createPlugin();
52 - var ThreePlugin = createPlugin();
50 + const OnePlugin = createPlugin();
51 + const TwoPlugin = createPlugin();
52 + const ThreePlugin = createPlugin();
53
54 EventPluginRegistry.injectEventPluginsByName({
55 one: OnePlugin,
@@ -67,9 +67,9 @@ describe('EventPluginRegistry', () => {
67 });
68
69 it('should be able to inject repeated plugins and out-of-order', () => {
70 - var OnePlugin = createPlugin();
71 - var TwoPlugin = createPlugin();
72 - var ThreePlugin = createPlugin();
70 + const OnePlugin = createPlugin();
71 + const TwoPlugin = createPlugin();
72 + const ThreePlugin = createPlugin();
73
74 EventPluginRegistry.injectEventPluginsByName({
75 one: OnePlugin,
@@ -88,7 +88,7 @@ describe('EventPluginRegistry', () => {
88 });
89
90 it('should throw if plugin does not implement `extractEvents`', () => {
91 - var BadPlugin = {};
91 + const BadPlugin = {};
92
93 EventPluginRegistry.injectEventPluginOrder(['bad']);
94
@@ -103,8 +103,8 @@ describe('EventPluginRegistry', () => {
103 });
104
105 it('should throw if plugin does not exist in ordering', () => {
106 - var OnePlugin = createPlugin();
107 - var RandomPlugin = createPlugin();
106 + const OnePlugin = createPlugin();
107 + const RandomPlugin = createPlugin();
108
109 EventPluginRegistry.injectEventPluginOrder(['one']);
110
@@ -120,7 +120,7 @@ describe('EventPluginRegistry', () => {
120 });
121
122 it('should throw if ordering is injected more than once', () => {
123 - var pluginOrdering = [];
123 + const pluginOrdering = [];
124
125 EventPluginRegistry.injectEventPluginOrder(pluginOrdering);
126
@@ -133,8 +133,8 @@ describe('EventPluginRegistry', () => {
133 });
134
135 it('should throw if different plugins injected using same name', () => {
136 - var OnePlugin = createPlugin();
137 - var TwoPlugin = createPlugin();
136 + const OnePlugin = createPlugin();
137 + const TwoPlugin = createPlugin();
138
139 EventPluginRegistry.injectEventPluginsByName({same: OnePlugin});
140
@@ -147,13 +147,13 @@ describe('EventPluginRegistry', () => {
147 });
148
149 it('should publish registration names of injected plugins', () => {
150 - var OnePlugin = createPlugin({
150 + const OnePlugin = createPlugin({
151 eventTypes: {
152 click: {registrationName: 'onClick'},
153 focus: {registrationName: 'onFocus'},
154 },
155 });
156 - var TwoPlugin = createPlugin({
156 + const TwoPlugin = createPlugin({
157 eventTypes: {
158 magic: {
159 phasedRegistrationNames: {
@@ -187,12 +187,12 @@ describe('EventPluginRegistry', () => {
187 });
188
189 it('should throw if multiple registration names collide', () => {
190 - var OnePlugin = createPlugin({
190 + const OnePlugin = createPlugin({
191 eventTypes: {
192 photoCapture: {registrationName: 'onPhotoCapture'},
193 },
194 });
195 - var TwoPlugin = createPlugin({
195 + const TwoPlugin = createPlugin({
196 eventTypes: {
197 photo: {
198 phasedRegistrationNames: {
@@ -217,7 +217,7 @@ describe('EventPluginRegistry', () => {
217 });
218
219 it('should throw if an invalid event is published', () => {
220 - var OnePlugin = createPlugin({
220 + const OnePlugin = createPlugin({
221 eventTypes: {
222 badEvent: {
223 /* missing configuration */
packages/events/__tests__/ResponderEventPlugin-test.internal.js
+86 -86
@@ -9,12 +9,12 @@
9
10 'use strict';
11
12 -var {HostComponent} = require('shared/ReactTypeOfWork');
12 +const {HostComponent} = require('shared/ReactTypeOfWork');
13
14 -var EventPluginHub;
15 -var ResponderEventPlugin;
14 +let EventPluginHub;
15 +let ResponderEventPlugin;
16
17 -var touch = function(nodeHandle, i) {
17 +const touch = function(nodeHandle, i) {
18 return {target: nodeHandle, identifier: i};
19 };
20
@@ -25,7 +25,7 @@ var touch = function(nodeHandle, i) {
25 * @return {TouchEvent} Model of a touch event that is compliant with responder
26 * system plugin.
27 */
28 -var touchEvent = function(nodeHandle, touches, changedTouches) {
28 +const touchEvent = function(nodeHandle, touches, changedTouches) {
29 return {
30 target: nodeHandle,
31 changedTouches: changedTouches,
@@ -33,18 +33,18 @@ var touchEvent = function(nodeHandle, touches, changedTouches) {
33 };
34 };
35
36 -var subsequence = function(arr, indices) {
37 - var ret = [];
38 - for (var i = 0; i < indices.length; i++) {
39 - var index = indices[i];
36 +const subsequence = function(arr, indices) {
37 + const ret = [];
38 + for (let i = 0; i < indices.length; i++) {
39 + const index = indices[i];
40 ret.push(arr[index]);
41 }
42 return ret;
43 };
44
45 -var antiSubsequence = function(arr, indices) {
46 - var ret = [];
47 - for (var i = 0; i < arr.length; i++) {
45 +const antiSubsequence = function(arr, indices) {
46 + const ret = [];
47 + for (let i = 0; i < arr.length; i++) {
48 if (indices.indexOf(i) === -1) {
49 ret.push(arr[i]);
50 }
@@ -56,16 +56,16 @@ var antiSubsequence = function(arr, indices) {
56 * Helper for creating touch test config data.
57 * @param allTouchHandles
58 */
59 -var _touchConfig = function(
59 +const _touchConfig = function(
60 topType,
61 targetNodeHandle,
62 allTouchHandles,
63 changedIndices,
64 eventTarget,
65 ) {
66 - var allTouchObjects = allTouchHandles.map(touch);
67 - var changedTouchObjects = subsequence(allTouchObjects, changedIndices);
68 - var activeTouchObjects = topType === 'topTouchStart'
66 + const allTouchObjects = allTouchHandles.map(touch);
67 + const changedTouchObjects = subsequence(allTouchObjects, changedIndices);
68 + const activeTouchObjects = topType === 'topTouchStart'
69 ? allTouchObjects
70 : topType === 'topTouchMove'
71 ? allTouchObjects
@@ -104,7 +104,7 @@ var _touchConfig = function(
104 * @return {object} Config data used by test cases for extracting responder
105 * events.
106 */
107 -var startConfig = function(nodeHandle, allTouchHandles, changedIndices) {
107 +const startConfig = function(nodeHandle, allTouchHandles, changedIndices) {
108 return _touchConfig(
109 'topTouchStart',
110 nodeHandle,
@@ -117,7 +117,7 @@ var startConfig = function(nodeHandle, allTouchHandles, changedIndices) {
117 /**
118 * @see `startConfig`
119 */
120 -var moveConfig = function(nodeHandle, allTouchHandles, changedIndices) {
120 +const moveConfig = function(nodeHandle, allTouchHandles, changedIndices) {
121 return _touchConfig(
122 'topTouchMove',
123 nodeHandle,
@@ -130,7 +130,7 @@ var moveConfig = function(nodeHandle, allTouchHandles, changedIndices) {
130 /**
131 * @see `startConfig`
132 */
133 -var endConfig = function(nodeHandle, allTouchHandles, changedIndices) {
133 +const endConfig = function(nodeHandle, allTouchHandles, changedIndices) {
134 return _touchConfig(
135 'topTouchEnd',
136 nodeHandle,
@@ -167,9 +167,9 @@ var endConfig = function(nodeHandle, allTouchHandles, changedIndices) {
167 * ever invoked).
168 *
169 */
170 -var NA = -1;
171 -var oneEventLoopTestConfig = function(readableIDToID) {
172 - var ret = {
170 +const NA = -1;
171 +const oneEventLoopTestConfig = function(readableIDToID) {
172 + const ret = {
173 // Negotiation
174 scrollShouldSetResponder: {bubbled: {}, captured: {}},
175 startShouldSetResponder: {bubbled: {}, captured: {}},
@@ -185,8 +185,8 @@ var oneEventLoopTestConfig = function(readableIDToID) {
185 responderEnd: {},
186 responderRelease: {},
187 };
188 - for (var eventName in ret) {
189 - for (var readableNodeName in readableIDToID) {
188 + for (const eventName in ret) {
189 + for (const readableNodeName in readableIDToID) {
190 if (ret[eventName].bubbled) {
191 // Two phase
192 ret[eventName].bubbled[readableNodeName] = {
@@ -215,9 +215,9 @@ var oneEventLoopTestConfig = function(readableIDToID) {
215 * @param {object} eventTestConfig
216 * @param {object} readableIDToID
217 */
218 -var registerTestHandlers = function(eventTestConfig, readableIDToID) {
219 - var runs = {dispatchCount: 0};
220 - var neverFire = function(readableID, registrationName) {
218 +const registerTestHandlers = function(eventTestConfig, readableIDToID) {
219 + const runs = {dispatchCount: 0};
220 + const neverFire = function(readableID, registrationName) {
221 runs.dispatchCount++;
222 expect('').toBe(
223 'Event type: ' +
@@ -230,11 +230,11 @@ var registerTestHandlers = function(eventTestConfig, readableIDToID) {
230 );
231 };
232
233 - var registerOneEventType = function(registrationName, eventTypeTestConfig) {
234 - for (var readableID in eventTypeTestConfig) {
235 - var nodeConfig = eventTypeTestConfig[readableID];
236 - var id = readableIDToID[readableID];
237 - var handler = nodeConfig.order === NA
233 + const registerOneEventType = function(registrationName, eventTypeTestConfig) {
234 + for (const readableID in eventTypeTestConfig) {
235 + const nodeConfig = eventTypeTestConfig[readableID];
236 + const id = readableIDToID[readableID];
237 + const handler = nodeConfig.order === NA
238 ? neverFire.bind(null, readableID, registrationName)
239 : // We partially apply readableID and nodeConfig, as they change in the
240 // parent closure across iterations.
@@ -250,9 +250,9 @@ var registerTestHandlers = function(eventTestConfig, readableIDToID) {
250 putListener(getInstanceFromNode(id), registrationName, handler);
251 }
252 };
253 - for (var eventName in eventTestConfig) {
254 - var oneEventTypeTestConfig = eventTestConfig[eventName];
255 - var hasTwoPhase = !!oneEventTypeTestConfig.bubbled;
253 + for (const eventName in eventTestConfig) {
254 + const oneEventTypeTestConfig = eventTestConfig[eventName];
255 + const hasTwoPhase = !!oneEventTypeTestConfig.bubbled;
256 if (hasTwoPhase) {
257 registerOneEventType(
258 ResponderEventPlugin.eventTypes[eventName].phasedRegistrationNames
@@ -274,16 +274,16 @@ var registerTestHandlers = function(eventTestConfig, readableIDToID) {
274 return runs;
275 };
276
277 -var run = function(config, hierarchyConfig, nativeEventConfig) {
278 - var max = NA;
279 - var searchForMax = function(nodeConfig) {
280 - for (var readableID in nodeConfig) {
281 - var order = nodeConfig[readableID].order;
277 +const run = function(config, hierarchyConfig, nativeEventConfig) {
278 + let max = NA;
279 + const searchForMax = function(nodeConfig) {
280 + for (const readableID in nodeConfig) {
281 + const order = nodeConfig[readableID].order;
282 max = order > max ? order : max;
283 }
284 };
285 - for (var eventName in config) {
286 - var eventConfig = config[eventName];
285 + for (const eventName in config) {
286 + const eventConfig = config[eventName];
287 if (eventConfig.bubbled) {
288 searchForMax(eventConfig.bubbled);
289 searchForMax(eventConfig.captured);
@@ -293,10 +293,10 @@ var run = function(config, hierarchyConfig, nativeEventConfig) {
293 }
294
295 // Register the handlers
296 - var runData = registerTestHandlers(config, hierarchyConfig);
296 + const runData = registerTestHandlers(config, hierarchyConfig);
297
298 // Trigger the event
299 - var extractedEvents = ResponderEventPlugin.extractEvents(
299 + const extractedEvents = ResponderEventPlugin.extractEvents(
300 nativeEventConfig.topLevelType,
301 nativeEventConfig.targetInst,
302 nativeEventConfig.nativeEvent,
@@ -315,32 +315,32 @@ var run = function(config, hierarchyConfig, nativeEventConfig) {
315 ); // +1 for extra ++
316 };
317
318 -var GRANDPARENT_HOST_NODE = {};
319 -var PARENT_HOST_NODE = {};
320 -var CHILD_HOST_NODE = {};
321 -var CHILD_HOST_NODE2 = {};
318 +const GRANDPARENT_HOST_NODE = {};
319 +const PARENT_HOST_NODE = {};
320 +const CHILD_HOST_NODE = {};
321 +const CHILD_HOST_NODE2 = {};
322
323 // These intentionally look like Fibers. ReactTreeTraversal depends on their field names.
324 // TODO: we could test this with regular DOM nodes (and real fibers) instead.
325 -var GRANDPARENT_INST = {
325 +const GRANDPARENT_INST = {
326 return: null,
327 tag: HostComponent,
328 stateNode: GRANDPARENT_HOST_NODE,
329 memoizedProps: {},
330 };
331 -var PARENT_INST = {
331 +const PARENT_INST = {
332 return: GRANDPARENT_INST,
333 tag: HostComponent,
334 stateNode: PARENT_HOST_NODE,
335 memoizedProps: {},
336 };
337 -var CHILD_INST = {
337 +const CHILD_INST = {
338 return: PARENT_INST,
339 tag: HostComponent,
340 stateNode: CHILD_HOST_NODE,
341 memoizedProps: {},
342 };
343 -var CHILD_INST2 = {
343 +const CHILD_INST2 = {
344 return: PARENT_INST,
345 tag: HostComponent,
346 stateNode: CHILD_HOST_NODE2,
@@ -352,13 +352,13 @@ PARENT_HOST_NODE.testInstance = PARENT_INST;
352 CHILD_HOST_NODE.testInstance = CHILD_INST;
353 CHILD_HOST_NODE2.testInstance = CHILD_INST2;
354
355 -var three = {
355 +const three = {
356 grandParent: GRANDPARENT_HOST_NODE,
357 parent: PARENT_HOST_NODE,
358 child: CHILD_HOST_NODE,
359 };
360
361 -var siblings = {
361 +const siblings = {
362 parent: PARENT_HOST_NODE,
363 childOne: CHILD_HOST_NODE,
364 childTwo: CHILD_HOST_NODE2,
@@ -411,7 +411,7 @@ describe('ResponderEventPlugin', () => {
411 });
412
413 it('should do nothing when no one wants to respond', () => {
414 - var config = oneEventLoopTestConfig(three);
414 + let config = oneEventLoopTestConfig(three);
415 config.startShouldSetResponder.captured.grandParent = {
416 order: 0,
417 returnVal: false,
@@ -448,7 +448,7 @@ describe('ResponderEventPlugin', () => {
448 */
449
450 it('should grant responder grandParent while capturing', () => {
451 - var config = oneEventLoopTestConfig(three);
451 + let config = oneEventLoopTestConfig(three);
452 config.startShouldSetResponder.captured.grandParent = {
453 order: 0,
454 returnVal: true,
@@ -468,7 +468,7 @@ describe('ResponderEventPlugin', () => {
468 });
469
470 it('should grant responder parent while capturing', () => {
471 - var config = oneEventLoopTestConfig(three);
471 + let config = oneEventLoopTestConfig(three);
472 config.startShouldSetResponder.captured.grandParent = {
473 order: 0,
474 returnVal: false,
@@ -492,7 +492,7 @@ describe('ResponderEventPlugin', () => {
492 });
493
494 it('should grant responder child while capturing', () => {
495 - var config = oneEventLoopTestConfig(three);
495 + let config = oneEventLoopTestConfig(three);
496 config.startShouldSetResponder.captured.grandParent = {
497 order: 0,
498 returnVal: false,
@@ -517,7 +517,7 @@ describe('ResponderEventPlugin', () => {
517 });
518
519 it('should grant responder child while bubbling', () => {
520 - var config = oneEventLoopTestConfig(three);
520 + let config = oneEventLoopTestConfig(three);
521 config.startShouldSetResponder.captured.grandParent = {
522 order: 0,
523 returnVal: false,
@@ -546,7 +546,7 @@ describe('ResponderEventPlugin', () => {
546 });
547
548 it('should grant responder parent while bubbling', () => {
549 - var config = oneEventLoopTestConfig(three);
549 + let config = oneEventLoopTestConfig(three);
550 config.startShouldSetResponder.captured.grandParent = {
551 order: 0,
552 returnVal: false,
@@ -576,7 +576,7 @@ describe('ResponderEventPlugin', () => {
576 });
577
578 it('should grant responder grandParent while bubbling', () => {
579 - var config = oneEventLoopTestConfig(three);
579 + let config = oneEventLoopTestConfig(three);
580 config.startShouldSetResponder.captured.grandParent = {
581 order: 0,
582 returnVal: false,
@@ -618,7 +618,7 @@ describe('ResponderEventPlugin', () => {
618 */
619
620 it('should grant responder grandParent while capturing move', () => {
621 - var config = oneEventLoopTestConfig(three);
621 + let config = oneEventLoopTestConfig(three);
622
623 config.startShouldSetResponder.captured.grandParent = {order: 0};
624 config.startShouldSetResponder.captured.parent = {order: 1};
@@ -648,7 +648,7 @@ describe('ResponderEventPlugin', () => {
648 });
649
650 it('should grant responder parent while capturing move', () => {
651 - var config = oneEventLoopTestConfig(three);
651 + let config = oneEventLoopTestConfig(three);
652
653 config.startShouldSetResponder.captured.grandParent = {order: 0};
654 config.startShouldSetResponder.captured.parent = {order: 1};
@@ -679,7 +679,7 @@ describe('ResponderEventPlugin', () => {
679 });
680
681 it('should grant responder child while capturing move', () => {
682 - var config = oneEventLoopTestConfig(three);
682 + let config = oneEventLoopTestConfig(three);
683
684 config.startShouldSetResponder.captured.grandParent = {order: 0};
685 config.startShouldSetResponder.captured.parent = {order: 1};
@@ -714,7 +714,7 @@ describe('ResponderEventPlugin', () => {
714 });
715
716 it('should grant responder child while bubbling move', () => {
717 - var config = oneEventLoopTestConfig(three);
717 + let config = oneEventLoopTestConfig(three);
718
719 config.startShouldSetResponder.captured.grandParent = {order: 0};
720 config.startShouldSetResponder.captured.parent = {order: 1};
@@ -750,7 +750,7 @@ describe('ResponderEventPlugin', () => {
750 });
751
752 it('should grant responder parent while bubbling move', () => {
753 - var config = oneEventLoopTestConfig(three);
753 + let config = oneEventLoopTestConfig(three);
754
755 config.startShouldSetResponder.captured.grandParent = {order: 0};
756 config.startShouldSetResponder.captured.parent = {order: 1};
@@ -787,7 +787,7 @@ describe('ResponderEventPlugin', () => {
787 });
788
789 it('should grant responder grandParent while bubbling move', () => {
790 - var config = oneEventLoopTestConfig(three);
790 + let config = oneEventLoopTestConfig(three);
791
792 config.startShouldSetResponder.captured.grandParent = {order: 0};
793 config.startShouldSetResponder.captured.parent = {order: 1};
@@ -833,7 +833,7 @@ describe('ResponderEventPlugin', () => {
833 */
834
835 it('should bubble negotiation to first common ancestor of responder', () => {
836 - var config = oneEventLoopTestConfig(three);
836 + let config = oneEventLoopTestConfig(three);
837 config.startShouldSetResponder.captured.grandParent = {
838 order: 0,
839 returnVal: false,
@@ -875,7 +875,7 @@ describe('ResponderEventPlugin', () => {
875 });
876
877 it('should bubble negotiation to first common ancestor of responder then transfer', () => {
878 - var config = oneEventLoopTestConfig(three);
878 + let config = oneEventLoopTestConfig(three);
879 config.startShouldSetResponder.captured.grandParent = {
880 order: 0,
881 returnVal: false,
@@ -932,7 +932,7 @@ describe('ResponderEventPlugin', () => {
932 */
933 it('should negotiate with deepest target on second touch if nothing is responder', () => {
934 // Initially nothing wants to become the responder
935 - var config = oneEventLoopTestConfig(three);
935 + let config = oneEventLoopTestConfig(three);
936 config.startShouldSetResponder.captured.grandParent = {
937 order: 0,
938 returnVal: false,
@@ -1080,7 +1080,7 @@ describe('ResponderEventPlugin', () => {
1080 */
1081 it('should negotiate until first common ancestor when there are siblings', () => {
1082 // Initially nothing wants to become the responder
1083 - var config = oneEventLoopTestConfig(siblings);
1083 + let config = oneEventLoopTestConfig(siblings);
1084 config.startShouldSetResponder.captured.parent = {
1085 order: 0,
1086 returnVal: false,
@@ -1119,7 +1119,7 @@ describe('ResponderEventPlugin', () => {
1119 };
1120 config.responderStart.childOne = {order: 2};
1121
1122 - var touchConfig = startConfig(
1122 + const touchConfig = startConfig(
1123 siblings.childTwo,
1124 [siblings.childOne, siblings.childTwo],
1125 [1],
@@ -1174,7 +1174,7 @@ describe('ResponderEventPlugin', () => {
1174
1175 it('should notify of being rejected. responderStart/Move happens on current responder', () => {
1176 // Initially nothing wants to become the responder
1177 - var config = oneEventLoopTestConfig(three);
1177 + let config = oneEventLoopTestConfig(three);
1178 config.startShouldSetResponder.captured.grandParent = {
1179 order: 0,
1180 returnVal: false,
@@ -1213,7 +1213,7 @@ describe('ResponderEventPlugin', () => {
1213 // The start/move should occur on the original responder if new one is rejected
1214 config.responderMove.child = {order: 6};
1215
1216 - var touchConfig = moveConfig(three.child, [three.child], [0]);
1216 + let touchConfig = moveConfig(three.child, [three.child], [0]);
1217 run(config, three, touchConfig);
1218 expect(ResponderEventPlugin._getResponder()).toBe(
1219 getInstanceFromNode(three.child),
@@ -1244,7 +1244,7 @@ describe('ResponderEventPlugin', () => {
1244
1245 it('should negotiate scroll', () => {
1246 // Initially nothing wants to become the responder
1247 - var config = oneEventLoopTestConfig(three);
1247 + let config = oneEventLoopTestConfig(three);
1248 config.startShouldSetResponder.captured.grandParent = {
1249 order: 0,
1250 returnVal: false,
@@ -1325,7 +1325,7 @@ describe('ResponderEventPlugin', () => {
1325
1326 it('should cancel correctly', () => {
1327 // Initially our child becomes responder
1328 - var config = oneEventLoopTestConfig(three);
1328 + let config = oneEventLoopTestConfig(three);
1329 config.startShouldSetResponder.captured.grandParent = {
1330 order: 0,
1331 returnVal: false,
@@ -1351,7 +1351,7 @@ describe('ResponderEventPlugin', () => {
1351 config.responderEnd.child = {order: 0};
1352 config.responderTerminate.child = {order: 1};
1353
1354 - var nativeEvent = _touchConfig(
1354 + const nativeEvent = _touchConfig(
1355 'topTouchCancel',
1356 three.child,
1357 [three.child],
@@ -1364,10 +1364,10 @@ describe('ResponderEventPlugin', () => {
1364 it('should determine the first common ancestor correctly', () => {
1365 // This test was moved here from the ReactTreeTraversal test since only the
1366 // ResponderEventPlugin uses `getLowestCommonAncestor`
1367 - var React = require('react');
1368 - var ReactTestUtils = require('react-dom/test-utils');
1369 - var ReactTreeTraversal = require('shared/ReactTreeTraversal');
1370 - var ReactDOMComponentTree = require('../../react-dom/src/client/ReactDOMComponentTree');
1367 + const React = require('react');
1368 + const ReactTestUtils = require('react-dom/test-utils');
1369 + const ReactTreeTraversal = require('shared/ReactTreeTraversal');
1370 + const ReactDOMComponentTree = require('../../react-dom/src/client/ReactDOMComponentTree');
1371
1372 class ChildComponent extends React.Component {
1373 render() {
@@ -1394,9 +1394,9 @@ describe('ResponderEventPlugin', () => {
1394 }
1395 }
1396
1397 - var parent = ReactTestUtils.renderIntoDocument(<ParentComponent />);
1397 + const parent = ReactTestUtils.renderIntoDocument(<ParentComponent />);
1398
1399 - var ancestors = [
1399 + const ancestors = [
1400 // Common ancestor with self is self.
1401 {
1402 one: parent.refs.P_P1_C1.refs.DIV_1,
@@ -1436,10 +1436,10 @@ describe('ResponderEventPlugin', () => {
1436 com: parent.refs.P,
1437 },
1438 ];
1439 - var i;
1439 + let i;
1440 for (i = 0; i < ancestors.length; i++) {
1441 - var plan = ancestors[i];
1442 - var firstCommon = ReactTreeTraversal.getLowestCommonAncestor(
1441 + const plan = ancestors[i];
1442 + const firstCommon = ReactTreeTraversal.getLowestCommonAncestor(
1443 ReactDOMComponentTree.getInstanceFromNode(plan.one),
1444 ReactDOMComponentTree.getInstanceFromNode(plan.two),
1445 );
packages/events/__tests__/accumulateInto-test.internal.js
+6 -6
@@ -9,7 +9,7 @@
9
10 'use strict';
11
12 -var accumulateInto;
12 +let accumulateInto;
13
14 describe('accumulateInto', () => {
15 beforeEach(() => {
@@ -25,23 +25,23 @@ describe('accumulateInto', () => {
25 });
26
27 it('returns the second item if first is null', () => {
28 - var a = [];
28 + const a = [];
29 expect(accumulateInto(null, a)).toBe(a);
30 });
31
32 it('merges the second into the first if first item is an array', () => {
33 - var a = [1, 2];
34 - var b = [3, 4];
33 + const a = [1, 2];
34 + const b = [3, 4];
35 accumulateInto(a, b);
36 expect(a).toEqual([1, 2, 3, 4]);
37 expect(b).toEqual([3, 4]);
38 - var c = [1];
38 + const c = [1];
39 accumulateInto(c, 2);
40 expect(c).toEqual([1, 2]);
41 });
42
43 it('returns a new array if first or both items are scalar', () => {
44 - var a = [2];
44 + const a = [2];
45 expect(accumulateInto(1, a)).toEqual([1, 2]);
46 expect(a).toEqual([2]);
47 expect(accumulateInto(1, 2)).toEqual([1, 2]);