Coder Social home page Coder Social logo

React 事件处理 about creamidea.github.com HOT 2 OPEN

creamidea avatar creamidea commented on September 26, 2024
React 事件处理

from creamidea.github.com.

Comments (2)

creamidea avatar creamidea commented on September 26, 2024

listenToAllSupportedEvents 会把所有的事件都在 container 上注册一遍!!!

dispatchEventForPluginEventSystem(
  domEventName, // 原生事件名称
  eventSystemFlags, // 事件标志,比如是否 capture
  nativeEvent, // 原生事件对象
  return_targetInst, // null, Suspense, HostRoot。后面也被定义为 ancestorInst
  targetContainer, // 根 DOM 容器
);

onSelect, onChange 这里事件,会由 SelectEventPlugin.js, ChangeEventPlugin.js 内注册处理。原理:会事先通过 registerEvents 函数注册

function registerEvents() {
  registerTwoPhaseEvent('onSelect', [
    'focusout',
    'contextmenu',
    'dragend',
    'focusin',
    'keydown',
    'keyup',
    'mousedown',
    'mouseup',
    'selectionchange',
  ]);
}

在 extract 阶段,会捕获原生 DOM 事件,比如 mousedown,那么进入 switch-case 进行处理,转成查找注册给 React onSelect 事件

function constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget) {
  ...
  const listeners = accumulateTwoPhaseListeners(
    activeElementInst,
    'onSelect',
  );
  ...
}

from creamidea.github.com.

creamidea avatar creamidea commented on September 26, 2024

https://stackoverflow.com/questions/44279434/react-onselect-event-not-working

from creamidea.github.com.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.