UNPKG

4.08 kBJavaScriptView Raw
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 *
7 * @flow
8 */
9
10export type ReactNode =
11 | React$Element<any>
12 | ReactPortal
13 | ReactText
14 | ReactFragment
15 | ReactProvider<any>
16 | ReactConsumer<any>;
17
18export type ReactEmpty = null | void | boolean;
19
20export type ReactFragment = ReactEmpty | Iterable<React$Node>;
21
22export type ReactNodeList = ReactEmpty | React$Node;
23
24export type ReactText = string | number;
25
26export type ReactProvider<T> = {
27 $$typeof: Symbol | number,
28 type: ReactProviderType<T>,
29 key: null | string,
30 ref: null,
31 props: {
32 value: T,
33 children?: ReactNodeList,
34 },
35};
36
37export type ReactProviderType<T> = {
38 $$typeof: Symbol | number,
39 _context: ReactContext<T>,
40};
41
42export type ReactConsumer<T> = {
43 $$typeof: Symbol | number,
44 type: ReactContext<T>,
45 key: null | string,
46 ref: null,
47 props: {
48 children: (value: T) => ReactNodeList,
49 unstable_observedBits?: number,
50 },
51};
52
53export type ReactContext<T> = {
54 $$typeof: Symbol | number,
55 Consumer: ReactContext<T>,
56 Provider: ReactProviderType<T>,
57
58 _calculateChangedBits: ((a: T, b: T) => number) | null,
59
60 _currentValue: T,
61 _currentValue2: T,
62 _threadCount: number,
63
64 // DEV only
65 _currentRenderer?: Object | null,
66 _currentRenderer2?: Object | null,
67};
68
69export type ReactPortal = {
70 $$typeof: Symbol | number,
71 key: null | string,
72 containerInfo: any,
73 children: ReactNodeList,
74 // TODO: figure out the API for cross-renderer implementation.
75 implementation: any,
76};
77
78export type RefObject = {|
79 current: any,
80|};
81
82export type ReactEventResponderInstance<E, C> = {|
83 fiber: Object,
84 props: Object,
85 responder: ReactEventResponder<E, C>,
86 rootEventTypes: null | Set<string>,
87 state: Object,
88 target: mixed,
89|};
90
91export type ReactEventResponderListener<E, C> = {|
92 props: Object,
93 responder: ReactEventResponder<E, C>,
94|};
95
96export type ReactEventResponder<E, C> = {
97 $$typeof: Symbol | number,
98 displayName: string,
99 targetEventTypes: null | Array<string>,
100 rootEventTypes: null | Array<string>,
101 getInitialState: null | ((props: Object) => Object),
102 onEvent:
103 | null
104 | ((event: E, context: C, props: Object, state: Object) => void),
105 onRootEvent:
106 | null
107 | ((event: E, context: C, props: Object, state: Object) => void),
108 onMount: null | ((context: C, props: Object, state: Object) => void),
109 onUnmount: null | ((context: C, props: Object, state: Object) => void),
110 onOwnershipChange:
111 | null
112 | ((context: C, props: Object, state: Object) => void),
113};
114
115export type EventPriority = 0 | 1 | 2;
116
117export const DiscreteEvent: EventPriority = 0;
118export const UserBlockingEvent: EventPriority = 1;
119export const ContinuousEvent: EventPriority = 2;
120
121export type ReactFundamentalComponentInstance<C, H> = {|
122 currentFiber: mixed,
123 instance: mixed,
124 prevProps: null | Object,
125 props: Object,
126 impl: ReactFundamentalImpl<C, H>,
127 state: Object,
128|};
129
130export type ReactFundamentalImpl<C, H> = {
131 displayName: string,
132 reconcileChildren: boolean,
133 getInitialState?: (props: Object) => Object,
134 getInstance: (context: C, props: Object, state: Object) => H,
135 getServerSideString?: (context: C, props: Object) => string,
136 getServerSideStringClose?: (context: C, props: Object) => string,
137 onMount: (context: C, instance: mixed, props: Object, state: Object) => void,
138 shouldUpdate?: (
139 context: C,
140 prevProps: null | Object,
141 nextProps: Object,
142 state: Object,
143 ) => boolean,
144 onUpdate?: (
145 context: C,
146 instance: mixed,
147 prevProps: null | Object,
148 nextProps: Object,
149 state: Object,
150 ) => void,
151 onUnmount?: (
152 context: C,
153 instance: mixed,
154 props: Object,
155 state: Object,
156 ) => void,
157 onHydrate?: (context: C, props: Object, state: Object) => boolean,
158 onFocus?: (context: C, props: Object, state: Object) => boolean,
159};
160
161export type ReactFundamentalComponent<C, H> = {|
162 $$typeof: Symbol | number,
163 impl: ReactFundamentalImpl<C, H>,
164|};