This repository has been archived by the owner on Mar 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
reconciler.ts
247 lines (199 loc) · 5.53 KB
/
reconciler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable class-methods-use-this */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable class-methods-use-this */
import { FC } from 'react';
import ReactReconciler from 'react-reconciler';
type Type = FC;
type Props = any;
type Container = Record<string, never>;
type Instance = any;
type TextInstance = any;
type SuspenseInstance = any;
type HydratableInstance = any;
type PublicInstance = any;
type HostContext = any;
type UpdatePayload = any;
type ChildSet = any;
type TimeoutHandle = any;
type NoTimeout = any;
type OpaqueHandle = ReactReconciler.Fiber;
export class HostConfig
implements
ReactReconciler.HostConfig<
Type,
Props,
Container,
Instance,
TextInstance,
SuspenseInstance,
HydratableInstance,
PublicInstance,
HostContext,
UpdatePayload,
ChildSet, // TODO Placeholder for undocumented API
TimeoutHandle,
NoTimeout
>
{
preparePortalMount(containerInfo: Container): void {
// NoOp
}
scheduleTimeout(fn: (...args: unknown[]) => unknown, delay?: number) {
// NoOp
}
cancelTimeout(id: any): void {
// NoOp
}
queueMicrotask(fn: () => void): void {
// NoOp
}
cloneInstance?: any;
cloneFundamentalInstance?: any;
createContainerChildSet?: any;
appendChildToContainerChildSet?: any;
finalizeContainerChildren?: any;
replaceContainerChildren?: any;
cloneHiddenInstance?: any;
cloneHiddenTextInstance?: any;
public now = Date.now;
public setTimeout = setTimeout;
public clearTimeout = clearTimeout;
public noTimeout: NoTimeout = -1; // TODO
// Temporary workaround for scenario where multiple renderers concurrently
// render using the same context objects. E.g. React DOM and React ART on the
// same page. DOM is the primary renderer; ART is the secondary renderer.
public isPrimaryRenderer = false;
public supportsMutation = false;
public supportsPersistence = false;
public supportsHydration = false;
public getPublicInstance(instance: Instance | TextInstance): PublicInstance {
return instance;
}
public getRootHostContext(rootContainerInstance: Container): HostContext {
return {};
}
public getChildHostContext(
parentHostContext: HostContext,
type: Type,
rootContainerInstance: Container,
): HostContext {
return parentHostContext;
}
public prepareForCommit(containerInfo: Container): Record<string, any> | null {
return null;
}
public resetAfterCommit(containerInfo: Container): void {
// containerInfo.setRoot
}
/**
* Create component instance
*/
public createInstance(
type: Type,
props: Props,
rootContainerInstance: Container,
hostContext: HostContext,
internalInstanceHandle: OpaqueHandle,
): Instance {
// NoOp
return type(props);
}
public appendInitialChild(parentInstance: Instance, child: Instance | TextInstance): void {
parentInstance.appendChild(child);
}
public finalizeInitialChildren(
parentInstance: Instance,
type: Type,
props: Props,
rootContainerInstance: Container,
hostContext: HostContext,
): boolean {
return false;
}
public prepareUpdate(
instance: Instance,
type: Type,
oldProps: Props,
newProps: Props,
rootContainerInstance: Container,
hostContext: HostContext,
): null | UpdatePayload {
return {};
}
public shouldSetTextContent(type: Type, props: Props): boolean {
return false;
}
public shouldDeprioritizeSubtree(type: Type, props: Props): boolean {
return false;
}
public createTextInstance(
text: string,
rootContainerInstance: Container,
hostContext: HostContext,
internalInstanceHandle: OpaqueHandle,
): TextInstance {
return text;
}
public scheduleDeferredCallback(callback: () => any, options?: { timeout: number }): any {
// NoOp
}
public cancelDeferredCallback(callbackID: any): void {
// NoOp
}
// -------------------
// Mutation
// (optional)
// -------------------
public appendChild(parentInstance: Instance, child: Instance | TextInstance): void {
// NoOp
if (parentInstance.appendChild) {
parentInstance.appendChild(child);
}
}
public appendChildToContainer(container: Container, child: Instance | TextInstance): void {
// if (container.appendChild) {
// container.appendChild(child);
// }
}
public commitTextUpdate(textInstance: TextInstance, oldText: string, newText: string): void {
// NoOp
}
public commitMount(instance: Instance, type: Type, newProps: Props, internalInstanceHandle: OpaqueHandle): void {
// NoOp
}
public commitUpdate(
instance: Instance,
updatePayload: UpdatePayload,
type: Type,
oldProps: Props,
newProps: Props,
internalInstanceHandle: OpaqueHandle,
): void {
// NoOp
}
public insertBefore(
parentInstance: Instance,
child: Instance | TextInstance,
beforeChild: Instance | TextInstance,
): void {
// NoOp
}
public insertInContainerBefore(
container: Container,
child: Instance | TextInstance,
beforeChild: Instance | TextInstance,
): void {
// NoOp
}
public removeChild(parentInstance: Instance, child: Instance | TextInstance): void {
// NoOp
}
public removeChildFromContainer(container: Container, child: Instance | TextInstance): void {
// NoOp
}
public resetTextContent(instance: Instance): void {
// NoOp
}
}
export const reconciler = ReactReconciler(new HostConfig());