Skip to content

Commit

Permalink
[react-interactions] Remove responder root event types + revert commi…
Browse files Browse the repository at this point in the history
…t phase change (#17577)
  • Loading branch information
trueadm authored Dec 11, 2019
1 parent 9ac42dd commit 2afeebd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 117 deletions.
10 changes: 1 addition & 9 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import type {
ReactDOMFundamentalComponentInstance,
} from 'shared/ReactDOMTypes';
import {
addRootEventTypesForResponderInstance,
mountEventResponder,
unmountEventResponder,
dispatchEventForResponderEventSystem,
Expand Down Expand Up @@ -954,17 +953,10 @@ export function mountResponderInstance(
): ReactDOMEventResponderInstance {
// Listen to events
const doc = instance.ownerDocument;
const {
rootEventTypes,
targetEventTypes,
} = ((responder: any): ReactDOMEventResponder);
const {targetEventTypes} = ((responder: any): ReactDOMEventResponder);
if (targetEventTypes !== null) {
listenToEventResponderEventTypes(targetEventTypes, doc);
}
if (rootEventTypes !== null) {
addRootEventTypesForResponderInstance(responderInstance, rootEventTypes);
listenToEventResponderEventTypes(rootEventTypes, doc);
}
mountEventResponder(
responder,
responderInstance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const DiscreteEvent = 0;
function createEventResponder({
onEvent,
onRootEvent,
rootEventTypes,
targetEventTypes,
onMount,
onUnmount,
Expand All @@ -32,7 +31,6 @@ function createEventResponder({
}) {
return React.unstable_createResponder('TestEventResponder', {
targetEventTypes,
rootEventTypes,
onEvent,
onRootEvent,
onMount,
Expand Down Expand Up @@ -616,43 +614,6 @@ describe('DOMEventResponderSystem', () => {
expect(counter).toEqual(5);
});

it('the event responder root listeners should fire on a root click event', () => {
let eventResponderFiredCount = 0;
let eventLog = [];

const TestResponder = createEventResponder({
rootEventTypes: ['click'],
onRootEvent: event => {
eventResponderFiredCount++;
eventLog.push({
name: event.type,
passive: event.passive,
phase: 'root',
});
},
});

const Test = () => {
const listener = React.unstable_useResponder(TestResponder, {});
return <button DEPRECATED_flareListeners={listener}>Click me!</button>;
};

ReactDOM.render(<Test />, container);
expect(container.innerHTML).toBe('<button>Click me!</button>');

// Clicking the button should trigger the event responder onEvent() twice
dispatchClickEvent(document.body);
expect(eventResponderFiredCount).toBe(1);
expect(eventLog.length).toBe(1);
expect(eventLog).toEqual([
{
name: 'click',
passive: false,
phase: 'root',
},
]);
});

it('the event responder target listeners should correctly fire for only their events', () => {
let clickEventComponent1Fired = 0;
let clickEventComponent2Fired = 0;
Expand Down Expand Up @@ -714,65 +675,6 @@ describe('DOMEventResponderSystem', () => {
]);
});

it('the event responder root listeners should correctly fire for only their events', () => {
let clickEventComponent1Fired = 0;
let clickEventComponent2Fired = 0;
let eventLog = [];

const TestResponderA = createEventResponder({
rootEventTypes: ['click_active'],
onRootEvent: event => {
clickEventComponent1Fired++;
eventLog.push({
name: event.type,
passive: event.passive,
});
},
});

const TestResponderB = createEventResponder({
rootEventTypes: ['click'],
onRootEvent: event => {
clickEventComponent2Fired++;
eventLog.push({
name: event.type,
passive: event.passive,
});
},
});

const Test = () => {
const listener = React.unstable_useResponder(TestResponderA, {});
const listener2 = React.unstable_useResponder(TestResponderB, {});

return (
<div DEPRECATED_flareListeners={listener}>
<button DEPRECATED_flareListeners={listener2}>Click me!</button>
</div>
);
};

ReactDOM.render(<Test />, container);

dispatchClickEvent(document.body);

expect(clickEventComponent1Fired).toBe(1);
expect(clickEventComponent2Fired).toBe(1);
expect(eventLog.length).toBe(2);
expect(eventLog).toEqual([
{
name: 'click',
passive: false,
},
{
name: 'click',
passive: false,
},
]);

ReactDOM.render(<Test />, container);
});

it('the event responder system should warn on accessing invalid properties', () => {
const TestResponder = createEventResponder({
targetEventTypes: ['click'],
Expand Down
5 changes: 0 additions & 5 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import warningWithoutStack from 'shared/warningWithoutStack';

import {dispatchEvent} from './ReactFabricEventEmitter';
import {
addRootEventTypesForResponderInstance,
mountEventResponder,
unmountEventResponder,
} from './ReactFabricEventResponderSystem';
Expand Down Expand Up @@ -453,10 +452,6 @@ export function mountResponderInstance(
instance: Instance,
) {
if (enableFlareAPI) {
const {rootEventTypes} = responder;
if (rootEventTypes !== null) {
addRootEventTypesForResponderInstance(responderInstance, rootEventTypes);
}
mountEventResponder(responder, responderInstance, props, state);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
if (enableFlareAPI) {
const prevListeners = oldProps.DEPRECATED_flareListeners;
const nextListeners = newProps.DEPRECATED_flareListeners;
if (prevListeners !== nextListeners || current === null) {
if (prevListeners !== nextListeners) {
updateLegacyEventListeners(nextListeners, finishedWork, null);
}
}
Expand Down
20 changes: 17 additions & 3 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import {
import {createFundamentalStateInstance} from './ReactFiberFundamental';
import {Never} from './ReactFiberExpirationTime';
import {resetChildFibers} from './ReactChildFiber';
import {updateLegacyEventListeners} from './ReactFiberEvents';
import {createScopeMethods} from './ReactFiberScope';

function markUpdate(workInProgress: Fiber) {
Expand Down Expand Up @@ -729,7 +730,11 @@ function completeWork(
if (enableFlareAPI) {
const listeners = newProps.DEPRECATED_flareListeners;
if (listeners != null) {
markUpdate(workInProgress);
updateLegacyEventListeners(
listeners,
workInProgress,
rootContainerInstance,
);
}
}
} else {
Expand All @@ -749,7 +754,11 @@ function completeWork(
if (enableFlareAPI) {
const listeners = newProps.DEPRECATED_flareListeners;
if (listeners != null) {
markUpdate(workInProgress);
updateLegacyEventListeners(
listeners,
workInProgress,
rootContainerInstance,
);
}
}

Expand Down Expand Up @@ -1255,7 +1264,12 @@ function completeWork(
if (enableFlareAPI) {
const listeners = newProps.DEPRECATED_flareListeners;
if (listeners != null) {
markUpdate(workInProgress);
const rootContainerInstance = getRootHostContainer();
updateLegacyEventListeners(
listeners,
workInProgress,
rootContainerInstance,
);
}
}
if (workInProgress.ref !== null) {
Expand Down
1 change: 0 additions & 1 deletion packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export type ReactEventResponder<E, C> = {
displayName: string,
targetEventTypes: null | Array<string>,
targetPortalPropagation: boolean,
rootEventTypes: null | Array<string>,
getInitialState: null | ((props: Object) => Object),
onEvent:
| null
Expand Down

0 comments on commit 2afeebd

Please sign in to comment.