Skip to content

Commit 0c03a47

Browse files
authored
Adds experimental event API scaffolding (#15108)
* Adds experimental event API scaffolding
1 parent 679402a commit 0c03a47

18 files changed

+155
-4
lines changed

packages/react-art/src/ReactARTHostConfig.js

+16
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,19 @@ export function unhideInstance(instance, props) {
430430
export function unhideTextInstance(textInstance, text): void {
431431
// Noop
432432
}
433+
434+
export function handleEventComponent(
435+
eventResponder: ReactEventResponder,
436+
rootContainerInstance: Container,
437+
internalInstanceHandle: Object,
438+
) {
439+
// TODO: add handleEventComponent implementation
440+
}
441+
442+
export function handleEventTarget(
443+
type: string,
444+
props: Props,
445+
internalInstanceHandle: Object,
446+
) {
447+
// TODO: add handleEventTarget implementation
448+
}

packages/react-dom/src/client/ReactDOMHostConfig.js

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
import dangerousStyleValue from '../shared/dangerousStyleValue';
4444

4545
import type {DOMContainer} from './ReactDOM';
46+
import type {ReactEventResponder} from 'shared/ReactTypes';
4647

4748
export type Type = string;
4849
export type Props = {
@@ -793,3 +794,19 @@ export function didNotFindHydratableSuspenseInstance(
793794
// TODO: warnForInsertedHydratedSuspense(parentInstance);
794795
}
795796
}
797+
798+
export function handleEventComponent(
799+
eventResponder: ReactEventResponder,
800+
rootContainerInstance: Container,
801+
internalInstanceHandle: Object,
802+
) {
803+
// TODO: add handleEventComponent implementation
804+
}
805+
806+
export function handleEventTarget(
807+
type: string,
808+
props: Props,
809+
internalInstanceHandle: Object,
810+
) {
811+
// TODO: add handleEventTarget implementation
812+
}

packages/react-native-renderer/src/ReactFabricHostConfig.js

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
NativeMethodsMixinType,
1515
ReactNativeBaseComponentViewConfig,
1616
} from './ReactNativeTypes';
17+
import type {ReactEventResponder} from 'shared/ReactTypes';
1718

1819
import {
1920
mountSafeCallback_NOT_REALLY_SAFE,
@@ -417,3 +418,19 @@ export function replaceContainerChildren(
417418
container: Container,
418419
newChildren: ChildSet,
419420
): void {}
421+
422+
export function handleEventComponent(
423+
eventResponder: ReactEventResponder,
424+
rootContainerInstance: Container,
425+
internalInstanceHandle: Object,
426+
) {
427+
// TODO: add handleEventComponent implementation
428+
}
429+
430+
export function handleEventTarget(
431+
type: string,
432+
props: Props,
433+
internalInstanceHandle: Object,
434+
) {
435+
// TODO: add handleEventTarget implementation
436+
}

packages/react-native-renderer/src/ReactNativeHostConfig.js

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';
11+
import type {ReactEventResponder} from 'shared/ReactTypes';
1112

1213
import invariant from 'shared/invariant';
1314

@@ -476,3 +477,19 @@ export function unhideTextInstance(
476477
): void {
477478
throw new Error('Not yet implemented.');
478479
}
480+
481+
export function handleEventComponent(
482+
eventResponder: ReactEventResponder,
483+
rootContainerInstance: Container,
484+
internalInstanceHandle: Object,
485+
) {
486+
// TODO: add handleEventComponent implementation
487+
}
488+
489+
export function handleEventTarget(
490+
type: string,
491+
props: Props,
492+
internalInstanceHandle: Object,
493+
) {
494+
// TODO: add handleEventTarget implementation
495+
}

packages/react-reconciler/src/ReactFiberCommitWork.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
IncompleteClassComponent,
4444
MemoComponent,
4545
SimpleMemoComponent,
46+
EventTarget,
4647
} from 'shared/ReactWorkTags';
4748
import {
4849
invokeGuardedCallback,
@@ -90,6 +91,7 @@ import {
9091
hideTextInstance,
9192
unhideInstance,
9293
unhideTextInstance,
94+
handleEventTarget,
9395
} from './ReactFiberHostConfig';
9496
import {
9597
captureCommitPhaseError,
@@ -299,6 +301,7 @@ function commitBeforeMutationLifeCycles(
299301
case HostText:
300302
case HostPortal:
301303
case IncompleteClassComponent:
304+
case EventTarget:
302305
// Nothing to do for these component types
303306
return;
304307
default: {
@@ -584,8 +587,8 @@ function commitLifeCycles(
584587
return;
585588
}
586589
case SuspenseComponent:
587-
break;
588590
case IncompleteClassComponent:
591+
case EventTarget:
589592
break;
590593
default: {
591594
invariant(
@@ -1213,6 +1216,12 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
12131216
case IncompleteClassComponent: {
12141217
return;
12151218
}
1219+
case EventTarget: {
1220+
const newProps = finishedWork.memoizedProps;
1221+
const type = finishedWork.type.type;
1222+
handleEventTarget(type, newProps, finishedWork);
1223+
return;
1224+
}
12161225
default: {
12171226
invariant(
12181227
false,

packages/react-reconciler/src/ReactFiberCompleteWork.js

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import {
3838
SimpleMemoComponent,
3939
LazyComponent,
4040
IncompleteClassComponent,
41+
EventComponent,
42+
EventTarget,
4143
} from 'shared/ReactWorkTags';
4244
import {
4345
Placement,
@@ -63,6 +65,7 @@ import {
6365
createContainerChildSet,
6466
appendChildToContainerChildSet,
6567
finalizeContainerChildren,
68+
handleEventComponent,
6669
} from './ReactFiberHostConfig';
6770
import {
6871
getRootHostContainer,
@@ -762,6 +765,16 @@ function completeWork(
762765
}
763766
break;
764767
}
768+
case EventComponent: {
769+
const rootContainerInstance = getRootHostContainer();
770+
const responder = workInProgress.type.responder;
771+
handleEventComponent(responder, rootContainerInstance, workInProgress);
772+
break;
773+
}
774+
case EventTarget: {
775+
markUpdate(workInProgress);
776+
break;
777+
}
765778
default:
766779
invariant(
767780
false,

packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export const isPrimaryRenderer = $$$hostConfig.isPrimaryRenderer;
5959
export const supportsMutation = $$$hostConfig.supportsMutation;
6060
export const supportsPersistence = $$$hostConfig.supportsPersistence;
6161
export const supportsHydration = $$$hostConfig.supportsHydration;
62+
export const handleEventComponent = $$$hostConfig.handleEventComponent;
63+
export const handleEventTarget = $$$hostConfig.handleEventTarget;
6264

6365
// -------------------
6466
// Mutation

packages/react-test-renderer/src/ReactTestHostConfig.js

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import warning from 'shared/warning';
1111

12+
import type {ReactEventResponder} from 'shared/ReactTypes';
13+
1214
export type Type = string;
1315
export type Props = Object;
1416
export type Container = {|
@@ -260,3 +262,19 @@ export function unhideTextInstance(
260262
): void {
261263
textInstance.isHidden = false;
262264
}
265+
266+
export function handleEventComponent(
267+
eventResponder: ReactEventResponder,
268+
rootContainerInstance: Container,
269+
internalInstanceHandle: Object,
270+
) {
271+
// TODO: add handleEventComponent implementation
272+
}
273+
274+
export function handleEventTarget(
275+
type: string,
276+
props: Props,
277+
internalInstanceHandle: Object,
278+
) {
279+
// TODO: add handleEventTarget implementation
280+
}

packages/shared/ReactFeatureFlags.js

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ export const warnAboutShorthandPropertyCollision = false;
5858
// See https://github.com/react-native-community/discussions-and-proposals/issues/72 for more information
5959
// This is a flag so we can fix warnings in RN core before turning it on
6060
export const warnAboutDeprecatedSetNativeProps = false;
61+
62+
// Experimental React Events support. Only used in www builds for now.
63+
export const enableEventAPI = false;

packages/shared/ReactSymbols.js

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export const REACT_SUSPENSE_TYPE = hasSymbol
4646
: 0xead1;
4747
export const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
4848
export const REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
49+
export const REACT_EVENT_COMPONENT_TYPE = hasSymbol
50+
? Symbol.for('react.event')
51+
: 0xead5;
52+
export const REACT_EVENT_TARGET_TYPE = hasSymbol
53+
? Symbol.for('react.event_target')
54+
: 0xead6;
4955

5056
const MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
5157
const FAUX_ITERATOR_SYMBOL = '@@iterator';

packages/shared/ReactTypes.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export type ReactNode =
1313
| ReactText
1414
| ReactFragment
1515
| ReactProvider<any>
16-
| ReactConsumer<any>;
16+
| ReactConsumer<any>
17+
| ReactEvent
18+
| ReactEventTarget;
1719

1820
export type ReactEmpty = null | void | boolean;
1921

@@ -78,3 +80,20 @@ export type ReactPortal = {
7880
export type RefObject = {|
7981
current: any,
8082
|};
83+
84+
export type ReactEventResponder = {
85+
targetEventTypes: Array<string>,
86+
createInitialState?: (props: Object) => Object,
87+
handleEvent: (context: Object, props: Object, state: Object) => void,
88+
};
89+
90+
export type ReactEvent = {|
91+
$$typeof: Symbol | number,
92+
props: null | Object,
93+
responder: ReactEventResponder,
94+
|};
95+
96+
export type ReactEventTarget = {|
97+
$$typeof: Symbol | number,
98+
type: string,
99+
|};

packages/shared/ReactWorkTags.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export type WorkTag =
2626
| 15
2727
| 16
2828
| 17
29-
| 18;
29+
| 18
30+
| 19
31+
| 20;
3032

3133
export const FunctionComponent = 0;
3234
export const ClassComponent = 1;
@@ -47,3 +49,5 @@ export const SimpleMemoComponent = 15;
4749
export const LazyComponent = 16;
4850
export const IncompleteClassComponent = 17;
4951
export const DehydratedSuspenseComponent = 18;
52+
export const EventComponent = 19;
53+
export const EventTarget = 20;

packages/shared/forks/ReactFeatureFlags.native-fb.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const disableInputAttributeSyncing = false;
2929
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
3030
export const warnAboutDeprecatedLifecycles = true;
3131
export const warnAboutDeprecatedSetNativeProps = true;
32+
export const enableEventAPI = false;
3233

3334
// Only used in www builds.
3435
export function addUserTimingListener() {

packages/shared/forks/ReactFeatureFlags.native-oss.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const enableStableConcurrentModeAPIs = false;
2626
export const warnAboutShorthandPropertyCollision = false;
2727
export const enableSchedulerDebugging = false;
2828
export const warnAboutDeprecatedSetNativeProps = false;
29+
export const enableEventAPI = false;
2930

3031
// Only used in www builds.
3132
export function addUserTimingListener() {

packages/shared/forks/ReactFeatureFlags.persistent.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const enableStableConcurrentModeAPIs = false;
2626
export const warnAboutShorthandPropertyCollision = false;
2727
export const enableSchedulerDebugging = false;
2828
export const warnAboutDeprecatedSetNativeProps = false;
29+
export const enableEventAPI = false;
2930

3031
// Only used in www builds.
3132
export function addUserTimingListener() {

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const enableStableConcurrentModeAPIs = false;
2424
export const enableSchedulerDebugging = false;
2525
export const warnAboutDeprecatedSetNativeProps = false;
2626
export const disableJavaScriptURLs = false;
27+
export const enableEventAPI = true;
2728

2829
// Only used in www builds.
2930
export function addUserTimingListener() {

packages/shared/forks/ReactFeatureFlags.www.js

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ function updateFlagOutsideOfReactCallStack() {
6565
}
6666
}
6767

68+
export const enableEventAPI = true;
69+
6870
// Flow magic to verify the exports of this file match the original version.
6971
// eslint-disable-next-line no-unused-vars
7072
type Check<_X, Y: _X, X: Y = _X> = null;

packages/shared/isValidElementType.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
REACT_SUSPENSE_TYPE,
1919
REACT_MEMO_TYPE,
2020
REACT_LAZY_TYPE,
21+
REACT_EVENT_COMPONENT_TYPE,
22+
REACT_EVENT_TARGET_TYPE,
2123
} from 'shared/ReactSymbols';
2224

2325
export default function isValidElementType(type: mixed) {
@@ -36,6 +38,8 @@ export default function isValidElementType(type: mixed) {
3638
type.$$typeof === REACT_MEMO_TYPE ||
3739
type.$$typeof === REACT_PROVIDER_TYPE ||
3840
type.$$typeof === REACT_CONTEXT_TYPE ||
39-
type.$$typeof === REACT_FORWARD_REF_TYPE))
41+
type.$$typeof === REACT_FORWARD_REF_TYPE ||
42+
type.$$typeof === REACT_EVENT_COMPONENT_TYPE ||
43+
type.$$typeof === REACT_EVENT_TARGET_TYPE))
4044
);
4145
}

0 commit comments

Comments
 (0)