48
type Instance = {|
49
type: string,
50
id: number,
51
+ parent: number,
52
children: Array<Instance | TextInstance>,
53
text: string | null,
54
prop: any,
58
type TextInstance = {|
59
text: string,
60
id: number,
61
+ parent: number,
62
hidden: boolean,
63
context: HostContext,
64
|};
82
parentInstance: Container | Instance,
83
child: Instance | TextInstance,
84
): void {
85
+ const prevParent = child.parent;
86
+ if (prevParent !== -1 && prevParent !== parentInstance.id) {
87
+ throw new Error('Reparenting is not allowed');
88
+ }
89
+ child.parent = parentInstance.id;
90
const index = parentInstance.children.indexOf(child);
91
if (index !== -1) {
92
parentInstance.children.splice(index, 1);
218
const clone = {
219
id: instance.id,
220
type: type,
221
+ parent: instance.parent,
222
children: keepChildren ? instance.children : [],
223
text: shouldSetTextContent(type, newProps)
224
? computeText((newProps.children: any) + '', instance.context)
231
value: clone.id,
232
enumerable: false,
233
});
234
+ Object.defineProperty(clone, 'parent', {
235
+ value: clone.parent,
236
+ enumerable: false,
237
+ });
238
Object.defineProperty(clone, 'text', {
239
value: clone.text,
240
enumerable: false,
297
id: instanceCounter++,
298
type: type,
299
children: [],
300
+ parent: -1,
301
text: shouldSetTextContent(type, props)
302
? computeText((props.children: any) + '', hostContext)
303
: null,
307
};
308
// Hide from unit tests
309
Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false});
310
+ Object.defineProperty(inst, 'parent', {
311
+ value: inst.parent,
312
+ enumerable: false,
313
+ });
314
Object.defineProperty(inst, 'text', {
315
value: inst.text,
316
enumerable: false,
330
parentInstance: Instance,
331
child: Instance | TextInstance,
332
): void {
333
+ const prevParent = child.parent;
334
+ if (prevParent !== -1 && prevParent !== parentInstance.id) {
335
+ throw new Error('Reparenting is not allowed');
336
+ }
337
+ child.parent = parentInstance.id;
338
parentInstance.children.push(child);
339
},
340
379
const inst = {
380
text: text,
381
id: instanceCounter++,
382
+ parent: -1,
383
hidden: false,
384
context: hostContext,
385
};
386
// Hide from unit tests
387
Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false});
388
+ Object.defineProperty(inst, 'parent', {
389
+ value: inst.parent,
390
+ enumerable: false,
391
+ });
392
Object.defineProperty(inst, 'context', {
393
value: inst.context,
394
enumerable: false,
709
const offscreenTextInstance: TextInstance = {
710
text: instance.text,
711
id: instanceCounter++,
712
+ parent: instance.parent,
713
hidden: hideNearestNode || instance.hidden,
714
context: instance.context,
715
};
718
value: offscreenTextInstance.id,
719
enumerable: false,
720
});
721
+ Object.defineProperty(offscreenTextInstance, 'parent', {
722
+ value: offscreenTextInstance.parent,
723
+ enumerable: false,
724
+ });
725
Object.defineProperty(offscreenTextInstance, 'context', {
726
value: offscreenTextInstance.context,
727
enumerable: false,
757
const clone: Instance = {
758
id: instance.id,
759
type: instance.type,
760
+ parent: instance.parent,
761
children: clonedChildren,
762
text: instance.text,
763
prop: instance.prop,
768
value: clone.id,
769
enumerable: false,
770
});
771
+ Object.defineProperty(clone, 'parent', {
772
+ value: clone.parent,
773
+ enumerable: false,
774
+ });
775
Object.defineProperty(clone, 'text', {
776
value: clone.text,
777
enumerable: false,
791
const clone = {
792
text: textInstance.text,
793
id: textInstance.id,
794
+ parent: textInstance.parent,
795
hidden: textInstance.hidden || hideNearestNode,
796
context: textInstance.context,
797
};
799
value: clone.id,
800
enumerable: false,
801
});
802
+ Object.defineProperty(clone, 'parent', {
803
+ value: clone.parent,
804
+ enumerable: false,
805
+ });
806
Object.defineProperty(clone, 'context', {
807
value: clone.context,
808
enumerable: false,