@@ -11,30 +11,36 @@ import emptyObject from 'fbjs/lib/emptyObject';
11
11
12
12
import * as TestRendererScheduling from './ReactTestRendererScheduling' ;
13
13
14
+ export type Type = string ;
15
+ export type Props = Object ;
16
+ export type Container = { |
17
+ children : Array < Instance | TextInstance > ,
18
+ createNodeMock : Function ,
19
+ tag : 'CONTAINER' ,
20
+ | } ;
14
21
export type Instance = { |
15
22
type : string ,
16
23
props : Object ,
17
24
children : Array < Instance | TextInstance > ,
18
25
rootContainerInstance : Container ,
19
26
tag : 'INSTANCE' ,
20
27
| } ;
21
-
22
28
export type TextInstance = { |
23
29
text : string ,
24
30
tag : 'TEXT' ,
25
31
| } ;
26
-
27
- type Container = { |
28
- children : Array < Instance | TextInstance > ,
29
- createNodeMock : Function ,
30
- tag : 'CONTAINER' ,
31
- | } ;
32
-
33
- type Props = Object ;
32
+ export type HydratableInstance = Instance | TextInstance ;
33
+ export type PublicInstance = Instance | TextInstance ;
34
+ export type HostContext = Object ;
35
+ export type UpdatePayload = Object ;
36
+ export type ChildSet = void ; // Unused
34
37
35
38
const UPDATE_SIGNAL = { } ;
36
39
37
- function getPublicInstance ( inst : Instance | TextInstance ) : * {
40
+ export * from 'shared/HostConfigWithNoPersistence' ;
41
+ export * from 'shared/HostConfigWithNoHydration' ;
42
+
43
+ export function getPublicInstance ( inst : Instance | TextInstance ) : * {
38
44
switch ( inst . tag ) {
39
45
case 'INSTANCE' :
40
46
const createNodeMock = inst . rootContainerInstance . createNodeMock ;
@@ -47,7 +53,7 @@ function getPublicInstance(inst: Instance | TextInstance): * {
47
53
}
48
54
}
49
55
50
- function appendChild (
56
+ export function appendChild (
51
57
parentInstance : Instance | Container ,
52
58
child : Instance | TextInstance ,
53
59
) : void {
@@ -58,7 +64,7 @@ function appendChild(
58
64
parentInstance . children . push ( child ) ;
59
65
}
60
66
61
- function insertBefore (
67
+ export function insertBefore (
62
68
parentInstance : Instance | Container ,
63
69
child : Instance | TextInstance ,
64
70
beforeChild : Instance | TextInstance ,
@@ -71,148 +77,152 @@ function insertBefore(
71
77
parentInstance . children . splice ( beforeIndex , 0 , child ) ;
72
78
}
73
79
74
- function removeChild (
80
+ export function removeChild (
75
81
parentInstance : Instance | Container ,
76
82
child : Instance | TextInstance ,
77
83
) : void {
78
84
const index = parentInstance . children . indexOf ( child ) ;
79
85
parentInstance . children . splice ( index , 1 ) ;
80
86
}
81
87
82
- const ReactTestHostConfig = {
83
- getRootHostContext ( ) {
84
- return emptyObject ;
85
- } ,
86
-
87
- getChildHostContext ( ) {
88
- return emptyObject ;
89
- } ,
90
-
91
- prepareForCommit ( ) : void {
92
- // noop
93
- } ,
94
-
95
- resetAfterCommit ( ) : void {
96
- // noop
97
- } ,
98
-
99
- createInstance (
100
- type : string ,
101
- props : Props ,
102
- rootContainerInstance : Container ,
103
- hostContext : Object ,
104
- internalInstanceHandle : Object ,
105
- ) : Instance {
106
- return {
107
- type ,
108
- props ,
109
- children : [ ] ,
110
- rootContainerInstance ,
111
- tag : 'INSTANCE' ,
112
- } ;
113
- } ,
114
-
115
- appendInitialChild (
116
- parentInstance : Instance ,
117
- child : Instance | TextInstance ,
118
- ) : void {
119
- const index = parentInstance . children . indexOf ( child ) ;
120
- if ( index !== - 1 ) {
121
- parentInstance . children . splice ( index , 1 ) ;
122
- }
123
- parentInstance . children . push ( child ) ;
124
- } ,
125
-
126
- finalizeInitialChildren (
127
- testElement : Instance ,
128
- type : string ,
129
- props : Props ,
130
- rootContainerInstance : Container ,
131
- ) : boolean {
132
- return false ;
133
- } ,
134
-
135
- prepareUpdate (
136
- testElement : Instance ,
137
- type : string ,
138
- oldProps : Props ,
139
- newProps : Props ,
140
- rootContainerInstance : Container ,
141
- hostContext : Object ,
142
- ) : null | { } {
143
- return UPDATE_SIGNAL ;
144
- } ,
145
-
146
- shouldSetTextContent ( type : string , props : Props ) : boolean {
147
- return false ;
148
- } ,
149
-
150
- shouldDeprioritizeSubtree ( type : string , props : Props ) : boolean {
151
- return false ;
152
- } ,
153
-
154
- createTextInstance (
155
- text : string ,
156
- rootContainerInstance : Container ,
157
- hostContext : Object ,
158
- internalInstanceHandle : Object ,
159
- ) : TextInstance {
160
- return {
161
- text,
162
- tag : 'TEXT' ,
163
- } ;
164
- } ,
165
-
166
- getPublicInstance ,
167
-
168
- scheduleDeferredCallback : TestRendererScheduling . scheduleDeferredCallback ,
169
- cancelDeferredCallback : TestRendererScheduling . cancelDeferredCallback ,
170
- // This approach enables `now` to be mocked by tests,
171
- // Even after the reconciler has initialized and read host config values.
172
- now : ( ) = > TestRendererScheduling . nowImplementation ( ) ,
173
-
174
- isPrimaryRenderer : true ,
175
-
176
- mutation : {
177
- commitUpdate (
178
- instance : Instance ,
179
- updatePayload : { } ,
180
- type : string ,
181
- oldProps : Props ,
182
- newProps : Props ,
183
- internalInstanceHandle : Object ,
184
- ) : void {
185
- instance . type = type ;
186
- instance . props = newProps;
187
- } ,
188
-
189
- commitMount (
190
- instance : Instance ,
191
- type : string ,
192
- newProps : Props ,
193
- internalInstanceHandle : Object ,
194
- ) : void {
195
- // noop
196
- } ,
197
-
198
- commitTextUpdate (
199
- textInstance : TextInstance ,
200
- oldText : string ,
201
- newText : string ,
202
- ) : void {
203
- textInstance. text = newText ;
204
- } ,
205
- resetTextContent ( testElement : Instance ) : void {
206
- // noop
207
- } ,
208
-
209
- appendChild : appendChild ,
210
- appendChildToContainer : appendChild ,
211
- insertBefore : insertBefore ,
212
- insertInContainerBefore : insertBefore ,
213
- removeChild : removeChild ,
214
- removeChildFromContainer : removeChild ,
215
- } ,
216
- } ;
217
-
218
- export default ReactTestHostConfig ;
88
+ export function getRootHostContext (
89
+ rootContainerInstance : Container ,
90
+ ) : HostContext {
91
+ return emptyObject ;
92
+ }
93
+
94
+ export function getChildHostContext (
95
+ parentHostContext : HostContext ,
96
+ type : string ,
97
+ rootContainerInstance : Container ,
98
+ ) : HostContext {
99
+ return emptyObject ;
100
+ }
101
+
102
+ export function prepareForCommit ( containerInfo : Container ) : void {
103
+ // noop
104
+ }
105
+
106
+ export function resetAfterCommit ( containerInfo : Container ) : void {
107
+ // noop
108
+ }
109
+
110
+ export function createInstance (
111
+ type : string ,
112
+ props : Props ,
113
+ rootContainerInstance : Container ,
114
+ hostContext : Object ,
115
+ internalInstanceHandle : Object ,
116
+ ) : Instance {
117
+ return {
118
+ type ,
119
+ props ,
120
+ children : [ ] ,
121
+ rootContainerInstance ,
122
+ tag : 'INSTANCE' ,
123
+ } ;
124
+ }
125
+
126
+ export function appendInitialChild (
127
+ parentInstance : Instance ,
128
+ child : Instance | TextInstance ,
129
+ ) : void {
130
+ const index = parentInstance . children . indexOf ( child ) ;
131
+ if ( index !== - 1 ) {
132
+ parentInstance . children . splice ( index , 1 ) ;
133
+ }
134
+ parentInstance . children . push ( child ) ;
135
+ }
136
+
137
+ export function finalizeInitialChildren (
138
+ testElement : Instance ,
139
+ type : string ,
140
+ props : Props ,
141
+ rootContainerInstance : Container ,
142
+ hostContext : Object ,
143
+ ) : boolean {
144
+ return false ;
145
+ }
146
+
147
+ export function prepareUpdate (
148
+ testElement : Instance ,
149
+ type : string ,
150
+ oldProps : Props ,
151
+ newProps : Props ,
152
+ rootContainerInstance : Container ,
153
+ hostContext : Object ,
154
+ ) : null | { } {
155
+ return UPDATE_SIGNAL ;
156
+ }
157
+
158
+ export function shouldSetTextContent ( type : string , props : Props ) : boolean {
159
+ return false ;
160
+ }
161
+
162
+ export function shouldDeprioritizeSubtree ( type : string , props : Props ) : boolean {
163
+ return false ;
164
+ }
165
+
166
+ export function createTextInstance (
167
+ text : string ,
168
+ rootContainerInstance : Container ,
169
+ hostContext : Object ,
170
+ internalInstanceHandle : Object ,
171
+ ) : TextInstance {
172
+ return {
173
+ text,
174
+ tag : 'TEXT' ,
175
+ } ;
176
+ }
177
+
178
+ export const isPrimaryRenderer = true ;
179
+ // This approach enables `now` to be mocked by tests,
180
+ // Even after the reconciler has initialized and read host config values.
181
+ export const now = ( ) => TestRendererScheduling . nowImplementation ( ) ;
182
+ export const scheduleDeferredCallback =
183
+ TestRendererScheduling . scheduleDeferredCallback ;
184
+ export const cancelDeferredCallback =
185
+ TestRendererScheduling . cancelDeferredCallback ;
186
+
187
+ // -------------------
188
+ // Mutation
189
+ // -------------------
190
+
191
+ export const supportsMutation = true ;
192
+
193
+ export function commitUpdate (
194
+ instance : Instance ,
195
+ updatePayload : { } ,
196
+ type : string ,
197
+ oldProps : Props ,
198
+ newProps : Props ,
199
+ internalInstanceHandle : Object ,
200
+ ) : void {
201
+ instance . type = type ;
202
+ instance . props = newProps ;
203
+ }
204
+
205
+ export function commitMount (
206
+ instance : Instance ,
207
+ type : string ,
208
+ newProps : Props ,
209
+ internalInstanceHandle : Object ,
210
+ ) : void {
211
+ // noop
212
+ }
213
+
214
+ export function commitTextUpdate (
215
+ textInstance : TextInstance ,
216
+ oldText : string ,
217
+ newText : string ,
218
+ ) : void {
219
+ textInstance . text = newText ;
220
+ }
221
+
222
+ export function resetTextContent ( testElement : Instance ) : void {
223
+ // noop
224
+ }
225
+
226
+ export const appendChildToContainer = appendChild ;
227
+ export const insertInContainerBefore = insertBefore ;
228
+ export const removeChildFromContainer = removeChild ;
0 commit comments