getListener.js — react Source File
Architecture documentation for getListener.js, a javascript file in the react codebase. 3 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 090215d4_d041_d740_3c6a_2b92c717e601["getListener.js"] 9c694103_7f39_88d0_6b4d_f9b2ffed5731["ReactFiberConfigDOM.js"] 090215d4_d041_d740_3c6a_2b92c717e601 --> 9c694103_7f39_88d0_6b4d_f9b2ffed5731 799a7834_f34c_8596_4026_015681eee732["ReactDOMComponentTree.js"] 090215d4_d041_d740_3c6a_2b92c717e601 --> 799a7834_f34c_8596_4026_015681eee732 42892443_e223_3da0_aeb9_e1b32a408fb0["ReactInternalTypes"] 090215d4_d041_d740_3c6a_2b92c717e601 --> 42892443_e223_3da0_aeb9_e1b32a408fb0 816b54e5_c63c_f8b2_68e8_0c637e281f03["DOMPluginEventSystem.js"] 816b54e5_c63c_f8b2_68e8_0c637e281f03 --> 090215d4_d041_d740_3c6a_2b92c717e601 style 090215d4_d041_d740_3c6a_2b92c717e601 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @flow
*/
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {Props} from '../client/ReactFiberConfigDOM';
import {getFiberCurrentPropsFromNode} from '../client/ReactDOMComponentTree';
function isInteractive(tag: string): boolean {
return (
tag === 'button' ||
tag === 'input' ||
tag === 'select' ||
tag === 'textarea'
);
}
function shouldPreventMouseEvent(
name: string,
type: string,
props: Props,
): boolean {
switch (name) {
case 'onClick':
case 'onClickCapture':
case 'onDoubleClick':
case 'onDoubleClickCapture':
case 'onMouseDown':
case 'onMouseDownCapture':
case 'onMouseMove':
case 'onMouseMoveCapture':
case 'onMouseUp':
case 'onMouseUpCapture':
case 'onMouseEnter':
return !!(props.disabled && isInteractive(type));
default:
return false;
}
}
/**
* @param {object} inst The instance, which is the source of events.
* @param {string} registrationName Name of listener (e.g. `onClick`).
* @return {?function} The stored callback.
*/
export default function getListener(
inst: Fiber,
registrationName: string,
): Function | null {
const stateNode = inst.stateNode;
if (stateNode === null) {
// Work in progress (ex: onload events in incremental mode).
return null;
}
const props = getFiberCurrentPropsFromNode(stateNode);
if (props === null) {
// Work in progress.
return null;
}
// $FlowFixMe[invalid-computed-prop]
const listener = props[registrationName];
if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
return null;
}
if (listener && typeof listener !== 'function') {
throw new Error(
`Expected \`${registrationName}\` listener to be a function, instead got a value of \`${typeof listener}\` type.`,
);
}
return listener;
}
Domain
Subdomains
Dependencies
- ReactDOMComponentTree.js
- ReactFiberConfigDOM.js
- ReactInternalTypes
Source
Frequently Asked Questions
What does getListener.js do?
getListener.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in getListener.js?
getListener.js defines 3 function(s): getListener, isInteractive, shouldPreventMouseEvent.
What does getListener.js depend on?
getListener.js imports 3 module(s): ReactDOMComponentTree.js, ReactFiberConfigDOM.js, ReactInternalTypes.
What files import getListener.js?
getListener.js is imported by 1 file(s): DOMPluginEventSystem.js.
Where is getListener.js in the architecture?
getListener.js is located at packages/react-dom-bindings/src/events/getListener.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-dom-bindings/src/events).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free