21
22
import type { Fiber } from 'ReactFiber';
23
import type { UpdateQueue } from 'ReactFiberUpdateQueue';
24
-import type { HostChildren } from 'ReactFiberReconciler';
24
25
var ReactFiberReconciler = require('ReactFiberReconciler');
26
var ReactInstanceMap = require('ReactInstanceMap');
31
var scheduledAnimationCallback = null;
32
var scheduledDeferredCallback = null;
33
35
-const TERMINAL_TAG = 99;
36
-const TEXT_TAG = 98;
37
-
34
type Container = { rootID: string, children: Array<Instance | TextInstance> };
35
type Props = { prop: any };
40
-type Instance = { tag: 99, type: string, id: number, children: Array<Instance | TextInstance>, prop: any };
41
-type TextInstance = { tag: 98, text: string };
36
+type Instance = {| type: string, id: number, children: Array<Instance | TextInstance>, prop: any |};
37
+type TextInstance = {| text: string, id: number |};
38
39
var instanceCounter = 0;
40
45
-function recursivelyAppendChildren(
46
- flatArray : Array<Instance | TextInstance>,
47
- child : HostChildren<Instance | TextInstance>
48
-) {
49
- if (!child) {
50
- return;
51
- }
52
- if (child.tag === TERMINAL_TAG || child.tag === TEXT_TAG) {
53
- flatArray.push(child);
54
- } else {
55
- let node = child;
56
- do {
57
- recursivelyAppendChildren(flatArray, node.output);
58
- } while (node = node.sibling);
59
- }
60
-}
61
-
62
-function flattenChildren(children : HostChildren<Instance | TextInstance>) {
63
- const flatArray = [];
64
- recursivelyAppendChildren(flatArray, children);
65
- return flatArray;
66
-}
67
-
41
var NoopRenderer = ReactFiberReconciler({
42
70
- createInstance(type : string, props : Props, children : HostChildren<Instance | TextInstance>) : Instance {
43
+ createInstance(type : string, props : Props) : Instance {
44
const inst = {
72
- tag: TERMINAL_TAG,
45
id: instanceCounter++,
46
type: type,
75
- children: flattenChildren(children),
47
+ children: [],
48
prop: props.prop,
49
};
50
// Hide from unit tests
79
- Object.defineProperty(inst, 'tag', { value: inst.tag, enumerable: false });
51
Object.defineProperty(inst, 'id', { value: inst.id, enumerable: false });
52
return inst;
53
},
54
55
+ appendInitialChild(parentInstance : Instance, child : Instance | TextInstance) : void {
56
+ parentInstance.children.push(child);
57
+ },
58
+
59
+ finalizeInitialChildren(domElement : Instance, type : string, props : Props) : void {
60
+ // Noop
61
+ },
62
+
63
prepareUpdate(instance : Instance, oldProps : Props, newProps : Props) : boolean {
64
return true;
65
},
69
},
70
71
createTextInstance(text : string) : TextInstance {
93
- var inst = { tag: TEXT_TAG, text : text };
72
+ var inst = { text : text, id: instanceCounter++ };
73
// Hide from unit tests
95
- Object.defineProperty(inst, 'tag', { value: inst.tag, enumerable: false });
74
+ Object.defineProperty(inst, 'id', { value: inst.id, enumerable: false });
75
return inst;
76
},
77
188
}
189
// Unsound duck typing.
190
const component = (componentOrElement : any);
212
- if (component.tag === TERMINAL_TAG || component.tag === TEXT_TAG) {
191
+ if (typeof component.id === 'number') {
192
return component;
193
}
194
const inst = ReactInstanceMap.get(component);
253
function logHostInstances(children: Array<Instance | TextInstance>, depth) {
254
for (var i = 0; i < children.length; i++) {
255
var child = children[i];
277
- if (child.tag === TEXT_TAG) {
278
- log(' '.repeat(depth) + '- ' + child.text);
256
+ var indent = ' '.repeat(depth);
257
+ if (typeof child.text === 'string') {
258
+ log(indent + '- ' + child.text);
259
} else {
280
- log(' '.repeat(depth) + '- ' + child.type + '#' + child.id);
260
+ // $FlowFixMe - The child should've been refined now.
261
+ log(indent + '- ' + child.type + '#' + child.id);
262
+ // $FlowFixMe - The child should've been refined now.
263
logHostInstances(child.children, depth + 1);
264
}
265
}