@@ -41,10 +41,18 @@ type Instance = {|
41
41
text : string | null ,
42
42
prop : any ,
43
43
hidden : boolean ,
44
+ context : HostContext ,
44
45
| } ;
45
- type TextInstance = { | text : string , id : number , hidden : boolean | } ;
46
+ type TextInstance = { |
47
+ text : string ,
48
+ id : number ,
49
+ hidden : boolean ,
50
+ context : HostContext ,
51
+ | } ;
52
+ type HostContext = Object ;
46
53
47
54
const NO_CONTEXT = { } ;
55
+ const UPPERCASE_CONTEXT = { } ;
48
56
const UPDATE_SIGNAL = { } ;
49
57
if ( __DEV__ ) {
50
58
Object . freeze ( NO_CONTEXT ) ;
@@ -190,10 +198,11 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
190
198
type : type ,
191
199
children : keepChildren ? instance . children : [ ] ,
192
200
text : shouldSetTextContent ( type , newProps )
193
- ? ( newProps . children : any ) + ''
201
+ ? computeText ( ( newProps . children : any ) + '' , instance . context )
194
202
: null ,
195
203
prop : newProps . prop ,
196
204
hidden : newProps . hidden === true ,
205
+ context : instance . context ,
197
206
} ;
198
207
Object . defineProperty ( clone , 'id' , {
199
208
value : clone . id ,
@@ -203,6 +212,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
203
212
value : clone . text ,
204
213
enumerable : false ,
205
214
} ) ;
215
+ Object . defineProperty ( clone , 'context' , {
216
+ value : clone . context ,
217
+ enumerable : false ,
218
+ } ) ;
206
219
hostCloneCounter ++ ;
207
220
return clone ;
208
221
}
@@ -216,20 +229,36 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
216
229
) ;
217
230
}
218
231
232
+ function computeText ( rawText , hostContext ) {
233
+ return hostContext === UPPERCASE_CONTEXT ? rawText . toUpperCase ( ) : rawText ;
234
+ }
235
+
219
236
const sharedHostConfig = {
220
237
getRootHostContext ( ) {
221
238
return NO_CONTEXT ;
222
239
} ,
223
240
224
- getChildHostContext ( ) {
241
+ getChildHostContext (
242
+ parentHostContext : HostContext ,
243
+ type : string ,
244
+ rootcontainerInstance : Container ,
245
+ ) {
246
+ if ( type === 'uppercase' ) {
247
+ return UPPERCASE_CONTEXT ;
248
+ }
225
249
return NO_CONTEXT ;
226
250
} ,
227
251
228
252
getPublicInstance ( instance ) {
229
253
return instance ;
230
254
} ,
231
255
232
- createInstance ( type : string , props : Props ) : Instance {
256
+ createInstance (
257
+ type : string ,
258
+ props : Props ,
259
+ rootContainerInstance : Container ,
260
+ hostContext : HostContext ,
261
+ ) : Instance {
233
262
if ( type === 'errorInCompletePhase' ) {
234
263
throw new Error ( 'Error in host config.' ) ;
235
264
}
@@ -238,17 +267,22 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
238
267
type : type ,
239
268
children : [ ] ,
240
269
text : shouldSetTextContent ( type , props )
241
- ? ( props . children : any ) + ''
270
+ ? computeText ( ( props . children : any ) + '' , hostContext )
242
271
: null ,
243
272
prop : props . prop ,
244
273
hidden : props . hidden === true ,
274
+ context : hostContext ,
245
275
} ;
246
276
// Hide from unit tests
247
277
Object . defineProperty ( inst , 'id' , { value : inst . id , enumerable : false } ) ;
248
278
Object . defineProperty ( inst , 'text' , {
249
279
value : inst . text ,
250
280
enumerable : false ,
251
281
} ) ;
282
+ Object . defineProperty ( inst , 'context' , {
283
+ value : inst . context ,
284
+ enumerable : false ,
285
+ } ) ;
252
286
return inst ;
253
287
} ,
254
288
@@ -298,9 +332,21 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
298
332
hostContext : Object ,
299
333
internalInstanceHandle : Object ,
300
334
) : TextInstance {
301
- const inst = { text : text , id : instanceCounter ++ , hidden : false } ;
335
+ if ( hostContext === UPPERCASE_CONTEXT ) {
336
+ text = text . toUpperCase ( ) ;
337
+ }
338
+ const inst = {
339
+ text : text ,
340
+ id : instanceCounter ++ ,
341
+ hidden : false ,
342
+ context : hostContext ,
343
+ } ;
302
344
// Hide from unit tests
303
345
Object . defineProperty ( inst , 'id' , { value : inst . id , enumerable : false } ) ;
346
+ Object . defineProperty ( inst , 'context' , {
347
+ value : inst . context ,
348
+ enumerable : false ,
349
+ } ) ;
304
350
return inst ;
305
351
} ,
306
352
@@ -343,7 +389,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
343
389
instance . prop = newProps . prop ;
344
390
instance . hidden = newProps . hidden === true ;
345
391
if ( shouldSetTextContent ( type , newProps ) ) {
346
- instance . text = ( newProps . children : any ) + '' ;
392
+ instance . text = computeText (
393
+ ( newProps . children : any ) + '' ,
394
+ instance . context ,
395
+ ) ;
347
396
}
348
397
} ,
349
398
@@ -353,7 +402,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
353
402
newText : string ,
354
403
) : void {
355
404
hostUpdateCounter ++ ;
356
- textInstance . text = newText ;
405
+ textInstance . text = computeText ( newText , textInstance . context ) ;
357
406
} ,
358
407
359
408
appendChild ,
@@ -453,23 +502,54 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
453
502
true ,
454
503
null ,
455
504
) ;
456
- clone . hidden = props . hidden ;
505
+ clone . hidden = props . hidden === true ;
506
+ return clone ;
507
+ } ,
508
+
509
+ cloneHiddenTextInstance (
510
+ instance : TextInstance ,
511
+ text : string ,
512
+ internalInstanceHandle : Object ,
513
+ ) : TextInstance {
514
+ const clone = {
515
+ text : instance . text ,
516
+ id : instanceCounter ++ ,
517
+ hidden : true ,
518
+ context : instance . context ,
519
+ } ;
520
+ // Hide from unit tests
521
+ Object . defineProperty ( clone , 'id' , {
522
+ value : clone . id ,
523
+ enumerable : false ,
524
+ } ) ;
525
+ Object . defineProperty ( clone , 'context' , {
526
+ value : clone . context ,
527
+ enumerable : false ,
528
+ } ) ;
457
529
return clone ;
458
530
} ,
459
531
460
- createHiddenTextInstance (
532
+ cloneUnhiddenTextInstance (
533
+ instance : TextInstance ,
461
534
text : string ,
462
- rootContainerInstance : Container ,
463
- hostContext : Object ,
464
535
internalInstanceHandle : Object ,
465
536
) : TextInstance {
466
- const inst = { text : text , id : instanceCounter ++ , hidden : true } ;
537
+ const clone = {
538
+ text : instance . text ,
539
+ id : instanceCounter ++ ,
540
+ hidden : false ,
541
+ context : instance . context ,
542
+ } ;
467
543
// Hide from unit tests
468
- Object . defineProperty ( inst , 'id' , {
469
- value : inst . id ,
544
+ Object . defineProperty ( clone , 'id' , {
545
+ value : clone . id ,
546
+ enumerable : false ,
547
+ } ) ;
548
+ Object . defineProperty ( clone , 'context' , {
549
+ value : clone . context ,
470
550
enumerable : false ,
471
551
} ) ;
472
- return inst ;
552
+ return clone ;
473
553
} ,
474
554
} ;
475
555
0 commit comments