code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function includesSomeLane(a, b) { return (a & b) !== NoLanes; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
includesSomeLane
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isSubsetOfLanes(set, subset) { return (set & subset) === subset; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
isSubsetOfLanes
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function mergeLanes(a, b) { return a | b; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
mergeLanes
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function removeLanes(set, subset) { return set & ~subset; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
removeLanes
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function intersectLanes(a, b) { return a & b; } // Seems redundant, but it changes the type from a single lane (used for
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
intersectLanes
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function laneToLanes(lane) { return lane; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
laneToLanes
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function higherPriorityLane(a, b) { // This works because the bit ranges decrease in priority as you go left. return a !== NoLane && a < b ? a : b; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
higherPriorityLane
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function createLaneMap(initial) { // Intentionally pushing one by one. // https://v8.dev/blog/elements-kinds#avoid-creating-holes var laneMap = []; for (var i = 0; i < TotalLanes; i++) { laneMap.push(initial); } return laneMap; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
createLaneMap
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function markRootUpdated(root, updateLane, eventTime) { root.pendingLanes |= updateLane; // If there are any suspended transitions, it's possible this new update // could unblock them. Clear the suspended lanes so that we can try rendering // them again. // // TODO: We really only need to unsuspend only lanes that are in the // `subtreeLanes` of the updated fiber, or the update lanes of the return // path. This would exclude suspended updates in an unrelated sibling tree, // since there's no way for this update to unblock it. // // We don't do this if the incoming update is idle, because we never process // idle updates until after all the regular updates have finished; there's no // way it could unblock a transition. if (updateLane !== IdleLane) { root.suspendedLanes = NoLanes; root.pingedLanes = NoLanes; } var eventTimes = root.eventTimes; var index = laneToIndex(updateLane); // We can always overwrite an existing timestamp because we prefer the most // recent event, and we assume time is monotonically increasing. eventTimes[index] = eventTime; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
markRootUpdated
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function markRootSuspended(root, suspendedLanes) { root.suspendedLanes |= suspendedLanes; root.pingedLanes &= ~suspendedLanes; // The suspended lanes are no longer CPU-bound. Clear their expiration times. var expirationTimes = root.expirationTimes; var lanes = suspendedLanes; while (lanes > 0) { var index = pickArbitraryLaneIndex(lanes); var lane = 1 << index; expirationTimes[index] = NoTimestamp; lanes &= ~lane; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
markRootSuspended
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function markRootPinged(root, pingedLanes, eventTime) { root.pingedLanes |= root.suspendedLanes & pingedLanes; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
markRootPinged
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function markRootFinished(root, remainingLanes) { var noLongerPendingLanes = root.pendingLanes & ~remainingLanes; root.pendingLanes = remainingLanes; // Let's try everything again root.suspendedLanes = NoLanes; root.pingedLanes = NoLanes; root.expiredLanes &= remainingLanes; root.mutableReadLanes &= remainingLanes; root.entangledLanes &= remainingLanes; var entanglements = root.entanglements; var eventTimes = root.eventTimes; var expirationTimes = root.expirationTimes; // Clear the lanes that no longer have pending work var lanes = noLongerPendingLanes; while (lanes > 0) { var index = pickArbitraryLaneIndex(lanes); var lane = 1 << index; entanglements[index] = NoLanes; eventTimes[index] = NoTimestamp; expirationTimes[index] = NoTimestamp; lanes &= ~lane; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
markRootFinished
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function markRootEntangled(root, entangledLanes) { // In addition to entangling each of the given lanes with each other, we also // have to consider _transitive_ entanglements. For each lane that is already // entangled with *any* of the given lanes, that lane is now transitively // entangled with *all* the given lanes. // // Translated: If C is entangled with A, then entangling A with B also // entangles C with B. // // If this is hard to grasp, it might help to intentionally break this // function and look at the tests that fail in ReactTransition-test.js. Try // commenting out one of the conditions below. var rootEntangledLanes = root.entangledLanes |= entangledLanes; var entanglements = root.entanglements; var lanes = rootEntangledLanes; while (lanes) { var index = pickArbitraryLaneIndex(lanes); var lane = 1 << index; if ( // Is this one of the newly entangled lanes? lane & entangledLanes | // Is this lane transitively entangled with the newly entangled lanes? entanglements[index] & entangledLanes) { entanglements[index] |= entangledLanes; } lanes &= ~lane; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
markRootEntangled
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getBumpedLaneForHydration(root, renderLanes) { var renderLane = getHighestPriorityLane(renderLanes); var lane; switch (renderLane) { case InputContinuousLane: lane = InputContinuousHydrationLane; break; case DefaultLane: lane = DefaultHydrationLane; break; case TransitionLane1: case TransitionLane2: case TransitionLane3: case TransitionLane4: case TransitionLane5: case TransitionLane6: case TransitionLane7: case TransitionLane8: case TransitionLane9: case TransitionLane10: case TransitionLane11: case TransitionLane12: case TransitionLane13: case TransitionLane14: case TransitionLane15: case TransitionLane16: case RetryLane1: case RetryLane2: case RetryLane3: case RetryLane4: case RetryLane5: lane = TransitionHydrationLane; break; case IdleLane: lane = IdleHydrationLane; break; default: // Everything else is already either a hydration lane, or shouldn't // be retried at a hydration lane. lane = NoLane; break; } // Check if the lane we chose is suspended. If so, that indicates that we // already attempted and failed to hydrate at that level. Also check if we're // already rendering that lane, which is rare but could happen. if ((lane & (root.suspendedLanes | renderLanes)) !== NoLane) { // Give up trying to hydrate and fall back to client render. return NoLane; } return lane; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
getBumpedLaneForHydration
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function addFiberToLanesMap(root, fiber, lanes) { if (!isDevToolsPresent) { return; } var pendingUpdatersLaneMap = root.pendingUpdatersLaneMap; while (lanes > 0) { var index = laneToIndex(lanes); var lane = 1 << index; var updaters = pendingUpdatersLaneMap[index]; updaters.add(fiber); lanes &= ~lane; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
addFiberToLanesMap
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function movePendingFibersToMemoized(root, lanes) { if (!isDevToolsPresent) { return; } var pendingUpdatersLaneMap = root.pendingUpdatersLaneMap; var memoizedUpdaters = root.memoizedUpdaters; while (lanes > 0) { var index = laneToIndex(lanes); var lane = 1 << index; var updaters = pendingUpdatersLaneMap[index]; if (updaters.size > 0) { updaters.forEach(function (fiber) { var alternate = fiber.alternate; if (alternate === null || !memoizedUpdaters.has(alternate)) { memoizedUpdaters.add(fiber); } }); updaters.clear(); } lanes &= ~lane; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
movePendingFibersToMemoized
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getTransitionsForLanes(root, lanes) { { return null; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
getTransitionsForLanes
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getCurrentUpdatePriority() { return currentUpdatePriority; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
getCurrentUpdatePriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function setCurrentUpdatePriority(newPriority) { currentUpdatePriority = newPriority; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
setCurrentUpdatePriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function runWithPriority(priority, fn) { var previousPriority = currentUpdatePriority; try { currentUpdatePriority = priority; return fn(); } finally { currentUpdatePriority = previousPriority; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
runWithPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function higherEventPriority(a, b) { return a !== 0 && a < b ? a : b; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
higherEventPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function lowerEventPriority(a, b) { return a === 0 || a > b ? a : b; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
lowerEventPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isHigherEventPriority(a, b) { return a !== 0 && a < b; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
isHigherEventPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function lanesToEventPriority(lanes) { var lane = getHighestPriorityLane(lanes); if (!isHigherEventPriority(DiscreteEventPriority, lane)) { return DiscreteEventPriority; } if (!isHigherEventPriority(ContinuousEventPriority, lane)) { return ContinuousEventPriority; } if (includesNonIdleWork(lane)) { return DefaultEventPriority; } return IdleEventPriority; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
lanesToEventPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isRootDehydrated(root) { var currentState = root.current.memoizedState; return currentState.isDehydrated; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
isRootDehydrated
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function setAttemptSynchronousHydration(fn) { _attemptSynchronousHydration = fn; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
setAttemptSynchronousHydration
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function setAttemptContinuousHydration(fn) { attemptContinuousHydration = fn; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
setAttemptContinuousHydration
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function setAttemptHydrationAtCurrentPriority(fn) { attemptHydrationAtCurrentPriority = fn; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
setAttemptHydrationAtCurrentPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function setGetCurrentUpdatePriority(fn) { getCurrentUpdatePriority$1 = fn; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
setGetCurrentUpdatePriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function setAttemptHydrationAtPriority(fn) { attemptHydrationAtPriority = fn; } // TODO: Upgrade this definition once we're on a newer version of Flow that
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
setAttemptHydrationAtPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isDiscreteEventThatRequiresHydration(eventType) { return discreteReplayableEvents.indexOf(eventType) > -1; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
isDiscreteEventThatRequiresHydration
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function createQueuedReplayableEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) { return { blockedOn: blockedOn, domEventName: domEventName, eventSystemFlags: eventSystemFlags, nativeEvent: nativeEvent, targetContainers: [targetContainer] }; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
createQueuedReplayableEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function clearIfContinuousEvent(domEventName, nativeEvent) { switch (domEventName) { case 'focusin': case 'focusout': queuedFocus = null; break; case 'dragenter': case 'dragleave': queuedDrag = null; break; case 'mouseover': case 'mouseout': queuedMouse = null; break; case 'pointerover': case 'pointerout': { var pointerId = nativeEvent.pointerId; queuedPointers.delete(pointerId); break; } case 'gotpointercapture': case 'lostpointercapture': { var _pointerId = nativeEvent.pointerId; queuedPointerCaptures.delete(_pointerId); break; } } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
clearIfContinuousEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function accumulateOrCreateContinuousQueuedReplayableEvent(existingQueuedEvent, blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) { if (existingQueuedEvent === null || existingQueuedEvent.nativeEvent !== nativeEvent) { var queuedEvent = createQueuedReplayableEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent); if (blockedOn !== null) { var _fiber2 = getInstanceFromNode(blockedOn); if (_fiber2 !== null) { // Attempt to increase the priority of this target. attemptContinuousHydration(_fiber2); } } return queuedEvent; } // If we have already queued this exact event, then it's because // the different event systems have different DOM event listeners. // We can accumulate the flags, and the targetContainers, and // store a single event to be replayed. existingQueuedEvent.eventSystemFlags |= eventSystemFlags; var targetContainers = existingQueuedEvent.targetContainers; if (targetContainer !== null && targetContainers.indexOf(targetContainer) === -1) { targetContainers.push(targetContainer); } return existingQueuedEvent; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
accumulateOrCreateContinuousQueuedReplayableEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function queueIfContinuousEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent) { // These set relatedTarget to null because the replayed event will be treated as if we // moved from outside the window (no target) onto the target once it hydrates. // Instead of mutating we could clone the event. switch (domEventName) { case 'focusin': { var focusEvent = nativeEvent; queuedFocus = accumulateOrCreateContinuousQueuedReplayableEvent(queuedFocus, blockedOn, domEventName, eventSystemFlags, targetContainer, focusEvent); return true; } case 'dragenter': { var dragEvent = nativeEvent; queuedDrag = accumulateOrCreateContinuousQueuedReplayableEvent(queuedDrag, blockedOn, domEventName, eventSystemFlags, targetContainer, dragEvent); return true; } case 'mouseover': { var mouseEvent = nativeEvent; queuedMouse = accumulateOrCreateContinuousQueuedReplayableEvent(queuedMouse, blockedOn, domEventName, eventSystemFlags, targetContainer, mouseEvent); return true; } case 'pointerover': { var pointerEvent = nativeEvent; var pointerId = pointerEvent.pointerId; queuedPointers.set(pointerId, accumulateOrCreateContinuousQueuedReplayableEvent(queuedPointers.get(pointerId) || null, blockedOn, domEventName, eventSystemFlags, targetContainer, pointerEvent)); return true; } case 'gotpointercapture': { var _pointerEvent = nativeEvent; var _pointerId2 = _pointerEvent.pointerId; queuedPointerCaptures.set(_pointerId2, accumulateOrCreateContinuousQueuedReplayableEvent(queuedPointerCaptures.get(_pointerId2) || null, blockedOn, domEventName, eventSystemFlags, targetContainer, _pointerEvent)); return true; } } return false; } // Check if this target is unblocked. Returns true if it's unblocked.
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
queueIfContinuousEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function attemptExplicitHydrationTarget(queuedTarget) { // TODO: This function shares a lot of logic with findInstanceBlockingEvent. // Try to unify them. It's a bit tricky since it would require two return // values. var targetInst = getClosestInstanceFromNode(queuedTarget.target); if (targetInst !== null) { var nearestMounted = getNearestMountedFiber(targetInst); if (nearestMounted !== null) { var tag = nearestMounted.tag; if (tag === SuspenseComponent) { var instance = getSuspenseInstanceFromFiber(nearestMounted); if (instance !== null) { // We're blocked on hydrating this boundary. // Increase its priority. queuedTarget.blockedOn = instance; attemptHydrationAtPriority(queuedTarget.priority, function () { attemptHydrationAtCurrentPriority(nearestMounted); }); return; } } else if (tag === HostRoot) { var root = nearestMounted.stateNode; if (isRootDehydrated(root)) { queuedTarget.blockedOn = getContainerFromFiber(nearestMounted); // We don't currently have a way to increase the priority of // a root other than sync. return; } } } } queuedTarget.blockedOn = null; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
attemptExplicitHydrationTarget
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function queueExplicitHydrationTarget(target) { // TODO: This will read the priority if it's dispatched by the React // event system but not native events. Should read window.event.type, like // we do for updates (getCurrentEventPriority). var updatePriority = getCurrentUpdatePriority$1(); var queuedTarget = { blockedOn: null, target: target, priority: updatePriority }; var i = 0; for (; i < queuedExplicitHydrationTargets.length; i++) { // Stop once we hit the first target with lower priority than if (!isHigherEventPriority(updatePriority, queuedExplicitHydrationTargets[i].priority)) { break; } } queuedExplicitHydrationTargets.splice(i, 0, queuedTarget); if (i === 0) { attemptExplicitHydrationTarget(queuedTarget); } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
queueExplicitHydrationTarget
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function attemptReplayContinuousQueuedEvent(queuedEvent) { if (queuedEvent.blockedOn !== null) { return false; } var targetContainers = queuedEvent.targetContainers; while (targetContainers.length > 0) { var targetContainer = targetContainers[0]; var nextBlockedOn = findInstanceBlockingEvent(queuedEvent.domEventName, queuedEvent.eventSystemFlags, targetContainer, queuedEvent.nativeEvent); if (nextBlockedOn === null) { { var nativeEvent = queuedEvent.nativeEvent; var nativeEventClone = new nativeEvent.constructor(nativeEvent.type, nativeEvent); setReplayingEvent(nativeEventClone); nativeEvent.target.dispatchEvent(nativeEventClone); resetReplayingEvent(); } } else { // We're still blocked. Try again later. var _fiber3 = getInstanceFromNode(nextBlockedOn); if (_fiber3 !== null) { attemptContinuousHydration(_fiber3); } queuedEvent.blockedOn = nextBlockedOn; return false; } // This target container was successfully dispatched. Try the next. targetContainers.shift(); } return true; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
attemptReplayContinuousQueuedEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function attemptReplayContinuousQueuedEventInMap(queuedEvent, key, map) { if (attemptReplayContinuousQueuedEvent(queuedEvent)) { map.delete(key); } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
attemptReplayContinuousQueuedEventInMap
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function replayUnblockedEvents() { hasScheduledReplayAttempt = false; if (queuedFocus !== null && attemptReplayContinuousQueuedEvent(queuedFocus)) { queuedFocus = null; } if (queuedDrag !== null && attemptReplayContinuousQueuedEvent(queuedDrag)) { queuedDrag = null; } if (queuedMouse !== null && attemptReplayContinuousQueuedEvent(queuedMouse)) { queuedMouse = null; } queuedPointers.forEach(attemptReplayContinuousQueuedEventInMap); queuedPointerCaptures.forEach(attemptReplayContinuousQueuedEventInMap); }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
replayUnblockedEvents
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function scheduleCallbackIfUnblocked(queuedEvent, unblocked) { if (queuedEvent.blockedOn === unblocked) { queuedEvent.blockedOn = null; if (!hasScheduledReplayAttempt) { hasScheduledReplayAttempt = true; // Schedule a callback to attempt replaying as many events as are // now unblocked. This first might not actually be unblocked yet. // We could check it early to avoid scheduling an unnecessary callback. unstable_scheduleCallback(unstable_NormalPriority, replayUnblockedEvents); } } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
scheduleCallbackIfUnblocked
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function retryIfBlockedOn(unblocked) { // Mark anything that was blocked on this as no longer blocked // and eligible for a replay. if (queuedDiscreteEvents.length > 0) { scheduleCallbackIfUnblocked(queuedDiscreteEvents[0], unblocked); // This is a exponential search for each boundary that commits. I think it's // worth it because we expect very few discrete events to queue up and once // we are actually fully unblocked it will be fast to replay them. for (var i = 1; i < queuedDiscreteEvents.length; i++) { var queuedEvent = queuedDiscreteEvents[i]; if (queuedEvent.blockedOn === unblocked) { queuedEvent.blockedOn = null; } } } if (queuedFocus !== null) { scheduleCallbackIfUnblocked(queuedFocus, unblocked); } if (queuedDrag !== null) { scheduleCallbackIfUnblocked(queuedDrag, unblocked); } if (queuedMouse !== null) { scheduleCallbackIfUnblocked(queuedMouse, unblocked); } var unblock = function (queuedEvent) { return scheduleCallbackIfUnblocked(queuedEvent, unblocked); }; queuedPointers.forEach(unblock); queuedPointerCaptures.forEach(unblock); for (var _i = 0; _i < queuedExplicitHydrationTargets.length; _i++) { var queuedTarget = queuedExplicitHydrationTargets[_i]; if (queuedTarget.blockedOn === unblocked) { queuedTarget.blockedOn = null; } } while (queuedExplicitHydrationTargets.length > 0) { var nextExplicitTarget = queuedExplicitHydrationTargets[0]; if (nextExplicitTarget.blockedOn !== null) { // We're still blocked. break; } else { attemptExplicitHydrationTarget(nextExplicitTarget); if (nextExplicitTarget.blockedOn === null) { // We're unblocked. queuedExplicitHydrationTargets.shift(); } } } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
retryIfBlockedOn
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
unblock = function (queuedEvent) { return scheduleCallbackIfUnblocked(queuedEvent, unblocked); }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
unblock
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function setEnabled(enabled) { _enabled = !!enabled; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
setEnabled
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isEnabled() { return _enabled; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
isEnabled
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function createEventListenerWrapperWithPriority(targetContainer, domEventName, eventSystemFlags) { var eventPriority = getEventPriority(domEventName); var listenerWrapper; switch (eventPriority) { case DiscreteEventPriority: listenerWrapper = dispatchDiscreteEvent; break; case ContinuousEventPriority: listenerWrapper = dispatchContinuousEvent; break; case DefaultEventPriority: default: listenerWrapper = dispatchEvent; break; } return listenerWrapper.bind(null, domEventName, eventSystemFlags, targetContainer); }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
createEventListenerWrapperWithPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function dispatchDiscreteEvent(domEventName, eventSystemFlags, container, nativeEvent) { var previousPriority = getCurrentUpdatePriority(); var prevTransition = ReactCurrentBatchConfig.transition; ReactCurrentBatchConfig.transition = null; try { setCurrentUpdatePriority(DiscreteEventPriority); dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent); } finally { setCurrentUpdatePriority(previousPriority); ReactCurrentBatchConfig.transition = prevTransition; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
dispatchDiscreteEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function dispatchContinuousEvent(domEventName, eventSystemFlags, container, nativeEvent) { var previousPriority = getCurrentUpdatePriority(); var prevTransition = ReactCurrentBatchConfig.transition; ReactCurrentBatchConfig.transition = null; try { setCurrentUpdatePriority(ContinuousEventPriority); dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent); } finally { setCurrentUpdatePriority(previousPriority); ReactCurrentBatchConfig.transition = prevTransition; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
dispatchContinuousEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function dispatchEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent) { if (!_enabled) { return; } { dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay(domEventName, eventSystemFlags, targetContainer, nativeEvent); } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
dispatchEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay(domEventName, eventSystemFlags, targetContainer, nativeEvent) { var blockedOn = findInstanceBlockingEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent); if (blockedOn === null) { dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, return_targetInst, targetContainer); clearIfContinuousEvent(domEventName, nativeEvent); return; } if (queueIfContinuousEvent(blockedOn, domEventName, eventSystemFlags, targetContainer, nativeEvent)) { nativeEvent.stopPropagation(); return; } // We need to clear only if we didn't queue because // queueing is accumulative. clearIfContinuousEvent(domEventName, nativeEvent); if (eventSystemFlags & IS_CAPTURE_PHASE && isDiscreteEventThatRequiresHydration(domEventName)) { while (blockedOn !== null) { var fiber = getInstanceFromNode(blockedOn); if (fiber !== null) { attemptSynchronousHydration(fiber); } var nextBlockedOn = findInstanceBlockingEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent); if (nextBlockedOn === null) { dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, return_targetInst, targetContainer); } if (nextBlockedOn === blockedOn) { break; } blockedOn = nextBlockedOn; } if (blockedOn !== null) { nativeEvent.stopPropagation(); } return; } // This is not replayable so we'll invoke it but without a target, // in case the event system needs to trace it. dispatchEventForPluginEventSystem(domEventName, eventSystemFlags, nativeEvent, null, targetContainer); }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function findInstanceBlockingEvent(domEventName, eventSystemFlags, targetContainer, nativeEvent) { // TODO: Warn if _enabled is false. return_targetInst = null; var nativeEventTarget = getEventTarget(nativeEvent); var targetInst = getClosestInstanceFromNode(nativeEventTarget); if (targetInst !== null) { var nearestMounted = getNearestMountedFiber(targetInst); if (nearestMounted === null) { // This tree has been unmounted already. Dispatch without a target. targetInst = null; } else { var tag = nearestMounted.tag; if (tag === SuspenseComponent) { var instance = getSuspenseInstanceFromFiber(nearestMounted); if (instance !== null) { // Queue the event to be replayed later. Abort dispatching since we // don't want this event dispatched twice through the event system. // TODO: If this is the first discrete event in the queue. Schedule an increased // priority for this boundary. return instance; } // This shouldn't happen, something went wrong but to avoid blocking // the whole system, dispatch the event without a target. // TODO: Warn. targetInst = null; } else if (tag === HostRoot) { var root = nearestMounted.stateNode; if (isRootDehydrated(root)) { // If this happens during a replay something went wrong and it might block // the whole system. return getContainerFromFiber(nearestMounted); } targetInst = null; } else if (nearestMounted !== targetInst) { // If we get an event (ex: img onload) before committing that // component's mount, ignore it for now (that is, treat it as if it was an // event on a non-React tree). We might also consider queueing events and // dispatching them after the mount. targetInst = null; } } } return_targetInst = targetInst; // We're not blocked on anything. return null; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
findInstanceBlockingEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getEventPriority(domEventName) { switch (domEventName) { // Used by SimpleEventPlugin: case 'cancel': case 'click': case 'close': case 'contextmenu': case 'copy': case 'cut': case 'auxclick': case 'dblclick': case 'dragend': case 'dragstart': case 'drop': case 'focusin': case 'focusout': case 'input': case 'invalid': case 'keydown': case 'keypress': case 'keyup': case 'mousedown': case 'mouseup': case 'paste': case 'pause': case 'play': case 'pointercancel': case 'pointerdown': case 'pointerup': case 'ratechange': case 'reset': case 'resize': case 'seeked': case 'submit': case 'touchcancel': case 'touchend': case 'touchstart': case 'volumechange': // Used by polyfills: // eslint-disable-next-line no-fallthrough case 'change': case 'selectionchange': case 'textInput': case 'compositionstart': case 'compositionend': case 'compositionupdate': // Only enableCreateEventHandleAPI: // eslint-disable-next-line no-fallthrough case 'beforeblur': case 'afterblur': // Not used by React but could be by user code: // eslint-disable-next-line no-fallthrough case 'beforeinput': case 'blur': case 'fullscreenchange': case 'focus': case 'hashchange': case 'popstate': case 'select': case 'selectstart': return DiscreteEventPriority; case 'drag': case 'dragenter': case 'dragexit': case 'dragleave': case 'dragover': case 'mousemove': case 'mouseout': case 'mouseover': case 'pointermove': case 'pointerout': case 'pointerover': case 'scroll': case 'toggle': case 'touchmove': case 'wheel': // Not used by React but could be by user code: // eslint-disable-next-line no-fallthrough case 'mouseenter': case 'mouseleave': case 'pointerenter': case 'pointerleave': return ContinuousEventPriority; case 'message': { // We might be in the Scheduler callback. // Eventually this mechanism will be replaced by a check // of the current priority on the native scheduler. var schedulerPriority = getCurrentPriorityLevel(); switch (schedulerPriority) { case ImmediatePriority: return DiscreteEventPriority; case UserBlockingPriority: return ContinuousEventPriority; case NormalPriority: case LowPriority: // TODO: Handle LowSchedulerPriority, somehow. Maybe the same lane as hydration. return DefaultEventPriority; case IdlePriority: return IdleEventPriority; default: return DefaultEventPriority; } } default: return DefaultEventPriority; } }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
getEventPriority
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function addEventBubbleListener(target, eventType, listener) { target.addEventListener(eventType, listener, false); return listener; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
addEventBubbleListener
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function addEventCaptureListener(target, eventType, listener) { target.addEventListener(eventType, listener, true); return listener; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
addEventCaptureListener
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function addEventCaptureListenerWithPassiveFlag(target, eventType, listener, passive) { target.addEventListener(eventType, listener, { capture: true, passive: passive }); return listener; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
addEventCaptureListenerWithPassiveFlag
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function addEventBubbleListenerWithPassiveFlag(target, eventType, listener, passive) { target.addEventListener(eventType, listener, { passive: passive }); return listener; }
`ReactInstanceMap` maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods. Note that this module is currently shared and assumed to be stateless. If this becomes an actual Map, that will break.
addEventBubbleListenerWithPassiveFlag
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function initialize(nativeEventTarget) { root = nativeEventTarget; startText = getText(); return true; }
These variables store information about text content of a target node, allowing comparison of content before and after a given event. Identify the node where selection currently begins, then observe both its text content and its current position in the DOM. Since the browser may natively replace the target node during composition, we can use its position to find its replacement.
initialize
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function reset() { root = null; startText = null; fallbackText = null; }
These variables store information about text content of a target node, allowing comparison of content before and after a given event. Identify the node where selection currently begins, then observe both its text content and its current position in the DOM. Since the browser may natively replace the target node during composition, we can use its position to find its replacement.
reset
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getData() { if (fallbackText) { return fallbackText; } var start; var startValue = startText; var startLength = startValue.length; var end; var endValue = getText(); var endLength = endValue.length; for (start = 0; start < startLength; start++) { if (startValue[start] !== endValue[start]) { break; } } var minEnd = startLength - start; for (end = 1; end <= minEnd; end++) { if (startValue[startLength - end] !== endValue[endLength - end]) { break; } } var sliceTail = end > 1 ? 1 - end : undefined; fallbackText = endValue.slice(start, sliceTail); return fallbackText; }
These variables store information about text content of a target node, allowing comparison of content before and after a given event. Identify the node where selection currently begins, then observe both its text content and its current position in the DOM. Since the browser may natively replace the target node during composition, we can use its position to find its replacement.
getData
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getText() { if ('value' in root) { return root.value; } return root.textContent; }
These variables store information about text content of a target node, allowing comparison of content before and after a given event. Identify the node where selection currently begins, then observe both its text content and its current position in the DOM. Since the browser may natively replace the target node during composition, we can use its position to find its replacement.
getText
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getEventCharCode(nativeEvent) { var charCode; var keyCode = nativeEvent.keyCode; if ('charCode' in nativeEvent) { charCode = nativeEvent.charCode; // FF does not set `charCode` for the Enter-key, check against `keyCode`. if (charCode === 0 && keyCode === 13) { charCode = 13; } } else { // IE8 does not implement `charCode`, but `keyCode` has the correct value. charCode = keyCode; } // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux) // report Enter as charCode 10 when ctrl is pressed. if (charCode === 10) { charCode = 13; } // Some non-printable keys are reported in `charCode`/`keyCode`, discard them. // Must not discard the (non-)printable Enter-key. if (charCode >= 32 || charCode === 13) { return charCode; } return 0; }
`charCode` represents the actual "character code" and is safe to use with `String.fromCharCode`. As such, only keys that correspond to printable characters produce a valid `charCode`, the only exception to this is Enter. The Tab-key is considered non-printable and does not have a `charCode`, presumably because it does not produce a tab-character in browsers. @param {object} nativeEvent Native browser event. @return {number} Normalized `charCode` property.
getEventCharCode
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function functionThatReturnsTrue() { return true; }
`charCode` represents the actual "character code" and is safe to use with `String.fromCharCode`. As such, only keys that correspond to printable characters produce a valid `charCode`, the only exception to this is Enter. The Tab-key is considered non-printable and does not have a `charCode`, presumably because it does not produce a tab-character in browsers. @param {object} nativeEvent Native browser event. @return {number} Normalized `charCode` property.
functionThatReturnsTrue
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function functionThatReturnsFalse() { return false; } // This is intentionally a factory so that we have different returned constructors.
`charCode` represents the actual "character code" and is safe to use with `String.fromCharCode`. As such, only keys that correspond to printable characters produce a valid `charCode`, the only exception to this is Enter. The Tab-key is considered non-printable and does not have a `charCode`, presumably because it does not produce a tab-character in browsers. @param {object} nativeEvent Native browser event. @return {number} Normalized `charCode` property.
functionThatReturnsFalse
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function createSyntheticEvent(Interface) { /** * Synthetic events are dispatched by event plugins, typically in response to a * top-level event delegation handler. * * These systems should generally use pooling to reduce the frequency of garbage * collection. The system should check `isPersistent` to determine whether the * event should be released into the pool after being dispatched. Users that * need a persisted event should invoke `persist`. * * Synthetic events (and subclasses) implement the DOM Level 3 Events API by * normalizing browser quirks. Subclasses do not necessarily have to implement a * DOM interface; custom application-specific events can also subclass this. */ function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) { this._reactName = reactName; this._targetInst = targetInst; this.type = reactEventType; this.nativeEvent = nativeEvent; this.target = nativeEventTarget; this.currentTarget = null; for (var _propName in Interface) { if (!Interface.hasOwnProperty(_propName)) { continue; } var normalize = Interface[_propName]; if (normalize) { this[_propName] = normalize(nativeEvent); } else { this[_propName] = nativeEvent[_propName]; } } var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false; if (defaultPrevented) { this.isDefaultPrevented = functionThatReturnsTrue; } else { this.isDefaultPrevented = functionThatReturnsFalse; } this.isPropagationStopped = functionThatReturnsFalse; return this; } assign(SyntheticBaseEvent.prototype, { preventDefault: function () { this.defaultPrevented = true; var event = this.nativeEvent; if (!event) { return; } if (event.preventDefault) { event.preventDefault(); // $FlowFixMe - flow is not aware of `unknown` in IE } else if (typeof event.returnValue !== 'unknown') { event.returnValue = false; } this.isDefaultPrevented = functionThatReturnsTrue; }, stopPropagation: function () { var event = this.nativeEvent; if (!event) { return; } if (event.stopPropagation) { event.stopPropagation(); // $FlowFixMe - flow is not aware of `unknown` in IE } else if (typeof event.cancelBubble !== 'unknown') { // The ChangeEventPlugin registers a "propertychange" event for // IE. This event does not support bubbling or cancelling, and // any references to cancelBubble throw "Member not found". A // typeof check of "unknown" circumvents this issue (and is also // IE specific). event.cancelBubble = true; } this.isPropagationStopped = functionThatReturnsTrue; }, /** * We release all dispatched `SyntheticEvent`s after each event loop, adding * them back into the pool. This allows a way to hold onto a reference that * won't be added back into the pool. */ persist: function () {// Modern event system doesn't use pooling. }, /** * Checks if this event should be released back into the pool. * * @return {boolean} True if this should not be released, false otherwise. */ isPersistent: functionThatReturnsTrue }); return SyntheticBaseEvent; }
`charCode` represents the actual "character code" and is safe to use with `String.fromCharCode`. As such, only keys that correspond to printable characters produce a valid `charCode`, the only exception to this is Enter. The Tab-key is considered non-printable and does not have a `charCode`, presumably because it does not produce a tab-character in browsers. @param {object} nativeEvent Native browser event. @return {number} Normalized `charCode` property.
createSyntheticEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) { this._reactName = reactName; this._targetInst = targetInst; this.type = reactEventType; this.nativeEvent = nativeEvent; this.target = nativeEventTarget; this.currentTarget = null; for (var _propName in Interface) { if (!Interface.hasOwnProperty(_propName)) { continue; } var normalize = Interface[_propName]; if (normalize) { this[_propName] = normalize(nativeEvent); } else { this[_propName] = nativeEvent[_propName]; } } var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false; if (defaultPrevented) { this.isDefaultPrevented = functionThatReturnsTrue; } else { this.isDefaultPrevented = functionThatReturnsFalse; } this.isPropagationStopped = functionThatReturnsFalse; return this; }
Synthetic events are dispatched by event plugins, typically in response to a top-level event delegation handler. These systems should generally use pooling to reduce the frequency of garbage collection. The system should check `isPersistent` to determine whether the event should be released into the pool after being dispatched. Users that need a persisted event should invoke `persist`. Synthetic events (and subclasses) implement the DOM Level 3 Events API by normalizing browser quirks. Subclasses do not necessarily have to implement a DOM interface; custom application-specific events can also subclass this.
SyntheticBaseEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function updateMouseMovementPolyfillState(event) { if (event !== lastMouseEvent) { if (lastMouseEvent && event.type === 'mousemove') { lastMovementX = event.screenX - lastMouseEvent.screenX; lastMovementY = event.screenY - lastMouseEvent.screenY; } else { lastMovementX = 0; lastMovementY = 0; } lastMouseEvent = event; } }
@interface Event @see http://www.w3.org/TR/DOM-Level-3-Events/
updateMouseMovementPolyfillState
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getEventKey(nativeEvent) { if (nativeEvent.key) { // Normalize inconsistent values reported by browsers due to // implementations of a working draft specification. // FireFox implements `key` but returns `MozPrintableKey` for all // printable characters (normalized to `Unidentified`), ignore it. var key = normalizeKey[nativeEvent.key] || nativeEvent.key; if (key !== 'Unidentified') { return key; } } // Browser does not implement `key`, polyfill as much of it as we can. if (nativeEvent.type === 'keypress') { var charCode = getEventCharCode(nativeEvent); // The enter-key is technically both printable and non-printable and can // thus be captured by `keypress`, no other non-printable key should. return charCode === 13 ? 'Enter' : String.fromCharCode(charCode); } if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') { // While user keyboard layout determines the actual meaning of each // `keyCode` value, almost all function keys have a universal value. return translateToKey[nativeEvent.keyCode] || 'Unidentified'; } return ''; }
@param {object} nativeEvent Native browser event. @return {string} Normalized `key` property.
getEventKey
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function modifierStateGetter(keyArg) { var syntheticEvent = this; var nativeEvent = syntheticEvent.nativeEvent; if (nativeEvent.getModifierState) { return nativeEvent.getModifierState(keyArg); } var keyProp = modifierKeyToProp[keyArg]; return keyProp ? !!nativeEvent[keyProp] : false; }
Translation from modifier key to the associated property in the event. @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
modifierStateGetter
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getEventModifierState(nativeEvent) { return modifierStateGetter; }
Translation from modifier key to the associated property in the event. @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
getEventModifierState
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function registerEvents() { registerTwoPhaseEvent('onBeforeInput', ['compositionend', 'keypress', 'textInput', 'paste']); registerTwoPhaseEvent('onCompositionEnd', ['compositionend', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']); registerTwoPhaseEvent('onCompositionStart', ['compositionstart', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']); registerTwoPhaseEvent('onCompositionUpdate', ['compositionupdate', 'focusout', 'keydown', 'keypress', 'keyup', 'mousedown']); } // Track whether we've ever handled a keypress on the space key.
@interface WheelEvent @see http://www.w3.org/TR/DOM-Level-3-Events/
registerEvents
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isKeypressCommand(nativeEvent) { return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) && // ctrlKey && altKey is equivalent to AltGr, and is not a command. !(nativeEvent.ctrlKey && nativeEvent.altKey); }
Return whether a native keypress event is assumed to be a command. This is required because Firefox fires `keypress` events for key commands (cut, copy, select-all, etc.) even though no character is inserted.
isKeypressCommand
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getCompositionEventType(domEventName) { switch (domEventName) { case 'compositionstart': return 'onCompositionStart'; case 'compositionend': return 'onCompositionEnd'; case 'compositionupdate': return 'onCompositionUpdate'; } }
Translate native top level events into event types.
getCompositionEventType
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isFallbackCompositionStart(domEventName, nativeEvent) { return domEventName === 'keydown' && nativeEvent.keyCode === START_KEYCODE; }
Does our fallback best-guess model think this event signifies that composition has begun?
isFallbackCompositionStart
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isFallbackCompositionEnd(domEventName, nativeEvent) { switch (domEventName) { case 'keyup': // Command keys insert or clear IME input. return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1; case 'keydown': // Expect IME keyCode on each keydown. If we get any other // code we must have exited earlier. return nativeEvent.keyCode !== START_KEYCODE; case 'keypress': case 'mousedown': case 'focusout': // Events are not possible without cancelling IME. return true; default: return false; } }
Does our fallback mode think that this event is the end of composition?
isFallbackCompositionEnd
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getDataFromCustomEvent(nativeEvent) { var detail = nativeEvent.detail; if (typeof detail === 'object' && 'data' in detail) { return detail.data; } return null; }
Google Input Tools provides composition data via a CustomEvent, with the `data` property populated in the `detail` object. If this is available on the event object, use it. If not, this is a plain composition event and we have nothing special to extract. @param {object} nativeEvent @return {?string}
getDataFromCustomEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isUsingKoreanIME(nativeEvent) { return nativeEvent.locale === 'ko'; } // Track the current IME composition status, if any.
Check if a composition event was triggered by Korean IME. Our fallback mode does not work well with IE's Korean IME, so just use native composition events when Korean IME is used. Although CompositionEvent.locale property is deprecated, it is available in IE, where our fallback mode is enabled. @param {object} nativeEvent @return {boolean}
isUsingKoreanIME
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getFallbackBeforeInputChars(domEventName, nativeEvent) { // If we are currently composing (IME) and using a fallback to do so, // try to extract the composed characters from the fallback object. // If composition event is available, we extract a string only at // compositionevent, otherwise extract it at fallback events. if (isComposing) { if (domEventName === 'compositionend' || !canUseCompositionEvent && isFallbackCompositionEnd(domEventName, nativeEvent)) { var chars = getData(); reset(); isComposing = false; return chars; } return null; } switch (domEventName) { case 'paste': // If a paste event occurs after a keypress, throw out the input // chars. Paste events should not lead to BeforeInput events. return null; case 'keypress': /** * As of v27, Firefox may fire keypress events even when no character * will be inserted. A few possibilities: * * - `which` is `0`. Arrow keys, Esc key, etc. * * - `which` is the pressed key code, but no char is available. * Ex: 'AltGr + d` in Polish. There is no modified character for * this key combination and no character is inserted into the * document, but FF fires the keypress for char code `100` anyway. * No `input` event will occur. * * - `which` is the pressed key code, but a command combination is * being used. Ex: `Cmd+C`. No character is inserted, and no * `input` event will occur. */ if (!isKeypressCommand(nativeEvent)) { // IE fires the `keypress` event when a user types an emoji via // Touch keyboard of Windows. In such a case, the `char` property // holds an emoji character like `\uD83D\uDE0A`. Because its length // is 2, the property `which` does not represent an emoji correctly. // In such a case, we directly return the `char` property instead of // using `which`. if (nativeEvent.char && nativeEvent.char.length > 1) { return nativeEvent.char; } else if (nativeEvent.which) { return String.fromCharCode(nativeEvent.which); } } return null; case 'compositionend': return useFallbackCompositionData && !isUsingKoreanIME(nativeEvent) ? null : nativeEvent.data; default: return null; } }
For browsers that do not provide the `textInput` event, extract the appropriate string to use for SyntheticInputEvent.
getFallbackBeforeInputChars
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function extractBeforeInputEvent(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget) { var chars; if (canUseTextInputEvent) { chars = getNativeBeforeInputChars(domEventName, nativeEvent); } else { chars = getFallbackBeforeInputChars(domEventName, nativeEvent); } // If no characters are being inserted, no BeforeInput event should // be fired. if (!chars) { return null; } var listeners = accumulateTwoPhaseListeners(targetInst, 'onBeforeInput'); if (listeners.length > 0) { var event = new SyntheticInputEvent('onBeforeInput', 'beforeinput', null, nativeEvent, nativeEventTarget); dispatchQueue.push({ event: event, listeners: listeners }); event.data = chars; } }
Extract a SyntheticInputEvent for `beforeInput`, based on either native `textInput` or fallback behavior. @return {?object} A SyntheticInputEvent.
extractBeforeInputEvent
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isTextInputElement(elem) { var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase(); if (nodeName === 'input') { return !!supportedInputTypes[elem.type]; } if (nodeName === 'textarea') { return true; } return false; }
@see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
isTextInputElement
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function startWatchingForValueChange(target, targetInst) { activeElement = target; activeElementInst = targetInst; activeElement.attachEvent('onpropertychange', handlePropertyChange); }
(For IE <=9) Starts tracking propertychange events on the passed-in element and override the value property so that we can distinguish user events from value changes in JS.
startWatchingForValueChange
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function stopWatchingForValueChange() { if (!activeElement) { return; } activeElement.detachEvent('onpropertychange', handlePropertyChange); activeElement = null; activeElementInst = null; }
(For IE <=9) Removes the event listeners from the currently-tracked element, if any exists.
stopWatchingForValueChange
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function handlePropertyChange(nativeEvent) { if (nativeEvent.propertyName !== 'value') { return; } if (getInstIfValueChanged(activeElementInst)) { manualDispatchChangeEvent(nativeEvent); } }
(For IE <=9) Handles a propertychange event, sending a `change` event if the value of the active element has changed.
handlePropertyChange
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function handleEventsForInputEventPolyfill(domEventName, target, targetInst) { if (domEventName === 'focusin') { // In IE9, propertychange fires for most input events but is buggy and // doesn't fire when text is deleted, but conveniently, selectionchange // appears to fire in all of the remaining cases so we catch those and // forward the event if the value has changed // In either case, we don't want to call the event handler if the value // is changed from JS so we redefine a setter for `.value` that updates // our activeElementValue variable, allowing us to ignore those changes // // stopWatching() should be a noop here but we call it just in case we // missed a blur event somehow. stopWatchingForValueChange(); startWatchingForValueChange(target, targetInst); } else if (domEventName === 'focusout') { stopWatchingForValueChange(); } } // For IE8 and IE9.
(For IE <=9) Handles a propertychange event, sending a `change` event if the value of the active element has changed.
handleEventsForInputEventPolyfill
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getTargetInstForInputEventPolyfill(domEventName, targetInst) { if (domEventName === 'selectionchange' || domEventName === 'keyup' || domEventName === 'keydown') { // On the selectionchange event, the target is just document which isn't // helpful for us so just check activeElement instead. // // 99% of the time, keydown and keyup aren't necessary. IE8 fails to fire // propertychange on the first input event after setting `value` from a // script and fires only keydown, keypress, keyup. Catching keyup usually // gets it and catching keydown lets us fire an event for the first // keystroke if user does a key repeat (it'll be a little delayed: right // before the second keystroke). Other input methods (e.g., paste) seem to // fire selectionchange normally. return getInstIfValueChanged(activeElementInst); } }
(For IE <=9) Handles a propertychange event, sending a `change` event if the value of the active element has changed.
getTargetInstForInputEventPolyfill
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function extractEvents$1(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) { var targetNode = targetInst ? getNodeFromInstance(targetInst) : window; var getTargetInstFunc, handleEventFunc; if (shouldUseChangeEvent(targetNode)) { getTargetInstFunc = getTargetInstForChangeEvent; } else if (isTextInputElement(targetNode)) { if (isInputEventSupported) { getTargetInstFunc = getTargetInstForInputOrChangeEvent; } else { getTargetInstFunc = getTargetInstForInputEventPolyfill; handleEventFunc = handleEventsForInputEventPolyfill; } } else if (shouldUseClickEvent(targetNode)) { getTargetInstFunc = getTargetInstForClickEvent; } if (getTargetInstFunc) { var inst = getTargetInstFunc(domEventName, targetInst); if (inst) { createAndAccumulateChangeEvent(dispatchQueue, inst, nativeEvent, nativeEventTarget); return; } } if (handleEventFunc) { handleEventFunc(domEventName, targetNode, targetInst); } // When blurring, set the value attribute for number inputs if (domEventName === 'focusout') { handleControlledInputBlur(targetNode); } }
This plugin creates an `onChange` event that normalizes change events across form elements. This event fires at a time when it's possible to change the element's value without seeing a flicker. Supported elements are: - input (see `isTextInputElement`) - textarea - select
extractEvents$1
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function registerEvents$2() { registerDirectEvent('onMouseEnter', ['mouseout', 'mouseover']); registerDirectEvent('onMouseLeave', ['mouseout', 'mouseover']); registerDirectEvent('onPointerEnter', ['pointerout', 'pointerover']); registerDirectEvent('onPointerLeave', ['pointerout', 'pointerover']); }
This plugin creates an `onChange` event that normalizes change events across form elements. This event fires at a time when it's possible to change the element's value without seeing a flicker. Supported elements are: - input (see `isTextInputElement`) - textarea - select
registerEvents$2
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function extractEvents$2(dispatchQueue, domEventName, targetInst, nativeEvent, nativeEventTarget, eventSystemFlags, targetContainer) { var isOverEvent = domEventName === 'mouseover' || domEventName === 'pointerover'; var isOutEvent = domEventName === 'mouseout' || domEventName === 'pointerout'; if (isOverEvent && !isReplayingEvent(nativeEvent)) { // If this is an over event with a target, we might have already dispatched // the event in the out event of the other target. If this is replayed, // then it's because we couldn't dispatch against this target previously // so we have to do it now instead. var related = nativeEvent.relatedTarget || nativeEvent.fromElement; if (related) { // If the related node is managed by React, we can assume that we have // already dispatched the corresponding events during its mouseout. if (getClosestInstanceFromNode(related) || isContainerMarkedAsRoot(related)) { return; } } } if (!isOutEvent && !isOverEvent) { // Must not be a mouse or pointer in or out - ignoring. return; } var win; // TODO: why is this nullable in the types but we read from it? if (nativeEventTarget.window === nativeEventTarget) { // `nativeEventTarget` is probably a window object. win = nativeEventTarget; } else { // TODO: Figure out why `ownerDocument` is sometimes undefined in IE8. var doc = nativeEventTarget.ownerDocument; if (doc) { win = doc.defaultView || doc.parentWindow; } else { win = window; } } var from; var to; if (isOutEvent) { var _related = nativeEvent.relatedTarget || nativeEvent.toElement; from = targetInst; to = _related ? getClosestInstanceFromNode(_related) : null; if (to !== null) { var nearestMounted = getNearestMountedFiber(to); if (to !== nearestMounted || to.tag !== HostComponent && to.tag !== HostText) { to = null; } } } else { // Moving to a node from outside the window. from = null; to = targetInst; } if (from === to) { // Nothing pertains to our managed components. return; } var SyntheticEventCtor = SyntheticMouseEvent; var leaveEventType = 'onMouseLeave'; var enterEventType = 'onMouseEnter'; var eventTypePrefix = 'mouse'; if (domEventName === 'pointerout' || domEventName === 'pointerover') { SyntheticEventCtor = SyntheticPointerEvent; leaveEventType = 'onPointerLeave'; enterEventType = 'onPointerEnter'; eventTypePrefix = 'pointer'; } var fromNode = from == null ? win : getNodeFromInstance(from); var toNode = to == null ? win : getNodeFromInstance(to); var leave = new SyntheticEventCtor(leaveEventType, eventTypePrefix + 'leave', from, nativeEvent, nativeEventTarget); leave.target = fromNode; leave.relatedTarget = toNode; var enter = null; // We should only process this nativeEvent if we are processing // the first ancestor. Next time, we will ignore the event. var nativeTargetInst = getClosestInstanceFromNode(nativeEventTarget); if (nativeTargetInst === targetInst) { var enterEvent = new SyntheticEventCtor(enterEventType, eventTypePrefix + 'enter', to, nativeEvent, nativeEventTarget); enterEvent.target = toNode; enterEvent.relatedTarget = fromNode; enter = enterEvent; } accumulateEnterLeaveTwoPhaseListeners(dispatchQueue, leave, enter, from, to); }
For almost every interaction we care about, there will be both a top-level `mouseover` and `mouseout` event that occurs. Only use `mouseout` so that we do not extract duplicate events. However, moving the mouse into the browser from outside will not fire a `mouseout` event. In this case, we use the `mouseover` top-level event.
extractEvents$2
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function shallowEqual(objA, objB) { if (objectIs(objA, objB)) { return true; } if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { return false; } var keysA = Object.keys(objA); var keysB = Object.keys(objB); if (keysA.length !== keysB.length) { return false; } // Test for A's keys different from B. for (var i = 0; i < keysA.length; i++) { var currentKey = keysA[i]; if (!hasOwnProperty.call(objB, currentKey) || !objectIs(objA[currentKey], objB[currentKey])) { return false; } } return true; }
Performs equality by iterating through keys on an object and returning false when any key has values which are not strictly equal between the arguments. Returns true when the values of all keys are strictly equal.
shallowEqual
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getLeafNode(node) { while (node && node.firstChild) { node = node.firstChild; } return node; }
Given any node return the first leaf node without children. @param {DOMElement|DOMTextNode} node @return {DOMElement|DOMTextNode}
getLeafNode
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getSiblingNode(node) { while (node) { if (node.nextSibling) { return node.nextSibling; } node = node.parentNode; } }
Get the next sibling within a container. This will walk up the DOM if a node's siblings have been exhausted. @param {DOMElement|DOMTextNode} node @return {?DOMElement|DOMTextNode}
getSiblingNode
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getNodeForCharacterOffset(root, offset) { var node = getLeafNode(root); var nodeStart = 0; var nodeEnd = 0; while (node) { if (node.nodeType === TEXT_NODE) { nodeEnd = nodeStart + node.textContent.length; if (nodeStart <= offset && nodeEnd >= offset) { return { node: node, offset: offset - nodeStart }; } nodeStart = nodeEnd; } node = getLeafNode(getSiblingNode(node)); } }
Get object describing the nodes which contain characters at offset. @param {DOMElement|DOMTextNode} root @param {number} offset @return {?object}
getNodeForCharacterOffset
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getModernOffsetsFromPoints(outerNode, anchorNode, anchorOffset, focusNode, focusOffset) { var length = 0; var start = -1; var end = -1; var indexWithinAnchor = 0; var indexWithinFocus = 0; var node = outerNode; var parentNode = null; outer: while (true) { var next = null; while (true) { if (node === anchorNode && (anchorOffset === 0 || node.nodeType === TEXT_NODE)) { start = length + anchorOffset; } if (node === focusNode && (focusOffset === 0 || node.nodeType === TEXT_NODE)) { end = length + focusOffset; } if (node.nodeType === TEXT_NODE) { length += node.nodeValue.length; } if ((next = node.firstChild) === null) { break; } // Moving from `node` to its first child `next`. parentNode = node; node = next; } while (true) { if (node === outerNode) { // If `outerNode` has children, this is always the second time visiting // it. If it has no children, this is still the first loop, and the only // valid selection is anchorNode and focusNode both equal to this node // and both offsets 0, in which case we will have handled above. break outer; } if (parentNode === anchorNode && ++indexWithinAnchor === anchorOffset) { start = length; } if (parentNode === focusNode && ++indexWithinFocus === focusOffset) { end = length; } if ((next = node.nextSibling) !== null) { break; } node = parentNode; parentNode = node.parentNode; } // Moving from `node` to its next sibling `next`. node = next; } if (start === -1 || end === -1) { // This should never happen. (Would happen if the anchor/focus nodes aren't // actually inside the passed-in node.) return null; } return { start: start, end: end }; }
Returns {start, end} where `start` is the character/codepoint index of (anchorNode, anchorOffset) within the textContent of `outerNode`, and `end` is the index of (focusNode, focusOffset). Returns null if you pass in garbage input but we should probably just crash. Exported only for testing.
getModernOffsetsFromPoints
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function setOffsets(node, offsets) { var doc = node.ownerDocument || document; var win = doc && doc.defaultView || window; // Edge fails with "Object expected" in some scenarios. // (For instance: TinyMCE editor used in a list component that supports pasting to add more, // fails when pasting 100+ items) if (!win.getSelection) { return; } var selection = win.getSelection(); var length = node.textContent.length; var start = Math.min(offsets.start, length); var end = offsets.end === undefined ? start : Math.min(offsets.end, length); // IE 11 uses modern selection, but doesn't support the extend method. // Flip backward selections, so we can set with a single range. if (!selection.extend && start > end) { var temp = end; end = start; start = temp; } var startMarker = getNodeForCharacterOffset(node, start); var endMarker = getNodeForCharacterOffset(node, end); if (startMarker && endMarker) { if (selection.rangeCount === 1 && selection.anchorNode === startMarker.node && selection.anchorOffset === startMarker.offset && selection.focusNode === endMarker.node && selection.focusOffset === endMarker.offset) { return; } var range = doc.createRange(); range.setStart(startMarker.node, startMarker.offset); selection.removeAllRanges(); if (start > end) { selection.addRange(range); selection.extend(endMarker.node, endMarker.offset); } else { range.setEnd(endMarker.node, endMarker.offset); selection.addRange(range); } } }
In modern non-IE browsers, we can support both forward and backward selections. Note: IE10+ supports the Selection object, but it does not support the `extend` method, which means that even in modern IE, it's not possible to programmatically create a backward selection. Thus, for all IE versions, we use the old IE API to create our selections. @param {DOMElement|DOMTextNode} node @param {object} offsets
setOffsets
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isTextNode(node) { return node && node.nodeType === TEXT_NODE; }
In modern non-IE browsers, we can support both forward and backward selections. Note: IE10+ supports the Selection object, but it does not support the `extend` method, which means that even in modern IE, it's not possible to programmatically create a backward selection. Thus, for all IE versions, we use the old IE API to create our selections. @param {DOMElement|DOMTextNode} node @param {object} offsets
isTextNode
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function containsNode(outerNode, innerNode) { if (!outerNode || !innerNode) { return false; } else if (outerNode === innerNode) { return true; } else if (isTextNode(outerNode)) { return false; } else if (isTextNode(innerNode)) { return containsNode(outerNode, innerNode.parentNode); } else if ('contains' in outerNode) { return outerNode.contains(innerNode); } else if (outerNode.compareDocumentPosition) { return !!(outerNode.compareDocumentPosition(innerNode) & 16); } else { return false; } }
In modern non-IE browsers, we can support both forward and backward selections. Note: IE10+ supports the Selection object, but it does not support the `extend` method, which means that even in modern IE, it's not possible to programmatically create a backward selection. Thus, for all IE versions, we use the old IE API to create our selections. @param {DOMElement|DOMTextNode} node @param {object} offsets
containsNode
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isInDocument(node) { return node && node.ownerDocument && containsNode(node.ownerDocument.documentElement, node); }
In modern non-IE browsers, we can support both forward and backward selections. Note: IE10+ supports the Selection object, but it does not support the `extend` method, which means that even in modern IE, it's not possible to programmatically create a backward selection. Thus, for all IE versions, we use the old IE API to create our selections. @param {DOMElement|DOMTextNode} node @param {object} offsets
isInDocument
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function isSameOriginFrame(iframe) { try { // Accessing the contentDocument of a HTMLIframeElement can cause the browser // to throw, e.g. if it has a cross-origin src attribute. // Safari will show an error in the console when the access results in "Blocked a frame with origin". e.g: // iframe.contentDocument.defaultView; // A safety way is to access one of the cross origin properties: Window or Location // Which might result in "SecurityError" DOM Exception and it is compatible to Safari. // https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl return typeof iframe.contentWindow.location.href === 'string'; } catch (err) { return false; } }
In modern non-IE browsers, we can support both forward and backward selections. Note: IE10+ supports the Selection object, but it does not support the `extend` method, which means that even in modern IE, it's not possible to programmatically create a backward selection. Thus, for all IE versions, we use the old IE API to create our selections. @param {DOMElement|DOMTextNode} node @param {object} offsets
isSameOriginFrame
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getActiveElementDeep() { var win = window; var element = getActiveElement(); while (element instanceof win.HTMLIFrameElement) { if (isSameOriginFrame(element)) { win = element.contentWindow; } else { return element; } element = getActiveElement(win.document); } return element; }
In modern non-IE browsers, we can support both forward and backward selections. Note: IE10+ supports the Selection object, but it does not support the `extend` method, which means that even in modern IE, it's not possible to programmatically create a backward selection. Thus, for all IE versions, we use the old IE API to create our selections. @param {DOMElement|DOMTextNode} node @param {object} offsets
getActiveElementDeep
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function hasSelectionCapabilities(elem) { var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase(); return nodeName && (nodeName === 'input' && (elem.type === 'text' || elem.type === 'search' || elem.type === 'tel' || elem.type === 'url' || elem.type === 'password') || nodeName === 'textarea' || elem.contentEditable === 'true'); }
@hasSelectionCapabilities: we get the element types that support selection from https://html.spec.whatwg.org/#do-not-apply, looking at `selectionStart` and `selectionEnd` rows.
hasSelectionCapabilities
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT
function getSelectionInformation() { var focusedElem = getActiveElementDeep(); return { focusedElem: focusedElem, selectionRange: hasSelectionCapabilities(focusedElem) ? getSelection(focusedElem) : null }; }
@hasSelectionCapabilities: we get the element types that support selection from https://html.spec.whatwg.org/#do-not-apply, looking at `selectionStart` and `selectionEnd` rows.
getSelectionInformation
javascript
facebook/memlab
packages/lens/src/tests/lib/react-dom-v18.dev.js
https://github.com/facebook/memlab/blob/master/packages/lens/src/tests/lib/react-dom-v18.dev.js
MIT