Adds experimental event API scaffolding (#15108)
* Adds experimental event API scaffolding
Dominic Gannaway committed
Mar 14, 2019 at 17:02 UTC
0c03a474362c27aa9222ae27088782a01402067c
18 files changed
+155
-4
packages/react-art/src/ReactARTHostConfig.js
+16
@@ -430,3 +430,19 @@ export function unhideInstance(instance, props) {
430
export function unhideTextInstance(textInstance, text): void {
431
// Noop
432
}
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
@@ -43,6 +43,7 @@ import {
43
import dangerousStyleValue from '../shared/dangerousStyleValue';
44
45
import type {DOMContainer} from './ReactDOM';
46
+import type {ReactEventResponder} from 'shared/ReactTypes';
47
48
export type Type = string;
49
export type Props = {
@@ -793,3 +794,19 @@ export function didNotFindHydratableSuspenseInstance(
794
// TODO: warnForInsertedHydratedSuspense(parentInstance);
795
}
796
}
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
@@ -14,6 +14,7 @@ import type {
14
NativeMethodsMixinType,
15
ReactNativeBaseComponentViewConfig,
16
} from './ReactNativeTypes';
17
+import type {ReactEventResponder} from 'shared/ReactTypes';
18
19
import {
20
mountSafeCallback_NOT_REALLY_SAFE,
@@ -417,3 +418,19 @@ export function replaceContainerChildren(
418
container: Container,
419
newChildren: ChildSet,
420
): 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
@@ -8,6 +8,7 @@
8
*/
9
10
import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';
11
+import type {ReactEventResponder} from 'shared/ReactTypes';
12
13
import invariant from 'shared/invariant';
14
@@ -476,3 +477,19 @@ export function unhideTextInstance(
477
): void {
478
throw new Error('Not yet implemented.');
479
}
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
@@ -43,6 +43,7 @@ import {
43
IncompleteClassComponent,
44
MemoComponent,
45
SimpleMemoComponent,
46
+ EventTarget,
47
} from 'shared/ReactWorkTags';
48
import {
49
invokeGuardedCallback,
@@ -90,6 +91,7 @@ import {
91
hideTextInstance,
92
unhideInstance,
93
unhideTextInstance,
94
+ handleEventTarget,
95
} from './ReactFiberHostConfig';
96
import {
97
captureCommitPhaseError,
@@ -299,6 +301,7 @@ function commitBeforeMutationLifeCycles(
301
case HostText:
302
case HostPortal:
303
case IncompleteClassComponent:
304
+ case EventTarget:
305
// Nothing to do for these component types
306
return;
307
default: {
@@ -584,8 +587,8 @@ function commitLifeCycles(
587
return;
588
}
589
case SuspenseComponent:
587
- break;
590
case IncompleteClassComponent:
591
+ case EventTarget:
592
break;
593
default: {
594
invariant(
@@ -1213,6 +1216,12 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1216
case IncompleteClassComponent: {
1217
return;
1218
}
1219
+ case EventTarget: {
1220
+ const newProps = finishedWork.memoizedProps;
1221
+ const type = finishedWork.type.type;
1222
+ handleEventTarget(type, newProps, finishedWork);
1223
+ return;
1224
+ }
1225
default: {
1226
invariant(
1227
false,
packages/react-reconciler/src/ReactFiberCompleteWork.js
+13
@@ -38,6 +38,8 @@ import {
38
SimpleMemoComponent,
39
LazyComponent,
40
IncompleteClassComponent,
41
+ EventComponent,
42
+ EventTarget,
43
} from 'shared/ReactWorkTags';
44
import {
45
Placement,
@@ -63,6 +65,7 @@ import {
65
createContainerChildSet,
66
appendChildToContainerChildSet,
67
finalizeContainerChildren,
68
+ handleEventComponent,
69
} from './ReactFiberHostConfig';
70
import {
71
getRootHostContainer,
@@ -762,6 +765,16 @@ function completeWork(
765
}
766
break;
767
}
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
+ }
778
default:
779
invariant(
780
false,
packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js
+2
@@ -59,6 +59,8 @@ export const isPrimaryRenderer = $$$hostConfig.isPrimaryRenderer;
59
export const supportsMutation = $$$hostConfig.supportsMutation;
60
export const supportsPersistence = $$$hostConfig.supportsPersistence;
61
export const supportsHydration = $$$hostConfig.supportsHydration;
62
+export const handleEventComponent = $$$hostConfig.handleEventComponent;
63
+export const handleEventTarget = $$$hostConfig.handleEventTarget;
64
65
// -------------------
66
// Mutation
packages/react-test-renderer/src/ReactTestHostConfig.js
+18
@@ -9,6 +9,8 @@
9
10
import warning from 'shared/warning';
11
12
+import type {ReactEventResponder} from 'shared/ReactTypes';
13
+
14
export type Type = string;
15
export type Props = Object;
16
export type Container = {|
@@ -260,3 +262,19 @@ export function unhideTextInstance(
262
): void {
263
textInstance.isHidden = false;
264
}
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
@@ -58,3 +58,6 @@ export const warnAboutShorthandPropertyCollision = false;
58
// See https://github.com/react-native-community/discussions-and-proposals/issues/72 for more information
59
// This is a flag so we can fix warnings in RN core before turning it on
60
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
@@ -46,6 +46,12 @@ export const REACT_SUSPENSE_TYPE = hasSymbol
46
: 0xead1;
47
export const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
48
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;
55
56
const MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
57
const FAUX_ITERATOR_SYMBOL = '@@iterator';
packages/shared/ReactTypes.js
+20
-1
@@ -13,7 +13,9 @@ export type ReactNode =
13
| ReactText
14
| ReactFragment
15
| ReactProvider<any>
16
- | ReactConsumer<any>;
16
+ | ReactConsumer<any>
17
+ | ReactEvent
18
+ | ReactEventTarget;
19
20
export type ReactEmpty = null | void | boolean;
21
@@ -78,3 +80,20 @@ export type ReactPortal = {
80
export type RefObject = {|
81
current: any,
82
|};
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
@@ -26,7 +26,9 @@ export type WorkTag =
26
| 15
27
| 16
28
| 17
29
- | 18;
29
+ | 18
30
+ | 19
31
+ | 20;
32
33
export const FunctionComponent = 0;
34
export const ClassComponent = 1;
@@ -47,3 +49,5 @@ export const SimpleMemoComponent = 15;
49
export const LazyComponent = 16;
50
export const IncompleteClassComponent = 17;
51
export const DehydratedSuspenseComponent = 18;
52
+export const EventComponent = 19;
53
+export const EventTarget = 20;
packages/shared/forks/ReactFeatureFlags.native-fb.js
+1
@@ -29,6 +29,7 @@ export const disableInputAttributeSyncing = false;
29
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
30
export const warnAboutDeprecatedLifecycles = true;
31
export const warnAboutDeprecatedSetNativeProps = true;
32
+export const enableEventAPI = false;
33
34
// Only used in www builds.
35
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.native-oss.js
+1
@@ -26,6 +26,7 @@ export const enableStableConcurrentModeAPIs = false;
26
export const warnAboutShorthandPropertyCollision = false;
27
export const enableSchedulerDebugging = false;
28
export const warnAboutDeprecatedSetNativeProps = false;
29
+export const enableEventAPI = false;
30
31
// Only used in www builds.
32
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.persistent.js
+1
@@ -26,6 +26,7 @@ export const enableStableConcurrentModeAPIs = false;
26
export const warnAboutShorthandPropertyCollision = false;
27
export const enableSchedulerDebugging = false;
28
export const warnAboutDeprecatedSetNativeProps = false;
29
+export const enableEventAPI = false;
30
31
// Only used in www builds.
32
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.test-renderer.www.js
+1
@@ -24,6 +24,7 @@ export const enableStableConcurrentModeAPIs = false;
24
export const enableSchedulerDebugging = false;
25
export const warnAboutDeprecatedSetNativeProps = false;
26
export const disableJavaScriptURLs = false;
27
+export const enableEventAPI = true;
28
29
// Only used in www builds.
30
export function addUserTimingListener() {
packages/shared/forks/ReactFeatureFlags.www.js
+2
@@ -65,6 +65,8 @@ function updateFlagOutsideOfReactCallStack() {
65
}
66
}
67
68
+export const enableEventAPI = true;
69
+
70
// Flow magic to verify the exports of this file match the original version.
71
// eslint-disable-next-line no-unused-vars
72
type Check<_X, Y: _X, X: Y = _X> = null;
packages/shared/isValidElementType.js
+5
-1
@@ -18,6 +18,8 @@ import {
18
REACT_SUSPENSE_TYPE,
19
REACT_MEMO_TYPE,
20
REACT_LAZY_TYPE,
21
+ REACT_EVENT_COMPONENT_TYPE,
22
+ REACT_EVENT_TARGET_TYPE,
23
} from 'shared/ReactSymbols';
24
25
export default function isValidElementType(type: mixed) {
@@ -36,6 +38,8 @@ export default function isValidElementType(type: mixed) {
38
type.$$typeof === REACT_MEMO_TYPE ||
39
type.$$typeof === REACT_PROVIDER_TYPE ||
40
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))
44
);
45
}