Home / Function/ addTrappedEventListener() — react Function Reference

addTrappedEventListener() — react Function Reference

Architecture documentation for the addTrappedEventListener() function in DOMPluginEventSystem.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  56389510_e7e6_46ee_7567_7c604d5f262b["addTrappedEventListener()"]
  816b54e5_c63c_f8b2_68e8_0c637e281f03["DOMPluginEventSystem.js"]
  56389510_e7e6_46ee_7567_7c604d5f262b -->|defined in| 816b54e5_c63c_f8b2_68e8_0c637e281f03
  9a006a44_c580_470b_507b_17fea64729bd["listenToNonDelegatedEvent()"]
  9a006a44_c580_470b_507b_17fea64729bd -->|calls| 56389510_e7e6_46ee_7567_7c604d5f262b
  e1b9c7d1_a1e1_1549_f27b_3d61efc611d5["listenToNativeEvent()"]
  e1b9c7d1_a1e1_1549_f27b_3d61efc611d5 -->|calls| 56389510_e7e6_46ee_7567_7c604d5f262b
  d14160aa_deee_23d3_22c4_e2413ebdeaca["listenToNativeEventForNonManagedEventTarget()"]
  d14160aa_deee_23d3_22c4_e2413ebdeaca -->|calls| 56389510_e7e6_46ee_7567_7c604d5f262b
  59f88372_b7f2_6022_203c_89c9b50a4f4d["deferClickToDocumentForLegacyFBSupport()"]
  59f88372_b7f2_6022_203c_89c9b50a4f4d -->|calls| 56389510_e7e6_46ee_7567_7c604d5f262b
  50d604eb_5807_6884_7241_32fb258f9cea["createEventListenerWrapperWithPriority()"]
  56389510_e7e6_46ee_7567_7c604d5f262b -->|calls| 50d604eb_5807_6884_7241_32fb258f9cea
  6f62cd9f_c774_b2b4_1083_5d44d0e5b33a["removeEventListener()"]
  56389510_e7e6_46ee_7567_7c604d5f262b -->|calls| 6f62cd9f_c774_b2b4_1083_5d44d0e5b33a
  8f122a48_619a_7b78_c1a9_6acf1f5f1627["addEventCaptureListenerWithPassiveFlag()"]
  56389510_e7e6_46ee_7567_7c604d5f262b -->|calls| 8f122a48_619a_7b78_c1a9_6acf1f5f1627
  89c13a07_d7ce_077f_deba_446a6e515ce3["addEventCaptureListener()"]
  56389510_e7e6_46ee_7567_7c604d5f262b -->|calls| 89c13a07_d7ce_077f_deba_446a6e515ce3
  802aac43_e21e_d669_df7e_fe675c09a0ee["addEventBubbleListenerWithPassiveFlag()"]
  56389510_e7e6_46ee_7567_7c604d5f262b -->|calls| 802aac43_e21e_d669_df7e_fe675c09a0ee
  3dfcdf97_f898_501e_34fc_cae6f0372e8c["addEventBubbleListener()"]
  56389510_e7e6_46ee_7567_7c604d5f262b -->|calls| 3dfcdf97_f898_501e_34fc_cae6f0372e8c
  style 56389510_e7e6_46ee_7567_7c604d5f262b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-dom-bindings/src/events/DOMPluginEventSystem.js lines 460–553

function addTrappedEventListener(
  targetContainer: EventTarget,
  domEventName: DOMEventName,
  eventSystemFlags: EventSystemFlags,
  isCapturePhaseListener: boolean,
  isDeferredListenerForLegacyFBSupport?: boolean,
) {
  let listener = createEventListenerWrapperWithPriority(
    targetContainer,
    domEventName,
    eventSystemFlags,
  );
  // If passive option is not supported, then the event will be
  // active and not passive.
  let isPassiveListener: void | boolean = undefined;
  if (passiveBrowserEventsSupported) {
    // Browsers introduced an intervention, making these events
    // passive by default on document. React doesn't bind them
    // to document anymore, but changing this now would undo
    // the performance wins from the change. So we emulate
    // the existing behavior manually on the roots now.
    // https://github.com/facebook/react/issues/19651
    if (
      domEventName === 'touchstart' ||
      domEventName === 'touchmove' ||
      domEventName === 'wheel'
    ) {
      isPassiveListener = true;
    }
  }

  targetContainer =
    enableLegacyFBSupport && isDeferredListenerForLegacyFBSupport
      ? (targetContainer: any).ownerDocument
      : targetContainer;

  let unsubscribeListener;
  // When legacyFBSupport is enabled, it's for when we
  // want to add a one time event listener to a container.
  // This should only be used with enableLegacyFBSupport
  // due to requirement to provide compatibility with
  // internal FB www event tooling. This works by removing
  // the event listener as soon as it is invoked. We could
  // also attempt to use the {once: true} param on
  // addEventListener, but that requires support and some
  // browsers do not support this today, and given this is
  // to support legacy code patterns, it's likely they'll
  // need support for such browsers.
  if (enableLegacyFBSupport && isDeferredListenerForLegacyFBSupport) {
    const originalListener = listener;
    // $FlowFixMe[missing-this-annot]
    listener = function (...p) {
      removeEventListener(
        targetContainer,
        domEventName,
        unsubscribeListener,
        isCapturePhaseListener,
      );
      return originalListener.apply(this, p);
    };
  }
  // TODO: There are too many combinations here. Consolidate them.
  if (isCapturePhaseListener) {
    if (isPassiveListener !== undefined) {
      unsubscribeListener = addEventCaptureListenerWithPassiveFlag(
        targetContainer,
        domEventName,
        listener,
        isPassiveListener,
      );
    } else {
      unsubscribeListener = addEventCaptureListener(
        targetContainer,
        domEventName,
        listener,
      );
    }
  } else {
    if (isPassiveListener !== undefined) {
      unsubscribeListener = addEventBubbleListenerWithPassiveFlag(
        targetContainer,

Domain

Subdomains

Frequently Asked Questions

What does addTrappedEventListener() do?
addTrappedEventListener() is a function in the react codebase, defined in packages/react-dom-bindings/src/events/DOMPluginEventSystem.js.
Where is addTrappedEventListener() defined?
addTrappedEventListener() is defined in packages/react-dom-bindings/src/events/DOMPluginEventSystem.js at line 460.
What does addTrappedEventListener() call?
addTrappedEventListener() calls 6 function(s): addEventBubbleListener, addEventBubbleListenerWithPassiveFlag, addEventCaptureListener, addEventCaptureListenerWithPassiveFlag, createEventListenerWrapperWithPriority, removeEventListener.
What calls addTrappedEventListener()?
addTrappedEventListener() is called by 4 function(s): deferClickToDocumentForLegacyFBSupport, listenToNativeEvent, listenToNativeEventForNonManagedEventTarget, listenToNonDelegatedEvent.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free