Skip to content

Commit 2decfe9

Browse files
raphamorimgaearon
authored andcommitted
events: convert var to let/const (#11714)
1 parent c78db58 commit 2decfe9

14 files changed

+244
-242
lines changed

packages/events/EventPluginHub.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type {AnyNativeEvent} from './PluginModuleType';
3030
* Internal queue of events that have accumulated their dispatches and are
3131
* waiting to have their dispatches executed.
3232
*/
33-
var eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
33+
let eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
3434

3535
/**
3636
* Dispatches an event and releases it back into the pool, unless persistent.
@@ -39,7 +39,7 @@ var eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
3939
* @param {boolean} simulated If the event is simulated (changes exn behavior)
4040
* @private
4141
*/
42-
var executeDispatchesAndRelease = function(
42+
const executeDispatchesAndRelease = function(
4343
event: ReactSyntheticEvent,
4444
simulated: boolean,
4545
) {
@@ -51,10 +51,10 @@ var executeDispatchesAndRelease = function(
5151
}
5252
}
5353
};
54-
var executeDispatchesAndReleaseSimulated = function(e) {
54+
const executeDispatchesAndReleaseSimulated = function(e) {
5555
return executeDispatchesAndRelease(e, true);
5656
};
57-
var executeDispatchesAndReleaseTopLevel = function(e) {
57+
const executeDispatchesAndReleaseTopLevel = function(e) {
5858
return executeDispatchesAndRelease(e, false);
5959
};
6060

@@ -130,7 +130,7 @@ export const injection = {
130130
* @return {?function} The stored callback.
131131
*/
132132
export function getListener(inst: Fiber, registrationName: string) {
133-
var listener;
133+
let listener;
134134

135135
// TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
136136
// live here; needs to be moved to a better place soon
@@ -170,12 +170,12 @@ export function extractEvents(
170170
nativeEvent: AnyNativeEvent,
171171
nativeEventTarget: EventTarget,
172172
) {
173-
var events;
174-
for (var i = 0; i < plugins.length; i++) {
173+
let events;
174+
for (let i = 0; i < plugins.length; i++) {
175175
// 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];
177177
if (possiblePlugin) {
178-
var extractedEvents = possiblePlugin.extractEvents(
178+
const extractedEvents = possiblePlugin.extractEvents(
179179
topLevelType,
180180
targetInst,
181181
nativeEvent,
@@ -212,7 +212,7 @@ export function enqueueEvents(
212212
export function processEventQueue(simulated: boolean) {
213213
// Set `eventQueue` to null before processing it so that we can tell if more
214214
// events get enqueued while processing.
215-
var processingEventQueue = eventQueue;
215+
const processingEventQueue = eventQueue;
216216
eventQueue = null;
217217

218218
if (!processingEventQueue) {

packages/events/EventPluginRegistry.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ import lowPriorityWarning from 'shared/lowPriorityWarning';
2020
type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>};
2121
type EventPluginOrder = null | Array<PluginName>;
2222

23-
var shouldWarnOnInjection = false;
23+
let shouldWarnOnInjection = false;
2424

2525
/**
2626
* Injectable ordering of event plugins.
2727
*/
28-
var eventPluginOrder: EventPluginOrder = null;
28+
let eventPluginOrder: EventPluginOrder = null;
2929

3030
/**
3131
* Injectable mapping from names to event plugin modules.
3232
*/
33-
var namesToPlugins: NamesToPlugins = {};
33+
const namesToPlugins: NamesToPlugins = {};
3434

3535
export function enableWarningOnInjection() {
3636
shouldWarnOnInjection = true;
@@ -46,9 +46,9 @@ function recomputePluginOrdering(): void {
4646
// Wait until an `eventPluginOrder` is injected.
4747
return;
4848
}
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);
5252
invariant(
5353
pluginIndex > -1,
5454
'EventPluginRegistry: Cannot inject event plugins that do not exist in ' +
@@ -65,8 +65,8 @@ function recomputePluginOrdering(): void {
6565
pluginName,
6666
);
6767
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) {
7070
invariant(
7171
publishEventForPlugin(
7272
publishedEvents[eventName],
@@ -102,11 +102,11 @@ function publishEventForPlugin(
102102
);
103103
eventNameDispatchConfigs[eventName] = dispatchConfig;
104104

105-
var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
105+
const phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
106106
if (phasedRegistrationNames) {
107-
for (var phaseName in phasedRegistrationNames) {
107+
for (const phaseName in phasedRegistrationNames) {
108108
if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
109-
var phasedRegistrationName = phasedRegistrationNames[phaseName];
109+
const phasedRegistrationName = phasedRegistrationNames[phaseName];
110110
publishRegistrationName(
111111
phasedRegistrationName,
112112
pluginModule,
@@ -149,7 +149,7 @@ function publishRegistrationName(
149149
pluginModule.eventTypes[eventName].dependencies;
150150

151151
if (__DEV__) {
152-
var lowerCasedName = registrationName.toLowerCase();
152+
const lowerCasedName = registrationName.toLowerCase();
153153
possibleRegistrationNames[lowerCasedName] = registrationName;
154154

155155
if (registrationName === 'onDoubleClick') {
@@ -243,12 +243,12 @@ export function injectEventPluginsByName(
243243
}
244244
}
245245

246-
var isOrderingDirty = false;
247-
for (var pluginName in injectedNamesToPlugins) {
246+
let isOrderingDirty = false;
247+
for (const pluginName in injectedNamesToPlugins) {
248248
if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
249249
continue;
250250
}
251-
var pluginModule = injectedNamesToPlugins[pluginName];
251+
const pluginModule = injectedNamesToPlugins[pluginName];
252252
if (
253253
!namesToPlugins.hasOwnProperty(pluginName) ||
254254
namesToPlugins[pluginName] !== pluginModule

packages/events/EventPluginUtils.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ export function isStartish(topLevelType) {
4545
return topLevelType === 'topMouseDown' || topLevelType === 'topTouchStart';
4646
}
4747

48-
var validateEventDispatches;
48+
let validateEventDispatches;
4949
if (__DEV__) {
5050
validateEventDispatches = function(event) {
51-
var dispatchListeners = event._dispatchListeners;
52-
var dispatchInstances = event._dispatchInstances;
51+
const dispatchListeners = event._dispatchListeners;
52+
const dispatchInstances = event._dispatchInstances;
5353

54-
var listenersIsArr = Array.isArray(dispatchListeners);
55-
var listenersLen = listenersIsArr
54+
const listenersIsArr = Array.isArray(dispatchListeners);
55+
const listenersLen = listenersIsArr
5656
? dispatchListeners.length
5757
: dispatchListeners ? 1 : 0;
5858

59-
var instancesIsArr = Array.isArray(dispatchInstances);
60-
var instancesLen = instancesIsArr
59+
const instancesIsArr = Array.isArray(dispatchInstances);
60+
const instancesLen = instancesIsArr
6161
? dispatchInstances.length
6262
: dispatchInstances ? 1 : 0;
6363

@@ -76,7 +76,7 @@ if (__DEV__) {
7676
* @param {*} inst Internal component instance
7777
*/
7878
function executeDispatch(event, simulated, listener, inst) {
79-
var type = event.type || 'unknown-event';
79+
const type = event.type || 'unknown-event';
8080
event.currentTarget = getNodeFromInstance(inst);
8181
ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError(
8282
type,
@@ -91,13 +91,13 @@ function executeDispatch(event, simulated, listener, inst) {
9191
* Standard/simple iteration through an event's collected dispatches.
9292
*/
9393
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;
9696
if (__DEV__) {
9797
validateEventDispatches(event);
9898
}
9999
if (Array.isArray(dispatchListeners)) {
100-
for (var i = 0; i < dispatchListeners.length; i++) {
100+
for (let i = 0; i < dispatchListeners.length; i++) {
101101
if (event.isPropagationStopped()) {
102102
break;
103103
}
@@ -124,13 +124,13 @@ export function executeDispatchesInOrder(event, simulated) {
124124
* true, or null if no listener returned true.
125125
*/
126126
function executeDispatchesInOrderStopAtTrueImpl(event) {
127-
var dispatchListeners = event._dispatchListeners;
128-
var dispatchInstances = event._dispatchInstances;
127+
const dispatchListeners = event._dispatchListeners;
128+
const dispatchInstances = event._dispatchInstances;
129129
if (__DEV__) {
130130
validateEventDispatches(event);
131131
}
132132
if (Array.isArray(dispatchListeners)) {
133-
for (var i = 0; i < dispatchListeners.length; i++) {
133+
for (let i = 0; i < dispatchListeners.length; i++) {
134134
if (event.isPropagationStopped()) {
135135
break;
136136
}
@@ -151,7 +151,7 @@ function executeDispatchesInOrderStopAtTrueImpl(event) {
151151
* @see executeDispatchesInOrderStopAtTrueImpl
152152
*/
153153
export function executeDispatchesInOrderStopAtTrue(event) {
154-
var ret = executeDispatchesInOrderStopAtTrueImpl(event);
154+
const ret = executeDispatchesInOrderStopAtTrueImpl(event);
155155
event._dispatchInstances = null;
156156
event._dispatchListeners = null;
157157
return ret;
@@ -170,16 +170,16 @@ export function executeDirectDispatch(event) {
170170
if (__DEV__) {
171171
validateEventDispatches(event);
172172
}
173-
var dispatchListener = event._dispatchListeners;
174-
var dispatchInstance = event._dispatchInstances;
173+
const dispatchListener = event._dispatchListeners;
174+
const dispatchInstance = event._dispatchInstances;
175175
invariant(
176176
!Array.isArray(dispatchListener),
177177
'executeDirectDispatch(...): Invalid `event`.',
178178
);
179179
event.currentTarget = dispatchListener
180180
? getNodeFromInstance(dispatchInstance)
181181
: null;
182-
var res = dispatchListener ? dispatchListener(event) : null;
182+
const res = dispatchListener ? dispatchListener(event) : null;
183183
event.currentTarget = null;
184184
event._dispatchListeners = null;
185185
event._dispatchInstances = null;

packages/events/EventPropagators.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type PropagationPhases = 'bubbled' | 'captured';
2323
* "phases" of propagation. This finds listeners by a given phase.
2424
*/
2525
function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
26-
var registrationName =
26+
const registrationName =
2727
event.dispatchConfig.phasedRegistrationNames[propagationPhase];
2828
return getListener(inst, registrationName);
2929
}
@@ -48,7 +48,7 @@ function accumulateDirectionalDispatches(inst, phase, event) {
4848
if (__DEV__) {
4949
warning(inst, 'Dispatching inst must not be null');
5050
}
51-
var listener = listenerAtPhase(inst, event, phase);
51+
const listener = listenerAtPhase(inst, event, phase);
5252
if (listener) {
5353
event._dispatchListeners = accumulateInto(
5454
event._dispatchListeners,
@@ -76,8 +76,8 @@ function accumulateTwoPhaseDispatchesSingle(event) {
7676
*/
7777
function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
7878
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;
8181
traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
8282
}
8383
}
@@ -89,8 +89,8 @@ function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
8989
*/
9090
function accumulateDispatches(inst, ignoredDirection, event) {
9191
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);
9494
if (listener) {
9595
event._dispatchListeners = accumulateInto(
9696
event._dispatchListeners,

packages/events/ReactControlledComponent.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ import {
1414

1515
// Use to restore controlled state after a change event has fired.
1616

17-
var fiberHostComponent = null;
17+
let fiberHostComponent = null;
1818

19-
var ReactControlledComponentInjection = {
19+
const ReactControlledComponentInjection = {
2020
injectFiberControlledHostComponent: function(hostComponentImpl) {
2121
// The fiber implementation doesn't use dynamic dispatch so we need to
2222
// inject the implementation.
2323
fiberHostComponent = hostComponentImpl;
2424
},
2525
};
2626

27-
var restoreTarget = null;
28-
var restoreQueue = null;
27+
let restoreTarget = null;
28+
let restoreQueue = null;
2929

3030
function restoreStateOfTarget(target) {
3131
// We perform this translation at the end of the event loop so that we
3232
// always receive the correct fiber here
33-
var internalInstance = getInstanceFromNode(target);
33+
const internalInstance = getInstanceFromNode(target);
3434
if (!internalInstance) {
3535
// Unmounted
3636
return;
@@ -67,14 +67,14 @@ export function restoreStateIfNeeded() {
6767
if (!restoreTarget) {
6868
return;
6969
}
70-
var target = restoreTarget;
71-
var queuedTargets = restoreQueue;
70+
const target = restoreTarget;
71+
const queuedTargets = restoreQueue;
7272
restoreTarget = null;
7373
restoreQueue = null;
7474

7575
restoreStateOfTarget(target);
7676
if (queuedTargets) {
77-
for (var i = 0; i < queuedTargets.length; i++) {
77+
for (let i = 0; i < queuedTargets.length; i++) {
7878
restoreStateOfTarget(queuedTargets[i]);
7979
}
8080
}

packages/events/ReactEventEmitterMixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function handleTopLevel(
2626
nativeEvent,
2727
nativeEventTarget,
2828
) {
29-
var events = extractEvents(
29+
const events = extractEvents(
3030
topLevelType,
3131
targetInst,
3232
nativeEvent,

packages/events/ReactGenericBatching.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import {restoreStateIfNeeded} from './ReactControlledComponent';
1414
// scheduled work and instead do synchronous work.
1515

1616
// Defaults
17-
var fiberBatchedUpdates = function(fn, bookkeeping) {
17+
let fiberBatchedUpdates = function(fn, bookkeeping) {
1818
return fn(bookkeeping);
1919
};
2020

21-
var isNestingBatched = false;
21+
let isNestingBatched = false;
2222
export function batchedUpdates(fn, bookkeeping) {
2323
if (isNestingBatched) {
2424
// If we are currently inside another batch, we need to wait until it
@@ -39,7 +39,7 @@ export function batchedUpdates(fn, bookkeeping) {
3939
}
4040
}
4141

42-
var ReactGenericBatchingInjection = {
42+
const ReactGenericBatchingInjection = {
4343
injectFiberBatchedUpdates: function(_batchedUpdates) {
4444
fiberBatchedUpdates = _batchedUpdates;
4545
},

0 commit comments

Comments
 (0)