Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
trueadm committed Mar 3, 2020
1 parent 2d66dc6 commit d63d2f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
18 changes: 10 additions & 8 deletions packages/react-dom/src/events/DOMModernPluginEventSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
import type {Fiber} from 'react-reconciler/src/ReactFiber';
import type {PluginModule} from 'legacy-events/PluginModuleType';
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';

import {registrationNameDependencies} from 'legacy-events/EventPluginRegistry';
import {batchedEventUpdates} from 'legacy-events/ReactGenericBatching';
Expand Down Expand Up @@ -102,11 +103,11 @@ function dispatchEventsForPlugins(
rootContainer: Element | Document,
): void {
const nativeEventTarget = getEventTarget(nativeEvent);
const syntheticEvents = [];
const syntheticEvents: Array<ReactSyntheticEvent> = [];

for (let i = 0; i < plugins.length; i++) {
const possiblePlugin: PluginModule<AnyNativeEvent> = plugins[i];
if (possiblePlugin) {
if (possiblePlugin !== undefined) {
const extractedEvents = possiblePlugin.extractEvents(
topLevelType,
targetInst,
Expand All @@ -115,12 +116,13 @@ function dispatchEventsForPlugins(
eventSystemFlags,
rootContainer,
);
if (extractedEvents) {
if (isArray(extractedEvents)) {
syntheticEvents.push(...(extractedEvents: any));
} else {
syntheticEvents.push(extractedEvents);
}
if (isArray(extractedEvents)) {
// Flow complains about @@iterator being missing in ReactSyntheticEvent,
// so we cast to avoid the Flow error.
const arrOfExtractedEvents = ((extractedEvents: any): Array<ReactSyntheticEvent>);
syntheticEvents.push(...arrOfExtractedEvents);
} else if (extractedEvents) {
syntheticEvents.push(extractedEvents);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ let React;
let ReactFeatureFlags;
let ReactDOM;

function dispatchEvent(element, type) {
function dispatchClickEvent(element) {
const event = document.createEvent('Event');
event.initEvent(type, true, true);
event.initEvent('click', true, true);
element.dispatchEvent(event);
}

function dispatchClickEvent(element) {
dispatchEvent(element, 'click');
}

describe('DOMModernPluginEventSystem', () => {
let container;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ReactNativeBridgeEventPlugin = {
nativeEvent: AnyNativeEvent,
nativeEventTarget: null | Object,
eventSystemFlags: EventSystemFlags,
): ?Object {
): Object | null {
if (targetInst == null) {
// Probably a node belonging to another renderer's tree.
return null;
Expand Down

0 comments on commit d63d2f6

Please sign in to comment.