events: convert var to let/const (#11714)
This commit is contained in:
parent
c78db58a61
commit
2decfe97dc
|
@ -30,7 +30,7 @@ import type {AnyNativeEvent} from './PluginModuleType';
|
|||
* Internal queue of events that have accumulated their dispatches and are
|
||||
* waiting to have their dispatches executed.
|
||||
*/
|
||||
var eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
|
||||
let eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
|
||||
|
||||
/**
|
||||
* Dispatches an event and releases it back into the pool, unless persistent.
|
||||
|
@ -39,7 +39,7 @@ var eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
|
|||
* @param {boolean} simulated If the event is simulated (changes exn behavior)
|
||||
* @private
|
||||
*/
|
||||
var executeDispatchesAndRelease = function(
|
||||
const executeDispatchesAndRelease = function(
|
||||
event: ReactSyntheticEvent,
|
||||
simulated: boolean,
|
||||
) {
|
||||
|
@ -51,10 +51,10 @@ var executeDispatchesAndRelease = function(
|
|||
}
|
||||
}
|
||||
};
|
||||
var executeDispatchesAndReleaseSimulated = function(e) {
|
||||
const executeDispatchesAndReleaseSimulated = function(e) {
|
||||
return executeDispatchesAndRelease(e, true);
|
||||
};
|
||||
var executeDispatchesAndReleaseTopLevel = function(e) {
|
||||
const executeDispatchesAndReleaseTopLevel = function(e) {
|
||||
return executeDispatchesAndRelease(e, false);
|
||||
};
|
||||
|
||||
|
@ -130,7 +130,7 @@ export const injection = {
|
|||
* @return {?function} The stored callback.
|
||||
*/
|
||||
export function getListener(inst: Fiber, registrationName: string) {
|
||||
var listener;
|
||||
let listener;
|
||||
|
||||
// TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
|
||||
// live here; needs to be moved to a better place soon
|
||||
|
@ -170,12 +170,12 @@ export function extractEvents(
|
|||
nativeEvent: AnyNativeEvent,
|
||||
nativeEventTarget: EventTarget,
|
||||
) {
|
||||
var events;
|
||||
for (var i = 0; i < plugins.length; i++) {
|
||||
let events;
|
||||
for (let i = 0; i < plugins.length; i++) {
|
||||
// Not every plugin in the ordering may be loaded at runtime.
|
||||
var possiblePlugin: PluginModule<AnyNativeEvent> = plugins[i];
|
||||
const possiblePlugin: PluginModule<AnyNativeEvent> = plugins[i];
|
||||
if (possiblePlugin) {
|
||||
var extractedEvents = possiblePlugin.extractEvents(
|
||||
const extractedEvents = possiblePlugin.extractEvents(
|
||||
topLevelType,
|
||||
targetInst,
|
||||
nativeEvent,
|
||||
|
@ -212,7 +212,7 @@ export function enqueueEvents(
|
|||
export function processEventQueue(simulated: boolean) {
|
||||
// Set `eventQueue` to null before processing it so that we can tell if more
|
||||
// events get enqueued while processing.
|
||||
var processingEventQueue = eventQueue;
|
||||
const processingEventQueue = eventQueue;
|
||||
eventQueue = null;
|
||||
|
||||
if (!processingEventQueue) {
|
||||
|
|
|
@ -20,17 +20,17 @@ import lowPriorityWarning from 'shared/lowPriorityWarning';
|
|||
type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>};
|
||||
type EventPluginOrder = null | Array<PluginName>;
|
||||
|
||||
var shouldWarnOnInjection = false;
|
||||
let shouldWarnOnInjection = false;
|
||||
|
||||
/**
|
||||
* Injectable ordering of event plugins.
|
||||
*/
|
||||
var eventPluginOrder: EventPluginOrder = null;
|
||||
let eventPluginOrder: EventPluginOrder = null;
|
||||
|
||||
/**
|
||||
* Injectable mapping from names to event plugin modules.
|
||||
*/
|
||||
var namesToPlugins: NamesToPlugins = {};
|
||||
const namesToPlugins: NamesToPlugins = {};
|
||||
|
||||
export function enableWarningOnInjection() {
|
||||
shouldWarnOnInjection = true;
|
||||
|
@ -46,9 +46,9 @@ function recomputePluginOrdering(): void {
|
|||
// Wait until an `eventPluginOrder` is injected.
|
||||
return;
|
||||
}
|
||||
for (var pluginName in namesToPlugins) {
|
||||
var pluginModule = namesToPlugins[pluginName];
|
||||
var pluginIndex = eventPluginOrder.indexOf(pluginName);
|
||||
for (const pluginName in namesToPlugins) {
|
||||
const pluginModule = namesToPlugins[pluginName];
|
||||
const pluginIndex = eventPluginOrder.indexOf(pluginName);
|
||||
invariant(
|
||||
pluginIndex > -1,
|
||||
'EventPluginRegistry: Cannot inject event plugins that do not exist in ' +
|
||||
|
@ -65,8 +65,8 @@ function recomputePluginOrdering(): void {
|
|||
pluginName,
|
||||
);
|
||||
plugins[pluginIndex] = pluginModule;
|
||||
var publishedEvents = pluginModule.eventTypes;
|
||||
for (var eventName in publishedEvents) {
|
||||
const publishedEvents = pluginModule.eventTypes;
|
||||
for (const eventName in publishedEvents) {
|
||||
invariant(
|
||||
publishEventForPlugin(
|
||||
publishedEvents[eventName],
|
||||
|
@ -102,11 +102,11 @@ function publishEventForPlugin(
|
|||
);
|
||||
eventNameDispatchConfigs[eventName] = dispatchConfig;
|
||||
|
||||
var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
||||
const phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
||||
if (phasedRegistrationNames) {
|
||||
for (var phaseName in phasedRegistrationNames) {
|
||||
for (const phaseName in phasedRegistrationNames) {
|
||||
if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
|
||||
var phasedRegistrationName = phasedRegistrationNames[phaseName];
|
||||
const phasedRegistrationName = phasedRegistrationNames[phaseName];
|
||||
publishRegistrationName(
|
||||
phasedRegistrationName,
|
||||
pluginModule,
|
||||
|
@ -149,7 +149,7 @@ function publishRegistrationName(
|
|||
pluginModule.eventTypes[eventName].dependencies;
|
||||
|
||||
if (__DEV__) {
|
||||
var lowerCasedName = registrationName.toLowerCase();
|
||||
const lowerCasedName = registrationName.toLowerCase();
|
||||
possibleRegistrationNames[lowerCasedName] = registrationName;
|
||||
|
||||
if (registrationName === 'onDoubleClick') {
|
||||
|
@ -243,12 +243,12 @@ export function injectEventPluginsByName(
|
|||
}
|
||||
}
|
||||
|
||||
var isOrderingDirty = false;
|
||||
for (var pluginName in injectedNamesToPlugins) {
|
||||
let isOrderingDirty = false;
|
||||
for (const pluginName in injectedNamesToPlugins) {
|
||||
if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
|
||||
continue;
|
||||
}
|
||||
var pluginModule = injectedNamesToPlugins[pluginName];
|
||||
const pluginModule = injectedNamesToPlugins[pluginName];
|
||||
if (
|
||||
!namesToPlugins.hasOwnProperty(pluginName) ||
|
||||
namesToPlugins[pluginName] !== pluginModule
|
||||
|
|
|
@ -45,19 +45,19 @@ export function isStartish(topLevelType) {
|
|||
return topLevelType === 'topMouseDown' || topLevelType === 'topTouchStart';
|
||||
}
|
||||
|
||||
var validateEventDispatches;
|
||||
let validateEventDispatches;
|
||||
if (__DEV__) {
|
||||
validateEventDispatches = function(event) {
|
||||
var dispatchListeners = event._dispatchListeners;
|
||||
var dispatchInstances = event._dispatchInstances;
|
||||
const dispatchListeners = event._dispatchListeners;
|
||||
const dispatchInstances = event._dispatchInstances;
|
||||
|
||||
var listenersIsArr = Array.isArray(dispatchListeners);
|
||||
var listenersLen = listenersIsArr
|
||||
const listenersIsArr = Array.isArray(dispatchListeners);
|
||||
const listenersLen = listenersIsArr
|
||||
? dispatchListeners.length
|
||||
: dispatchListeners ? 1 : 0;
|
||||
|
||||
var instancesIsArr = Array.isArray(dispatchInstances);
|
||||
var instancesLen = instancesIsArr
|
||||
const instancesIsArr = Array.isArray(dispatchInstances);
|
||||
const instancesLen = instancesIsArr
|
||||
? dispatchInstances.length
|
||||
: dispatchInstances ? 1 : 0;
|
||||
|
||||
|
@ -76,7 +76,7 @@ if (__DEV__) {
|
|||
* @param {*} inst Internal component instance
|
||||
*/
|
||||
function executeDispatch(event, simulated, listener, inst) {
|
||||
var type = event.type || 'unknown-event';
|
||||
const type = event.type || 'unknown-event';
|
||||
event.currentTarget = getNodeFromInstance(inst);
|
||||
ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError(
|
||||
type,
|
||||
|
@ -91,13 +91,13 @@ function executeDispatch(event, simulated, listener, inst) {
|
|||
* Standard/simple iteration through an event's collected dispatches.
|
||||
*/
|
||||
export function executeDispatchesInOrder(event, simulated) {
|
||||
var dispatchListeners = event._dispatchListeners;
|
||||
var dispatchInstances = event._dispatchInstances;
|
||||
const dispatchListeners = event._dispatchListeners;
|
||||
const dispatchInstances = event._dispatchInstances;
|
||||
if (__DEV__) {
|
||||
validateEventDispatches(event);
|
||||
}
|
||||
if (Array.isArray(dispatchListeners)) {
|
||||
for (var i = 0; i < dispatchListeners.length; i++) {
|
||||
for (let i = 0; i < dispatchListeners.length; i++) {
|
||||
if (event.isPropagationStopped()) {
|
||||
break;
|
||||
}
|
||||
|
@ -124,13 +124,13 @@ export function executeDispatchesInOrder(event, simulated) {
|
|||
* true, or null if no listener returned true.
|
||||
*/
|
||||
function executeDispatchesInOrderStopAtTrueImpl(event) {
|
||||
var dispatchListeners = event._dispatchListeners;
|
||||
var dispatchInstances = event._dispatchInstances;
|
||||
const dispatchListeners = event._dispatchListeners;
|
||||
const dispatchInstances = event._dispatchInstances;
|
||||
if (__DEV__) {
|
||||
validateEventDispatches(event);
|
||||
}
|
||||
if (Array.isArray(dispatchListeners)) {
|
||||
for (var i = 0; i < dispatchListeners.length; i++) {
|
||||
for (let i = 0; i < dispatchListeners.length; i++) {
|
||||
if (event.isPropagationStopped()) {
|
||||
break;
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ function executeDispatchesInOrderStopAtTrueImpl(event) {
|
|||
* @see executeDispatchesInOrderStopAtTrueImpl
|
||||
*/
|
||||
export function executeDispatchesInOrderStopAtTrue(event) {
|
||||
var ret = executeDispatchesInOrderStopAtTrueImpl(event);
|
||||
const ret = executeDispatchesInOrderStopAtTrueImpl(event);
|
||||
event._dispatchInstances = null;
|
||||
event._dispatchListeners = null;
|
||||
return ret;
|
||||
|
@ -170,8 +170,8 @@ export function executeDirectDispatch(event) {
|
|||
if (__DEV__) {
|
||||
validateEventDispatches(event);
|
||||
}
|
||||
var dispatchListener = event._dispatchListeners;
|
||||
var dispatchInstance = event._dispatchInstances;
|
||||
const dispatchListener = event._dispatchListeners;
|
||||
const dispatchInstance = event._dispatchInstances;
|
||||
invariant(
|
||||
!Array.isArray(dispatchListener),
|
||||
'executeDirectDispatch(...): Invalid `event`.',
|
||||
|
@ -179,7 +179,7 @@ export function executeDirectDispatch(event) {
|
|||
event.currentTarget = dispatchListener
|
||||
? getNodeFromInstance(dispatchInstance)
|
||||
: null;
|
||||
var res = dispatchListener ? dispatchListener(event) : null;
|
||||
const res = dispatchListener ? dispatchListener(event) : null;
|
||||
event.currentTarget = null;
|
||||
event._dispatchListeners = null;
|
||||
event._dispatchInstances = null;
|
||||
|
|
|
@ -23,7 +23,7 @@ type PropagationPhases = 'bubbled' | 'captured';
|
|||
* "phases" of propagation. This finds listeners by a given phase.
|
||||
*/
|
||||
function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
|
||||
var registrationName =
|
||||
const registrationName =
|
||||
event.dispatchConfig.phasedRegistrationNames[propagationPhase];
|
||||
return getListener(inst, registrationName);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ function accumulateDirectionalDispatches(inst, phase, event) {
|
|||
if (__DEV__) {
|
||||
warning(inst, 'Dispatching inst must not be null');
|
||||
}
|
||||
var listener = listenerAtPhase(inst, event, phase);
|
||||
const listener = listenerAtPhase(inst, event, phase);
|
||||
if (listener) {
|
||||
event._dispatchListeners = accumulateInto(
|
||||
event._dispatchListeners,
|
||||
|
@ -76,8 +76,8 @@ function accumulateTwoPhaseDispatchesSingle(event) {
|
|||
*/
|
||||
function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
|
||||
if (event && event.dispatchConfig.phasedRegistrationNames) {
|
||||
var targetInst = event._targetInst;
|
||||
var parentInst = targetInst ? getParentInstance(targetInst) : null;
|
||||
const targetInst = event._targetInst;
|
||||
const parentInst = targetInst ? getParentInstance(targetInst) : null;
|
||||
traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,8 @@ function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
|
|||
*/
|
||||
function accumulateDispatches(inst, ignoredDirection, event) {
|
||||
if (inst && event && event.dispatchConfig.registrationName) {
|
||||
var registrationName = event.dispatchConfig.registrationName;
|
||||
var listener = getListener(inst, registrationName);
|
||||
const registrationName = event.dispatchConfig.registrationName;
|
||||
const listener = getListener(inst, registrationName);
|
||||
if (listener) {
|
||||
event._dispatchListeners = accumulateInto(
|
||||
event._dispatchListeners,
|
||||
|
|
|
@ -14,9 +14,9 @@ import {
|
|||
|
||||
// Use to restore controlled state after a change event has fired.
|
||||
|
||||
var fiberHostComponent = null;
|
||||
let fiberHostComponent = null;
|
||||
|
||||
var ReactControlledComponentInjection = {
|
||||
const ReactControlledComponentInjection = {
|
||||
injectFiberControlledHostComponent: function(hostComponentImpl) {
|
||||
// The fiber implementation doesn't use dynamic dispatch so we need to
|
||||
// inject the implementation.
|
||||
|
@ -24,13 +24,13 @@ var ReactControlledComponentInjection = {
|
|||
},
|
||||
};
|
||||
|
||||
var restoreTarget = null;
|
||||
var restoreQueue = null;
|
||||
let restoreTarget = null;
|
||||
let restoreQueue = null;
|
||||
|
||||
function restoreStateOfTarget(target) {
|
||||
// We perform this translation at the end of the event loop so that we
|
||||
// always receive the correct fiber here
|
||||
var internalInstance = getInstanceFromNode(target);
|
||||
const internalInstance = getInstanceFromNode(target);
|
||||
if (!internalInstance) {
|
||||
// Unmounted
|
||||
return;
|
||||
|
@ -67,14 +67,14 @@ export function restoreStateIfNeeded() {
|
|||
if (!restoreTarget) {
|
||||
return;
|
||||
}
|
||||
var target = restoreTarget;
|
||||
var queuedTargets = restoreQueue;
|
||||
const target = restoreTarget;
|
||||
const queuedTargets = restoreQueue;
|
||||
restoreTarget = null;
|
||||
restoreQueue = null;
|
||||
|
||||
restoreStateOfTarget(target);
|
||||
if (queuedTargets) {
|
||||
for (var i = 0; i < queuedTargets.length; i++) {
|
||||
for (let i = 0; i < queuedTargets.length; i++) {
|
||||
restoreStateOfTarget(queuedTargets[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ export function handleTopLevel(
|
|||
nativeEvent,
|
||||
nativeEventTarget,
|
||||
) {
|
||||
var events = extractEvents(
|
||||
const events = extractEvents(
|
||||
topLevelType,
|
||||
targetInst,
|
||||
nativeEvent,
|
||||
|
|
|
@ -14,11 +14,11 @@ import {restoreStateIfNeeded} from './ReactControlledComponent';
|
|||
// scheduled work and instead do synchronous work.
|
||||
|
||||
// Defaults
|
||||
var fiberBatchedUpdates = function(fn, bookkeeping) {
|
||||
let fiberBatchedUpdates = function(fn, bookkeeping) {
|
||||
return fn(bookkeeping);
|
||||
};
|
||||
|
||||
var isNestingBatched = false;
|
||||
let isNestingBatched = false;
|
||||
export function batchedUpdates(fn, bookkeeping) {
|
||||
if (isNestingBatched) {
|
||||
// If we are currently inside another batch, we need to wait until it
|
||||
|
@ -39,7 +39,7 @@ export function batchedUpdates(fn, bookkeeping) {
|
|||
}
|
||||
}
|
||||
|
||||
var ReactGenericBatchingInjection = {
|
||||
const ReactGenericBatchingInjection = {
|
||||
injectFiberBatchedUpdates: function(_batchedUpdates) {
|
||||
fiberBatchedUpdates = _batchedUpdates;
|
||||
},
|
||||
|
|
|
@ -29,21 +29,21 @@ import accumulate from './accumulate';
|
|||
* Instance of element that should respond to touch/move types of interactions,
|
||||
* as indicated explicitly by relevant callbacks.
|
||||
*/
|
||||
var responderInst = null;
|
||||
let responderInst = null;
|
||||
|
||||
/**
|
||||
* Count of current touches. A textInput should become responder iff the
|
||||
* selection changes while there is a touch on the screen.
|
||||
*/
|
||||
var trackedTouchCount = 0;
|
||||
let trackedTouchCount = 0;
|
||||
|
||||
/**
|
||||
* Last reported number of active touches.
|
||||
*/
|
||||
var previousActiveTouches = 0;
|
||||
let previousActiveTouches = 0;
|
||||
|
||||
var changeResponder = function(nextResponderInst, blockHostResponder) {
|
||||
var oldResponderInst = responderInst;
|
||||
const changeResponder = function(nextResponderInst, blockHostResponder) {
|
||||
const oldResponderInst = responderInst;
|
||||
responderInst = nextResponderInst;
|
||||
if (ResponderEventPlugin.GlobalResponderHandler !== null) {
|
||||
ResponderEventPlugin.GlobalResponderHandler.onChange(
|
||||
|
@ -54,7 +54,7 @@ var changeResponder = function(nextResponderInst, blockHostResponder) {
|
|||
}
|
||||
};
|
||||
|
||||
var eventTypes = {
|
||||
const eventTypes = {
|
||||
/**
|
||||
* On a `touchStart`/`mouseDown`, is it desired that this element become the
|
||||
* responder?
|
||||
|
@ -318,7 +318,7 @@ function setResponderAndExtractTransfer(
|
|||
nativeEvent,
|
||||
nativeEventTarget,
|
||||
) {
|
||||
var shouldSetEventType = isStartish(topLevelType)
|
||||
const shouldSetEventType = isStartish(topLevelType)
|
||||
? eventTypes.startShouldSetResponder
|
||||
: isMoveish(topLevelType)
|
||||
? eventTypes.moveShouldSetResponder
|
||||
|
@ -327,7 +327,7 @@ function setResponderAndExtractTransfer(
|
|||
: eventTypes.scrollShouldSetResponder;
|
||||
|
||||
// TODO: stop one short of the current responder.
|
||||
var bubbleShouldSetFrom = !responderInst
|
||||
const bubbleShouldSetFrom = !responderInst
|
||||
? targetInst
|
||||
: getLowestCommonAncestor(responderInst, targetInst);
|
||||
|
||||
|
@ -335,8 +335,8 @@ function setResponderAndExtractTransfer(
|
|||
// (deepest ID) if it happens to be the current responder. The reasoning:
|
||||
// It's strange to get an `onMoveShouldSetResponder` when you're *already*
|
||||
// the responder.
|
||||
var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
|
||||
var shouldSetEvent = ResponderSyntheticEvent.getPooled(
|
||||
const skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
|
||||
const shouldSetEvent = ResponderSyntheticEvent.getPooled(
|
||||
shouldSetEventType,
|
||||
bubbleShouldSetFrom,
|
||||
nativeEvent,
|
||||
|
@ -348,7 +348,7 @@ function setResponderAndExtractTransfer(
|
|||
} else {
|
||||
accumulateTwoPhaseDispatches(shouldSetEvent);
|
||||
}
|
||||
var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
|
||||
const wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
|
||||
if (!shouldSetEvent.isPersistent()) {
|
||||
shouldSetEvent.constructor.release(shouldSetEvent);
|
||||
}
|
||||
|
@ -356,8 +356,8 @@ function setResponderAndExtractTransfer(
|
|||
if (!wantsResponderInst || wantsResponderInst === responderInst) {
|
||||
return null;
|
||||
}
|
||||
var extracted;
|
||||
var grantEvent = ResponderSyntheticEvent.getPooled(
|
||||
let extracted;
|
||||
const grantEvent = ResponderSyntheticEvent.getPooled(
|
||||
eventTypes.responderGrant,
|
||||
wantsResponderInst,
|
||||
nativeEvent,
|
||||
|
@ -366,9 +366,9 @@ function setResponderAndExtractTransfer(
|
|||
grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
|
||||
|
||||
accumulateDirectDispatches(grantEvent);
|
||||
var blockHostResponder = executeDirectDispatch(grantEvent) === true;
|
||||
const blockHostResponder = executeDirectDispatch(grantEvent) === true;
|
||||
if (responderInst) {
|
||||
var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
|
||||
const terminationRequestEvent = ResponderSyntheticEvent.getPooled(
|
||||
eventTypes.responderTerminationRequest,
|
||||
responderInst,
|
||||
nativeEvent,
|
||||
|
@ -377,7 +377,7 @@ function setResponderAndExtractTransfer(
|
|||
terminationRequestEvent.touchHistory =
|
||||
ResponderTouchHistoryStore.touchHistory;
|
||||
accumulateDirectDispatches(terminationRequestEvent);
|
||||
var shouldSwitch =
|
||||
const shouldSwitch =
|
||||
!hasDispatches(terminationRequestEvent) ||
|
||||
executeDirectDispatch(terminationRequestEvent);
|
||||
if (!terminationRequestEvent.isPersistent()) {
|
||||
|
@ -385,7 +385,7 @@ function setResponderAndExtractTransfer(
|
|||
}
|
||||
|
||||
if (shouldSwitch) {
|
||||
var terminateEvent = ResponderSyntheticEvent.getPooled(
|
||||
const terminateEvent = ResponderSyntheticEvent.getPooled(
|
||||
eventTypes.responderTerminate,
|
||||
responderInst,
|
||||
nativeEvent,
|
||||
|
@ -396,7 +396,7 @@ function setResponderAndExtractTransfer(
|
|||
extracted = accumulate(extracted, [grantEvent, terminateEvent]);
|
||||
changeResponder(wantsResponderInst, blockHostResponder);
|
||||
} else {
|
||||
var rejectEvent = ResponderSyntheticEvent.getPooled(
|
||||
const rejectEvent = ResponderSyntheticEvent.getPooled(
|
||||
eventTypes.responderReject,
|
||||
wantsResponderInst,
|
||||
nativeEvent,
|
||||
|
@ -442,16 +442,16 @@ function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
|
|||
* @return {boolean} Whether or not this touch end event ends the responder.
|
||||
*/
|
||||
function noResponderTouches(nativeEvent) {
|
||||
var touches = nativeEvent.touches;
|
||||
const touches = nativeEvent.touches;
|
||||
if (!touches || touches.length === 0) {
|
||||
return true;
|
||||
}
|
||||
for (var i = 0; i < touches.length; i++) {
|
||||
var activeTouch = touches[i];
|
||||
var target = activeTouch.target;
|
||||
for (let i = 0; i < touches.length; i++) {
|
||||
const activeTouch = touches[i];
|
||||
const target = activeTouch.target;
|
||||
if (target !== null && target !== undefined && target !== 0) {
|
||||
// Is the original touch location inside of the current responder?
|
||||
var targetInst = getInstanceFromNode(target);
|
||||
const targetInst = getInstanceFromNode(target);
|
||||
if (isAncestor(responderInst, targetInst)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ function noResponderTouches(nativeEvent) {
|
|||
return true;
|
||||
}
|
||||
|
||||
var ResponderEventPlugin = {
|
||||
const ResponderEventPlugin = {
|
||||
/* For unit testing only */
|
||||
_getResponder: function() {
|
||||
return responderInst;
|
||||
|
@ -494,7 +494,7 @@ var ResponderEventPlugin = {
|
|||
|
||||
ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
|
||||
|
||||
var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)
|
||||
let extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent)
|
||||
? setResponderAndExtractTransfer(
|
||||
topLevelType,
|
||||
targetInst,
|
||||
|
@ -512,17 +512,17 @@ var ResponderEventPlugin = {
|
|||
// These multiple individual change touch events are are always bookended
|
||||
// by `onResponderGrant`, and one of
|
||||
// (`onResponderRelease/onResponderTerminate`).
|
||||
var isResponderTouchStart = responderInst && isStartish(topLevelType);
|
||||
var isResponderTouchMove = responderInst && isMoveish(topLevelType);
|
||||
var isResponderTouchEnd = responderInst && isEndish(topLevelType);
|
||||
var incrementalTouch = isResponderTouchStart
|
||||
const isResponderTouchStart = responderInst && isStartish(topLevelType);
|
||||
const isResponderTouchMove = responderInst && isMoveish(topLevelType);
|
||||
const isResponderTouchEnd = responderInst && isEndish(topLevelType);
|
||||
const incrementalTouch = isResponderTouchStart
|
||||
? eventTypes.responderStart
|
||||
: isResponderTouchMove
|
||||
? eventTypes.responderMove
|
||||
: isResponderTouchEnd ? eventTypes.responderEnd : null;
|
||||
|
||||
if (incrementalTouch) {
|
||||
var gesture = ResponderSyntheticEvent.getPooled(
|
||||
const gesture = ResponderSyntheticEvent.getPooled(
|
||||
incrementalTouch,
|
||||
responderInst,
|
||||
nativeEvent,
|
||||
|
@ -533,18 +533,18 @@ var ResponderEventPlugin = {
|
|||
extracted = accumulate(extracted, gesture);
|
||||
}
|
||||
|
||||
var isResponderTerminate =
|
||||
const isResponderTerminate =
|
||||
responderInst && topLevelType === 'topTouchCancel';
|
||||
var isResponderRelease =
|
||||
const isResponderRelease =
|
||||
responderInst &&
|
||||
!isResponderTerminate &&
|
||||
isEndish(topLevelType) &&
|
||||
noResponderTouches(nativeEvent);
|
||||
var finalTouch = isResponderTerminate
|
||||
const finalTouch = isResponderTerminate
|
||||
? eventTypes.responderTerminate
|
||||
: isResponderRelease ? eventTypes.responderRelease : null;
|
||||
if (finalTouch) {
|
||||
var finalEvent = ResponderSyntheticEvent.getPooled(
|
||||
const finalEvent = ResponderSyntheticEvent.getPooled(
|
||||
finalTouch,
|
||||
responderInst,
|
||||
nativeEvent,
|
||||
|
@ -556,7 +556,7 @@ var ResponderEventPlugin = {
|
|||
changeResponder(null);
|
||||
}
|
||||
|
||||
var numberActiveTouches =
|
||||
const numberActiveTouches =
|
||||
ResponderTouchHistoryStore.touchHistory.numberActiveTouches;
|
||||
if (
|
||||
ResponderEventPlugin.GlobalInteractionHandler &&
|
||||
|
|
|
@ -12,7 +12,7 @@ import SyntheticEvent from './SyntheticEvent';
|
|||
* interface will ensure that it is cleaned up when pooled/destroyed. The
|
||||
* `ResponderEventPlugin` will populate it appropriately.
|
||||
*/
|
||||
var ResponderEventInterface = {
|
||||
const ResponderEventInterface = {
|
||||
touchHistory: function(nativeEvent) {
|
||||
return null; // Actually doesn't even look at the native event.
|
||||
},
|
||||
|
|
|
@ -11,11 +11,11 @@ import emptyFunction from 'fbjs/lib/emptyFunction';
|
|||
import invariant from 'fbjs/lib/invariant';
|
||||
import warning from 'fbjs/lib/warning';
|
||||
|
||||
var didWarnForAddedNewProperty = false;
|
||||
var isProxySupported = typeof Proxy === 'function';
|
||||
var EVENT_POOL_SIZE = 10;
|
||||
let didWarnForAddedNewProperty = false;
|
||||
const isProxySupported = typeof Proxy === 'function';
|
||||
const EVENT_POOL_SIZE = 10;
|
||||
|
||||
var shouldBeReleasedProperties = [
|
||||
const shouldBeReleasedProperties = [
|
||||
'dispatchConfig',
|
||||
'_targetInst',
|
||||
'nativeEvent',
|
||||
|
@ -29,7 +29,7 @@ var shouldBeReleasedProperties = [
|
|||
* @interface Event
|
||||
* @see http://www.w3.org/TR/DOM-Level-3-Events/
|
||||
*/
|
||||
var EventInterface = {
|
||||
const EventInterface = {
|
||||
type: null,
|
||||
target: null,
|
||||
// currentTarget is set when dispatching; no use in copying it here
|
||||
|
@ -79,15 +79,15 @@ function SyntheticEvent(
|
|||
this._targetInst = targetInst;
|
||||
this.nativeEvent = nativeEvent;
|
||||
|
||||
var Interface = this.constructor.Interface;
|
||||
for (var propName in Interface) {
|
||||
const Interface = this.constructor.Interface;
|
||||
for (const propName in Interface) {
|
||||
if (!Interface.hasOwnProperty(propName)) {
|
||||
continue;
|
||||
}
|
||||
if (__DEV__) {
|
||||
delete this[propName]; // this has a getter/setter for warnings
|
||||
}
|
||||
var normalize = Interface[propName];
|
||||
const normalize = Interface[propName];
|
||||
if (normalize) {
|
||||
this[propName] = normalize(nativeEvent);
|
||||
} else {
|
||||
|
@ -99,7 +99,7 @@ function SyntheticEvent(
|
|||
}
|
||||
}
|
||||
|
||||
var defaultPrevented =
|
||||
const defaultPrevented =
|
||||
nativeEvent.defaultPrevented != null
|
||||
? nativeEvent.defaultPrevented
|
||||
: nativeEvent.returnValue === false;
|
||||
|
@ -115,7 +115,7 @@ function SyntheticEvent(
|
|||
Object.assign(SyntheticEvent.prototype, {
|
||||
preventDefault: function() {
|
||||
this.defaultPrevented = true;
|
||||
var event = this.nativeEvent;
|
||||
const event = this.nativeEvent;
|
||||
if (!event) {
|
||||
return;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ Object.assign(SyntheticEvent.prototype, {
|
|||
},
|
||||
|
||||
stopPropagation: function() {
|
||||
var event = this.nativeEvent;
|
||||
const event = this.nativeEvent;
|
||||
if (!event) {
|
||||
return;
|
||||
}
|
||||
|
@ -168,8 +168,8 @@ Object.assign(SyntheticEvent.prototype, {
|
|||
* `PooledClass` looks for `destructor` on each instance it releases.
|
||||
*/
|
||||
destructor: function() {
|
||||
var Interface = this.constructor.Interface;
|
||||
for (var propName in Interface) {
|
||||
const Interface = this.constructor.Interface;
|
||||
for (const propName in Interface) {
|
||||
if (__DEV__) {
|
||||
Object.defineProperty(
|
||||
this,
|
||||
|
@ -180,7 +180,7 @@ Object.assign(SyntheticEvent.prototype, {
|
|||
this[propName] = null;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < shouldBeReleasedProperties.length; i++) {
|
||||
for (let i = 0; i < shouldBeReleasedProperties.length; i++) {
|
||||
this[shouldBeReleasedProperties[i]] = null;
|
||||
}
|
||||
if (__DEV__) {
|
||||
|
@ -212,11 +212,11 @@ SyntheticEvent.Interface = EventInterface;
|
|||
* @param {?object} Interface
|
||||
*/
|
||||
SyntheticEvent.augmentClass = function(Class, Interface) {
|
||||
var Super = this;
|
||||
const Super = this;
|
||||
|
||||
var E = function() {};
|
||||
const E = function() {};
|
||||
E.prototype = Super.prototype;
|
||||
var prototype = new E();
|
||||
const prototype = new E();
|
||||
|
||||
Object.assign(prototype, Class.prototype);
|
||||
Class.prototype = prototype;
|
||||
|
@ -275,7 +275,7 @@ addEventPoolingTo(SyntheticEvent);
|
|||
* @return {object} defineProperty object
|
||||
*/
|
||||
function getPooledWarningPropertyDefinition(propName, getVal) {
|
||||
var isFunction = typeof getVal === 'function';
|
||||
const isFunction = typeof getVal === 'function';
|
||||
return {
|
||||
configurable: true,
|
||||
set: set,
|
||||
|
@ -283,14 +283,16 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
|
|||
};
|
||||
|
||||
function set(val) {
|
||||
var action = isFunction ? 'setting the method' : 'setting the property';
|
||||
const action = isFunction ? 'setting the method' : 'setting the property';
|
||||
warn(action, 'This is effectively a no-op');
|
||||
return val;
|
||||
}
|
||||
|
||||
function get() {
|
||||
var action = isFunction ? 'accessing the method' : 'accessing the property';
|
||||
var result = isFunction
|
||||
const action = isFunction
|
||||
? 'accessing the method'
|
||||
: 'accessing the property';
|
||||
const result = isFunction
|
||||
? 'This is a no-op function'
|
||||
: 'This is set to null';
|
||||
warn(action, result);
|
||||
|
@ -298,7 +300,7 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
|
|||
}
|
||||
|
||||
function warn(action, result) {
|
||||
var warningCondition = false;
|
||||
const warningCondition = false;
|
||||
warning(
|
||||
warningCondition,
|
||||
"This synthetic event is reused for performance reasons. If you're seeing this, " +
|
||||
|
@ -334,7 +336,7 @@ function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
|
|||
}
|
||||
|
||||
function releasePooledEvent(event) {
|
||||
var EventConstructor = this;
|
||||
const EventConstructor = this;
|
||||
invariant(
|
||||
event instanceof EventConstructor,
|
||||
'Trying to release an event instance into a pool of a different type.',
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
var TouchHistoryMath = {
|
||||
const TouchHistoryMath = {
|
||||
/**
|
||||
* This code is optimized and not intended to look beautiful. This allows
|
||||
* computing of touch centroids that have moved after `touchesChangedAfter`
|
||||
|
@ -28,11 +28,11 @@ var TouchHistoryMath = {
|
|||
isXAxis,
|
||||
ofCurrent,
|
||||
) {
|
||||
var touchBank = touchHistory.touchBank;
|
||||
var total = 0;
|
||||
var count = 0;
|
||||
const touchBank = touchHistory.touchBank;
|
||||
let total = 0;
|
||||
let count = 0;
|
||||
|
||||
var oneTouchData =
|
||||
const oneTouchData =
|
||||
touchHistory.numberActiveTouches === 1
|
||||
? touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch]
|
||||
: null;
|
||||
|
@ -53,15 +53,15 @@ var TouchHistoryMath = {
|
|||
count = 1;
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < touchBank.length; i++) {
|
||||
var touchTrack = touchBank[i];
|
||||
for (let i = 0; i < touchBank.length; i++) {
|
||||
const touchTrack = touchBank[i];
|
||||
if (
|
||||
touchTrack !== null &&
|
||||
touchTrack !== undefined &&
|
||||
touchTrack.touchActive &&
|
||||
touchTrack.currentTimeStamp >= touchesChangedAfter
|
||||
) {
|
||||
var toAdd; // Yuck, program temporarily in invalid state.
|
||||
let toAdd; // Yuck, program temporarily in invalid state.
|
||||
if (ofCurrent && isXAxis) {
|
||||
toAdd = touchTrack.currentPageX;
|
||||
} else if (ofCurrent && !isXAxis) {
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
'use strict';
|
||||
|
||||
describe('EventPluginRegistry', () => {
|
||||
var EventPluginRegistry;
|
||||
var createPlugin;
|
||||
let EventPluginRegistry;
|
||||
let createPlugin;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
@ -27,9 +27,9 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should be able to inject ordering before plugins', () => {
|
||||
var OnePlugin = createPlugin();
|
||||
var TwoPlugin = createPlugin();
|
||||
var ThreePlugin = createPlugin();
|
||||
const OnePlugin = createPlugin();
|
||||
const TwoPlugin = createPlugin();
|
||||
const ThreePlugin = createPlugin();
|
||||
|
||||
EventPluginRegistry.injectEventPluginOrder(['one', 'two', 'three']);
|
||||
EventPluginRegistry.injectEventPluginsByName({
|
||||
|
@ -47,9 +47,9 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should be able to inject plugins before and after ordering', () => {
|
||||
var OnePlugin = createPlugin();
|
||||
var TwoPlugin = createPlugin();
|
||||
var ThreePlugin = createPlugin();
|
||||
const OnePlugin = createPlugin();
|
||||
const TwoPlugin = createPlugin();
|
||||
const ThreePlugin = createPlugin();
|
||||
|
||||
EventPluginRegistry.injectEventPluginsByName({
|
||||
one: OnePlugin,
|
||||
|
@ -67,9 +67,9 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should be able to inject repeated plugins and out-of-order', () => {
|
||||
var OnePlugin = createPlugin();
|
||||
var TwoPlugin = createPlugin();
|
||||
var ThreePlugin = createPlugin();
|
||||
const OnePlugin = createPlugin();
|
||||
const TwoPlugin = createPlugin();
|
||||
const ThreePlugin = createPlugin();
|
||||
|
||||
EventPluginRegistry.injectEventPluginsByName({
|
||||
one: OnePlugin,
|
||||
|
@ -88,7 +88,7 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should throw if plugin does not implement `extractEvents`', () => {
|
||||
var BadPlugin = {};
|
||||
const BadPlugin = {};
|
||||
|
||||
EventPluginRegistry.injectEventPluginOrder(['bad']);
|
||||
|
||||
|
@ -103,8 +103,8 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should throw if plugin does not exist in ordering', () => {
|
||||
var OnePlugin = createPlugin();
|
||||
var RandomPlugin = createPlugin();
|
||||
const OnePlugin = createPlugin();
|
||||
const RandomPlugin = createPlugin();
|
||||
|
||||
EventPluginRegistry.injectEventPluginOrder(['one']);
|
||||
|
||||
|
@ -120,7 +120,7 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should throw if ordering is injected more than once', () => {
|
||||
var pluginOrdering = [];
|
||||
const pluginOrdering = [];
|
||||
|
||||
EventPluginRegistry.injectEventPluginOrder(pluginOrdering);
|
||||
|
||||
|
@ -133,8 +133,8 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should throw if different plugins injected using same name', () => {
|
||||
var OnePlugin = createPlugin();
|
||||
var TwoPlugin = createPlugin();
|
||||
const OnePlugin = createPlugin();
|
||||
const TwoPlugin = createPlugin();
|
||||
|
||||
EventPluginRegistry.injectEventPluginsByName({same: OnePlugin});
|
||||
|
||||
|
@ -147,13 +147,13 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should publish registration names of injected plugins', () => {
|
||||
var OnePlugin = createPlugin({
|
||||
const OnePlugin = createPlugin({
|
||||
eventTypes: {
|
||||
click: {registrationName: 'onClick'},
|
||||
focus: {registrationName: 'onFocus'},
|
||||
},
|
||||
});
|
||||
var TwoPlugin = createPlugin({
|
||||
const TwoPlugin = createPlugin({
|
||||
eventTypes: {
|
||||
magic: {
|
||||
phasedRegistrationNames: {
|
||||
|
@ -187,12 +187,12 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should throw if multiple registration names collide', () => {
|
||||
var OnePlugin = createPlugin({
|
||||
const OnePlugin = createPlugin({
|
||||
eventTypes: {
|
||||
photoCapture: {registrationName: 'onPhotoCapture'},
|
||||
},
|
||||
});
|
||||
var TwoPlugin = createPlugin({
|
||||
const TwoPlugin = createPlugin({
|
||||
eventTypes: {
|
||||
photo: {
|
||||
phasedRegistrationNames: {
|
||||
|
@ -217,7 +217,7 @@ describe('EventPluginRegistry', () => {
|
|||
});
|
||||
|
||||
it('should throw if an invalid event is published', () => {
|
||||
var OnePlugin = createPlugin({
|
||||
const OnePlugin = createPlugin({
|
||||
eventTypes: {
|
||||
badEvent: {
|
||||
/* missing configuration */
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var {HostComponent} = require('shared/ReactTypeOfWork');
|
||||
const {HostComponent} = require('shared/ReactTypeOfWork');
|
||||
|
||||
var EventPluginHub;
|
||||
var ResponderEventPlugin;
|
||||
let EventPluginHub;
|
||||
let ResponderEventPlugin;
|
||||
|
||||
var touch = function(nodeHandle, i) {
|
||||
const touch = function(nodeHandle, i) {
|
||||
return {target: nodeHandle, identifier: i};
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@ var touch = function(nodeHandle, i) {
|
|||
* @return {TouchEvent} Model of a touch event that is compliant with responder
|
||||
* system plugin.
|
||||
*/
|
||||
var touchEvent = function(nodeHandle, touches, changedTouches) {
|
||||
const touchEvent = function(nodeHandle, touches, changedTouches) {
|
||||
return {
|
||||
target: nodeHandle,
|
||||
changedTouches: changedTouches,
|
||||
|
@ -33,18 +33,18 @@ var touchEvent = function(nodeHandle, touches, changedTouches) {
|
|||
};
|
||||
};
|
||||
|
||||
var subsequence = function(arr, indices) {
|
||||
var ret = [];
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
var index = indices[i];
|
||||
const subsequence = function(arr, indices) {
|
||||
const ret = [];
|
||||
for (let i = 0; i < indices.length; i++) {
|
||||
const index = indices[i];
|
||||
ret.push(arr[index]);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
var antiSubsequence = function(arr, indices) {
|
||||
var ret = [];
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
const antiSubsequence = function(arr, indices) {
|
||||
const ret = [];
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (indices.indexOf(i) === -1) {
|
||||
ret.push(arr[i]);
|
||||
}
|
||||
|
@ -56,16 +56,16 @@ var antiSubsequence = function(arr, indices) {
|
|||
* Helper for creating touch test config data.
|
||||
* @param allTouchHandles
|
||||
*/
|
||||
var _touchConfig = function(
|
||||
const _touchConfig = function(
|
||||
topType,
|
||||
targetNodeHandle,
|
||||
allTouchHandles,
|
||||
changedIndices,
|
||||
eventTarget,
|
||||
) {
|
||||
var allTouchObjects = allTouchHandles.map(touch);
|
||||
var changedTouchObjects = subsequence(allTouchObjects, changedIndices);
|
||||
var activeTouchObjects = topType === 'topTouchStart'
|
||||
const allTouchObjects = allTouchHandles.map(touch);
|
||||
const changedTouchObjects = subsequence(allTouchObjects, changedIndices);
|
||||
const activeTouchObjects = topType === 'topTouchStart'
|
||||
? allTouchObjects
|
||||
: topType === 'topTouchMove'
|
||||
? allTouchObjects
|
||||
|
@ -104,7 +104,7 @@ var _touchConfig = function(
|
|||
* @return {object} Config data used by test cases for extracting responder
|
||||
* events.
|
||||
*/
|
||||
var startConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
||||
const startConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
||||
return _touchConfig(
|
||||
'topTouchStart',
|
||||
nodeHandle,
|
||||
|
@ -117,7 +117,7 @@ var startConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
|||
/**
|
||||
* @see `startConfig`
|
||||
*/
|
||||
var moveConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
||||
const moveConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
||||
return _touchConfig(
|
||||
'topTouchMove',
|
||||
nodeHandle,
|
||||
|
@ -130,7 +130,7 @@ var moveConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
|||
/**
|
||||
* @see `startConfig`
|
||||
*/
|
||||
var endConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
||||
const endConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
||||
return _touchConfig(
|
||||
'topTouchEnd',
|
||||
nodeHandle,
|
||||
|
@ -167,9 +167,9 @@ var endConfig = function(nodeHandle, allTouchHandles, changedIndices) {
|
|||
* ever invoked).
|
||||
*
|
||||
*/
|
||||
var NA = -1;
|
||||
var oneEventLoopTestConfig = function(readableIDToID) {
|
||||
var ret = {
|
||||
const NA = -1;
|
||||
const oneEventLoopTestConfig = function(readableIDToID) {
|
||||
const ret = {
|
||||
// Negotiation
|
||||
scrollShouldSetResponder: {bubbled: {}, captured: {}},
|
||||
startShouldSetResponder: {bubbled: {}, captured: {}},
|
||||
|
@ -185,8 +185,8 @@ var oneEventLoopTestConfig = function(readableIDToID) {
|
|||
responderEnd: {},
|
||||
responderRelease: {},
|
||||
};
|
||||
for (var eventName in ret) {
|
||||
for (var readableNodeName in readableIDToID) {
|
||||
for (const eventName in ret) {
|
||||
for (const readableNodeName in readableIDToID) {
|
||||
if (ret[eventName].bubbled) {
|
||||
// Two phase
|
||||
ret[eventName].bubbled[readableNodeName] = {
|
||||
|
@ -215,9 +215,9 @@ var oneEventLoopTestConfig = function(readableIDToID) {
|
|||
* @param {object} eventTestConfig
|
||||
* @param {object} readableIDToID
|
||||
*/
|
||||
var registerTestHandlers = function(eventTestConfig, readableIDToID) {
|
||||
var runs = {dispatchCount: 0};
|
||||
var neverFire = function(readableID, registrationName) {
|
||||
const registerTestHandlers = function(eventTestConfig, readableIDToID) {
|
||||
const runs = {dispatchCount: 0};
|
||||
const neverFire = function(readableID, registrationName) {
|
||||
runs.dispatchCount++;
|
||||
expect('').toBe(
|
||||
'Event type: ' +
|
||||
|
@ -230,11 +230,11 @@ var registerTestHandlers = function(eventTestConfig, readableIDToID) {
|
|||
);
|
||||
};
|
||||
|
||||
var registerOneEventType = function(registrationName, eventTypeTestConfig) {
|
||||
for (var readableID in eventTypeTestConfig) {
|
||||
var nodeConfig = eventTypeTestConfig[readableID];
|
||||
var id = readableIDToID[readableID];
|
||||
var handler = nodeConfig.order === NA
|
||||
const registerOneEventType = function(registrationName, eventTypeTestConfig) {
|
||||
for (const readableID in eventTypeTestConfig) {
|
||||
const nodeConfig = eventTypeTestConfig[readableID];
|
||||
const id = readableIDToID[readableID];
|
||||
const handler = nodeConfig.order === NA
|
||||
? neverFire.bind(null, readableID, registrationName)
|
||||
: // We partially apply readableID and nodeConfig, as they change in the
|
||||
// parent closure across iterations.
|
||||
|
@ -250,9 +250,9 @@ var registerTestHandlers = function(eventTestConfig, readableIDToID) {
|
|||
putListener(getInstanceFromNode(id), registrationName, handler);
|
||||
}
|
||||
};
|
||||
for (var eventName in eventTestConfig) {
|
||||
var oneEventTypeTestConfig = eventTestConfig[eventName];
|
||||
var hasTwoPhase = !!oneEventTypeTestConfig.bubbled;
|
||||
for (const eventName in eventTestConfig) {
|
||||
const oneEventTypeTestConfig = eventTestConfig[eventName];
|
||||
const hasTwoPhase = !!oneEventTypeTestConfig.bubbled;
|
||||
if (hasTwoPhase) {
|
||||
registerOneEventType(
|
||||
ResponderEventPlugin.eventTypes[eventName].phasedRegistrationNames
|
||||
|
@ -274,16 +274,16 @@ var registerTestHandlers = function(eventTestConfig, readableIDToID) {
|
|||
return runs;
|
||||
};
|
||||
|
||||
var run = function(config, hierarchyConfig, nativeEventConfig) {
|
||||
var max = NA;
|
||||
var searchForMax = function(nodeConfig) {
|
||||
for (var readableID in nodeConfig) {
|
||||
var order = nodeConfig[readableID].order;
|
||||
const run = function(config, hierarchyConfig, nativeEventConfig) {
|
||||
let max = NA;
|
||||
const searchForMax = function(nodeConfig) {
|
||||
for (const readableID in nodeConfig) {
|
||||
const order = nodeConfig[readableID].order;
|
||||
max = order > max ? order : max;
|
||||
}
|
||||
};
|
||||
for (var eventName in config) {
|
||||
var eventConfig = config[eventName];
|
||||
for (const eventName in config) {
|
||||
const eventConfig = config[eventName];
|
||||
if (eventConfig.bubbled) {
|
||||
searchForMax(eventConfig.bubbled);
|
||||
searchForMax(eventConfig.captured);
|
||||
|
@ -293,10 +293,10 @@ var run = function(config, hierarchyConfig, nativeEventConfig) {
|
|||
}
|
||||
|
||||
// Register the handlers
|
||||
var runData = registerTestHandlers(config, hierarchyConfig);
|
||||
const runData = registerTestHandlers(config, hierarchyConfig);
|
||||
|
||||
// Trigger the event
|
||||
var extractedEvents = ResponderEventPlugin.extractEvents(
|
||||
const extractedEvents = ResponderEventPlugin.extractEvents(
|
||||
nativeEventConfig.topLevelType,
|
||||
nativeEventConfig.targetInst,
|
||||
nativeEventConfig.nativeEvent,
|
||||
|
@ -315,32 +315,32 @@ var run = function(config, hierarchyConfig, nativeEventConfig) {
|
|||
); // +1 for extra ++
|
||||
};
|
||||
|
||||
var GRANDPARENT_HOST_NODE = {};
|
||||
var PARENT_HOST_NODE = {};
|
||||
var CHILD_HOST_NODE = {};
|
||||
var CHILD_HOST_NODE2 = {};
|
||||
const GRANDPARENT_HOST_NODE = {};
|
||||
const PARENT_HOST_NODE = {};
|
||||
const CHILD_HOST_NODE = {};
|
||||
const CHILD_HOST_NODE2 = {};
|
||||
|
||||
// These intentionally look like Fibers. ReactTreeTraversal depends on their field names.
|
||||
// TODO: we could test this with regular DOM nodes (and real fibers) instead.
|
||||
var GRANDPARENT_INST = {
|
||||
const GRANDPARENT_INST = {
|
||||
return: null,
|
||||
tag: HostComponent,
|
||||
stateNode: GRANDPARENT_HOST_NODE,
|
||||
memoizedProps: {},
|
||||
};
|
||||
var PARENT_INST = {
|
||||
const PARENT_INST = {
|
||||
return: GRANDPARENT_INST,
|
||||
tag: HostComponent,
|
||||
stateNode: PARENT_HOST_NODE,
|
||||
memoizedProps: {},
|
||||
};
|
||||
var CHILD_INST = {
|
||||
const CHILD_INST = {
|
||||
return: PARENT_INST,
|
||||
tag: HostComponent,
|
||||
stateNode: CHILD_HOST_NODE,
|
||||
memoizedProps: {},
|
||||
};
|
||||
var CHILD_INST2 = {
|
||||
const CHILD_INST2 = {
|
||||
return: PARENT_INST,
|
||||
tag: HostComponent,
|
||||
stateNode: CHILD_HOST_NODE2,
|
||||
|
@ -352,13 +352,13 @@ PARENT_HOST_NODE.testInstance = PARENT_INST;
|
|||
CHILD_HOST_NODE.testInstance = CHILD_INST;
|
||||
CHILD_HOST_NODE2.testInstance = CHILD_INST2;
|
||||
|
||||
var three = {
|
||||
const three = {
|
||||
grandParent: GRANDPARENT_HOST_NODE,
|
||||
parent: PARENT_HOST_NODE,
|
||||
child: CHILD_HOST_NODE,
|
||||
};
|
||||
|
||||
var siblings = {
|
||||
const siblings = {
|
||||
parent: PARENT_HOST_NODE,
|
||||
childOne: CHILD_HOST_NODE,
|
||||
childTwo: CHILD_HOST_NODE2,
|
||||
|
@ -411,7 +411,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should do nothing when no one wants to respond', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -448,7 +448,7 @@ describe('ResponderEventPlugin', () => {
|
|||
*/
|
||||
|
||||
it('should grant responder grandParent while capturing', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: true,
|
||||
|
@ -468,7 +468,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder parent while capturing', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -492,7 +492,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder child while capturing', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -517,7 +517,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder child while bubbling', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -546,7 +546,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder parent while bubbling', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -576,7 +576,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder grandParent while bubbling', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -618,7 +618,7 @@ describe('ResponderEventPlugin', () => {
|
|||
*/
|
||||
|
||||
it('should grant responder grandParent while capturing move', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
|
||||
config.startShouldSetResponder.captured.grandParent = {order: 0};
|
||||
config.startShouldSetResponder.captured.parent = {order: 1};
|
||||
|
@ -648,7 +648,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder parent while capturing move', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
|
||||
config.startShouldSetResponder.captured.grandParent = {order: 0};
|
||||
config.startShouldSetResponder.captured.parent = {order: 1};
|
||||
|
@ -679,7 +679,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder child while capturing move', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
|
||||
config.startShouldSetResponder.captured.grandParent = {order: 0};
|
||||
config.startShouldSetResponder.captured.parent = {order: 1};
|
||||
|
@ -714,7 +714,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder child while bubbling move', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
|
||||
config.startShouldSetResponder.captured.grandParent = {order: 0};
|
||||
config.startShouldSetResponder.captured.parent = {order: 1};
|
||||
|
@ -750,7 +750,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder parent while bubbling move', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
|
||||
config.startShouldSetResponder.captured.grandParent = {order: 0};
|
||||
config.startShouldSetResponder.captured.parent = {order: 1};
|
||||
|
@ -787,7 +787,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should grant responder grandParent while bubbling move', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
|
||||
config.startShouldSetResponder.captured.grandParent = {order: 0};
|
||||
config.startShouldSetResponder.captured.parent = {order: 1};
|
||||
|
@ -833,7 +833,7 @@ describe('ResponderEventPlugin', () => {
|
|||
*/
|
||||
|
||||
it('should bubble negotiation to first common ancestor of responder', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -875,7 +875,7 @@ describe('ResponderEventPlugin', () => {
|
|||
});
|
||||
|
||||
it('should bubble negotiation to first common ancestor of responder then transfer', () => {
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -932,7 +932,7 @@ describe('ResponderEventPlugin', () => {
|
|||
*/
|
||||
it('should negotiate with deepest target on second touch if nothing is responder', () => {
|
||||
// Initially nothing wants to become the responder
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -1080,7 +1080,7 @@ describe('ResponderEventPlugin', () => {
|
|||
*/
|
||||
it('should negotiate until first common ancestor when there are siblings', () => {
|
||||
// Initially nothing wants to become the responder
|
||||
var config = oneEventLoopTestConfig(siblings);
|
||||
let config = oneEventLoopTestConfig(siblings);
|
||||
config.startShouldSetResponder.captured.parent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -1119,7 +1119,7 @@ describe('ResponderEventPlugin', () => {
|
|||
};
|
||||
config.responderStart.childOne = {order: 2};
|
||||
|
||||
var touchConfig = startConfig(
|
||||
const touchConfig = startConfig(
|
||||
siblings.childTwo,
|
||||
[siblings.childOne, siblings.childTwo],
|
||||
[1],
|
||||
|
@ -1174,7 +1174,7 @@ describe('ResponderEventPlugin', () => {
|
|||
|
||||
it('should notify of being rejected. responderStart/Move happens on current responder', () => {
|
||||
// Initially nothing wants to become the responder
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -1213,7 +1213,7 @@ describe('ResponderEventPlugin', () => {
|
|||
// The start/move should occur on the original responder if new one is rejected
|
||||
config.responderMove.child = {order: 6};
|
||||
|
||||
var touchConfig = moveConfig(three.child, [three.child], [0]);
|
||||
let touchConfig = moveConfig(three.child, [three.child], [0]);
|
||||
run(config, three, touchConfig);
|
||||
expect(ResponderEventPlugin._getResponder()).toBe(
|
||||
getInstanceFromNode(three.child),
|
||||
|
@ -1244,7 +1244,7 @@ describe('ResponderEventPlugin', () => {
|
|||
|
||||
it('should negotiate scroll', () => {
|
||||
// Initially nothing wants to become the responder
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -1325,7 +1325,7 @@ describe('ResponderEventPlugin', () => {
|
|||
|
||||
it('should cancel correctly', () => {
|
||||
// Initially our child becomes responder
|
||||
var config = oneEventLoopTestConfig(three);
|
||||
let config = oneEventLoopTestConfig(three);
|
||||
config.startShouldSetResponder.captured.grandParent = {
|
||||
order: 0,
|
||||
returnVal: false,
|
||||
|
@ -1351,7 +1351,7 @@ describe('ResponderEventPlugin', () => {
|
|||
config.responderEnd.child = {order: 0};
|
||||
config.responderTerminate.child = {order: 1};
|
||||
|
||||
var nativeEvent = _touchConfig(
|
||||
const nativeEvent = _touchConfig(
|
||||
'topTouchCancel',
|
||||
three.child,
|
||||
[three.child],
|
||||
|
@ -1364,10 +1364,10 @@ describe('ResponderEventPlugin', () => {
|
|||
it('should determine the first common ancestor correctly', () => {
|
||||
// This test was moved here from the ReactTreeTraversal test since only the
|
||||
// ResponderEventPlugin uses `getLowestCommonAncestor`
|
||||
var React = require('react');
|
||||
var ReactTestUtils = require('react-dom/test-utils');
|
||||
var ReactTreeTraversal = require('shared/ReactTreeTraversal');
|
||||
var ReactDOMComponentTree = require('../../react-dom/src/client/ReactDOMComponentTree');
|
||||
const React = require('react');
|
||||
const ReactTestUtils = require('react-dom/test-utils');
|
||||
const ReactTreeTraversal = require('shared/ReactTreeTraversal');
|
||||
const ReactDOMComponentTree = require('../../react-dom/src/client/ReactDOMComponentTree');
|
||||
|
||||
class ChildComponent extends React.Component {
|
||||
render() {
|
||||
|
@ -1394,9 +1394,9 @@ describe('ResponderEventPlugin', () => {
|
|||
}
|
||||
}
|
||||
|
||||
var parent = ReactTestUtils.renderIntoDocument(<ParentComponent />);
|
||||
const parent = ReactTestUtils.renderIntoDocument(<ParentComponent />);
|
||||
|
||||
var ancestors = [
|
||||
const ancestors = [
|
||||
// Common ancestor with self is self.
|
||||
{
|
||||
one: parent.refs.P_P1_C1.refs.DIV_1,
|
||||
|
@ -1436,10 +1436,10 @@ describe('ResponderEventPlugin', () => {
|
|||
com: parent.refs.P,
|
||||
},
|
||||
];
|
||||
var i;
|
||||
let i;
|
||||
for (i = 0; i < ancestors.length; i++) {
|
||||
var plan = ancestors[i];
|
||||
var firstCommon = ReactTreeTraversal.getLowestCommonAncestor(
|
||||
const plan = ancestors[i];
|
||||
const firstCommon = ReactTreeTraversal.getLowestCommonAncestor(
|
||||
ReactDOMComponentTree.getInstanceFromNode(plan.one),
|
||||
ReactDOMComponentTree.getInstanceFromNode(plan.two),
|
||||
);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var accumulateInto;
|
||||
let accumulateInto;
|
||||
|
||||
describe('accumulateInto', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -25,23 +25,23 @@ describe('accumulateInto', () => {
|
|||
});
|
||||
|
||||
it('returns the second item if first is null', () => {
|
||||
var a = [];
|
||||
const a = [];
|
||||
expect(accumulateInto(null, a)).toBe(a);
|
||||
});
|
||||
|
||||
it('merges the second into the first if first item is an array', () => {
|
||||
var a = [1, 2];
|
||||
var b = [3, 4];
|
||||
const a = [1, 2];
|
||||
const b = [3, 4];
|
||||
accumulateInto(a, b);
|
||||
expect(a).toEqual([1, 2, 3, 4]);
|
||||
expect(b).toEqual([3, 4]);
|
||||
var c = [1];
|
||||
const c = [1];
|
||||
accumulateInto(c, 2);
|
||||
expect(c).toEqual([1, 2]);
|
||||
});
|
||||
|
||||
it('returns a new array if first or both items are scalar', () => {
|
||||
var a = [2];
|
||||
const a = [2];
|
||||
expect(accumulateInto(1, a)).toEqual([1, 2]);
|
||||
expect(a).toEqual([2]);
|
||||
expect(accumulateInto(1, 2)).toEqual([1, 2]);
|
||||
|
|
Loading…
Reference in New Issue