GeezerVison is showing github.com — Refactor DOM plugin system to single module (#18025) · react/react@9def56e
File treeExpand file treeCollapse file tree Open diff view settings react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/legacy-events/EventPluginHub.js -176Lines changed: 0 additions & 176 deletions Collapse file Copy file name to clipboardExpand all lines: packages/legacy-events/EventPluginRegistry.js +3-7Lines changed: 3 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -89,7 +89,7 @@ function publishEventForPlugin( | 89 | 89 | ): boolean { | 90 | 90 | invariant( | 91 | 91 | !eventNameDispatchConfigs.hasOwnProperty(eventName), | 92 | | - 'EventPluginHub: More than one plugin attempted to publish the same ' + | | 92 | + 'EventPluginRegistry: More than one plugin attempted to publish the same ' + | 93 | 93 | 'event name, `%s`.', | 94 | 94 | eventName, | 95 | 95 | ); | @@ -133,7 +133,7 @@ function publishRegistrationName( | 133 | 133 | ): void { | 134 | 134 | invariant( | 135 | 135 | !registrationNameModules[registrationName], | 136 | | - 'EventPluginHub: More than one plugin attempted to publish the same ' + | | 136 | + 'EventPluginRegistry: More than one plugin attempted to publish the same ' + | 137 | 137 | 'registration name, `%s`.', | 138 | 138 | registrationName, | 139 | 139 | ); | @@ -153,8 +153,6 @@ function publishRegistrationName( | 153 | 153 |
| 154 | 154 | /** | 155 | 155 | * Registers plugins so that they can extract and dispatch events. | 156 | | - * | 157 | | - * @see {EventPluginHub} | 158 | 156 | */ | 159 | 157 |
| 160 | 158 | /** | @@ -193,7 +191,6 @@ export const possibleRegistrationNames = __DEV__ ? {} : (null: any); | 193 | 191 | * | 194 | 192 | * @param {array} InjectedEventPluginOrder | 195 | 193 | * @internal | 196 | | - * @see {EventPluginHub.injection.injectEventPluginOrder} | 197 | 194 | */ | 198 | 195 | export function injectEventPluginOrder( | 199 | 196 | injectedEventPluginOrder: EventPluginOrder, | @@ -209,14 +206,13 @@ export function injectEventPluginOrder( | 209 | 206 | } | 210 | 207 |
| 211 | 208 | /** | 212 | | - * Injects plugins to be used by `EventPluginHub`. The plugin names must be | | 209 | + * Injects plugins to be used by plugin event system. The plugin names must be | 213 | 210 | * in the ordering injected by `injectEventPluginOrder`. | 214 | 211 | * | 215 | 212 | * Plugins can be injected as part of page initialization or on-the-fly. | 216 | 213 | * | 217 | 214 | * @param {object} injectedNamesToPlugins Map from names to plugin modules. | 218 | 215 | * @internal | 219 | | - * @see {EventPluginHub.injection.injectEventPluginsByName} | 220 | 216 | */ | 221 | 217 | export function injectEventPluginsByName( | 222 | 218 | injectedNamesToPlugins: NamesToPlugins, | |
Collapse file Copy file name to clipboardExpand all lines: packages/legacy-events/EventPropagators.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,7 @@ import { | 11 | 11 | traverseEnterLeave, | 12 | 12 | } from 'shared/ReactTreeTraversal'; | 13 | 13 |
| 14 | | -import {getListener} from './EventPluginHub'; | | 14 | +import getListener from 'legacy-events/getListener'; | 15 | 15 | import accumulateInto from './accumulateInto'; | 16 | 16 | import forEachAccumulated from './forEachAccumulated'; | 17 | 17 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/legacy-events/ResponderEventPlugin.js +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -282,7 +282,7 @@ to return true:wantsResponderID| | | 282 | 282 | + + */ | 283 | 283 |
| 284 | 284 | /** | 285 | | - * A note about event ordering in the `EventPluginHub`. | | 285 | + * A note about event ordering in the `EventPluginRegistry`. | 286 | 286 | * | 287 | 287 | * Suppose plugins are injected in the following order: | 288 | 288 | * | @@ -301,7 +301,7 @@ to return true:wantsResponderID| | | 301 | 301 | * - When returned from `extractEvents`, deferred-dispatched events contain an | 302 | 302 | * "accumulation" of deferred dispatches. | 303 | 303 | * - These deferred dispatches are accumulated/collected before they are | 304 | | - * returned, but processed at a later time by the `EventPluginHub` (hence the | | 304 | + * returned, but processed at a later time by the `EventPluginRegistry` (hence the | 305 | 305 | * name deferred). | 306 | 306 | * | 307 | 307 | * In the process of returning their deferred-dispatched events, event plugins | @@ -325,9 +325,9 @@ to return true:wantsResponderID| | | 325 | 325 | * - `R`s on-demand events (if any) (dispatched by `R` on-demand) | 326 | 326 | * - `S`s on-demand events (if any) (dispatched by `S` on-demand) | 327 | 327 | * - `C`s on-demand events (if any) (dispatched by `C` on-demand) | 328 | | - * - `R`s extracted events (if any) (dispatched by `EventPluginHub`) | 329 | | - * - `S`s extracted events (if any) (dispatched by `EventPluginHub`) | 330 | | - * - `C`s extracted events (if any) (dispatched by `EventPluginHub`) | | 328 | + * - `R`s extracted events (if any) (dispatched by `EventPluginRegistry`) | | 329 | + * - `S`s extracted events (if any) (dispatched by `EventPluginRegistry`) | | 330 | + * - `C`s extracted events (if any) (dispatched by `EventPluginRegistry`) | 331 | 331 | * | 332 | 332 | * In the case of `ResponderEventPlugin`: If the `startShouldSetResponder` | 333 | 333 | * on-demand dispatch returns `true` (and some other details are satisfied) the | @@ -336,9 +336,9 @@ to return true:wantsResponderID| | | 336 | 336 | * will appear as follows: | 337 | 337 | * | 338 | 338 | * - `startShouldSetResponder` (`ResponderEventPlugin` dispatches on-demand) | 339 | | - * - `touchStartCapture` (`EventPluginHub` dispatches as usual) | 340 | | - * - `touchStart` (`EventPluginHub` dispatches as usual) | 341 | | - * - `responderGrant/Reject` (`EventPluginHub` dispatches as usual) | | 339 | + * - `touchStartCapture` (`EventPluginRegistry` dispatches as usual) | | 340 | + * - `touchStart` (`EventPluginRegistry` dispatches as usual) | | 341 | + * - `responderGrant/Reject` (`EventPluginRegistry` dispatches as usual) | 342 | 342 | */ | 343 | 343 |
| 344 | 344 | function setResponderAndExtractTransfer( | |
Collapse file Copy file name to clipboardExpand all lines: packages/legacy-events/__tests__/EventPluginRegistry-test.internal.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -211,7 +211,7 @@ describe('EventPluginRegistry', () => { | 211 | 211 | expect(function() { | 212 | 212 | EventPluginRegistry.injectEventPluginOrder(['one', 'two']); | 213 | 213 | }).toThrowError( | 214 | | - 'EventPluginHub: More than one plugin attempted to publish the same ' + | | 214 | + 'EventPluginRegistry: More than one plugin attempted to publish the same ' + | 215 | 215 | 'registration name, `onPhotoCapture`.', | 216 | 216 | ); | 217 | 217 | }); | |
Collapse file Copy file name to clipboard +74Lines changed: 74 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/** | | 2 | + * Copyright (c) Facebook, Inc. and its affiliates. | | 3 | + * | | 4 | + * This source code is licensed under the MIT license found in the | | 5 | + * LICENSE file in the root directory of this source tree. | | 6 | + * @flow | | 7 | + */ | | 8 | + | | 9 | +import type {Fiber} from 'react-reconciler/src/ReactFiber'; | | 10 | + | | 11 | +import invariant from 'shared/invariant'; | | 12 | + | | 13 | +import {getFiberCurrentPropsFromNode} from './EventPluginUtils'; | | 14 | + | | 15 | +function isInteractive(tag) { | | 16 | + return ( | | 17 | + tag === 'button' || | | 18 | + tag === 'input' || | | 19 | + tag === 'select' || | | 20 | + tag === 'textarea' | | 21 | + ); | | 22 | +} | | 23 | + | | 24 | +function shouldPreventMouseEvent(name, type, props) { | | 25 | + switch (name) { | | 26 | + case 'onClick': | | 27 | + case 'onClickCapture': | | 28 | + case 'onDoubleClick': | | 29 | + case 'onDoubleClickCapture': | | 30 | + case 'onMouseDown': | | 31 | + case 'onMouseDownCapture': | | 32 | + case 'onMouseMove': | | 33 | + case 'onMouseMoveCapture': | | 34 | + case 'onMouseUp': | | 35 | + case 'onMouseUpCapture': | | 36 | + case 'onMouseEnter': | | 37 | + return !!(props.disabled && isInteractive(type)); | | 38 | + default: | | 39 | + return false; | | 40 | + } | | 41 | +} | | 42 | + | | 43 | +/** | | 44 | + * @param {object} inst The instance, which is the source of events. | | 45 | + * @param {string} registrationName Name of listener (e.g. `onClick`). | | 46 | + * @return {?function} The stored callback. | | 47 | + */ | | 48 | +export default function getListener(inst: Fiber, registrationName: string) { | | 49 | + let listener; | | 50 | + | | 51 | + // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not | | 52 | + // live here; needs to be moved to a better place soon | | 53 | + const stateNode = inst.stateNode; | | 54 | + if (!stateNode) { | | 55 | + // Work in progress (ex: onload events in incremental mode). | | 56 | + return null; | | 57 | + } | | 58 | + const props = getFiberCurrentPropsFromNode(stateNode); | | 59 | + if (!props) { | | 60 | + // Work in progress. | | 61 | + return null; | | 62 | + } | | 63 | + listener = props[registrationName]; | | 64 | + if (shouldPreventMouseEvent(registrationName, inst.type, props)) { | | 65 | + return null; | | 66 | + } | | 67 | + invariant( | | 68 | + !listener || typeof listener === 'function', | | 69 | + 'Expected `%s` listener to be a function, instead got a value of `%s` type.', | | 70 | + registrationName, | | 71 | + typeof listener, | | 72 | + ); | | 73 | + return listener; | | 74 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/InvalidEventListeners-test.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 |
| 12 | 12 | jest.mock('../events/isEventSupported'); | 13 | 13 |
| 14 | | -describe('EventPluginHub', () => { | | 14 | +describe('InvalidEventListeners', () => { | 15 | 15 | let React; | 16 | 16 | let ReactTestUtils; | 17 | 17 |
| |
|