@@ -5,7 +5,7 @@ import * as ReactDOM from 'react-dom';
55
66import removeUndefinedProperties from '../utils/object/remove-undefined-properties' ;
77import { CHILDREN_TO_APPEND_PROP } from './react-content' ;
8- import { getComponentClass } from " ./registry" ;
8+ import { getComponentClass } from ' ./registry' ;
99
1010const DEBUG = false ;
1111
@@ -37,6 +37,10 @@ export class ReactNode {
3737 this . setRenderPending ( ) ;
3838 }
3939
40+ get parent ( ) : HTMLElement | ReactNode {
41+ return this . _parent ;
42+ }
43+
4044 private isNotRenderable : boolean ;
4145 get shouldRender ( ) {
4246 return ! this . isNotRenderable ;
@@ -80,13 +84,15 @@ export class ReactNode {
8084 // If type is still a string, then no React Element matches this string.
8185 this . typeIsReactElementClass = typeof this . type !== 'string' ;
8286
83- if ( DEBUG ) { console . log ( 'ReactNode > tryResolveTypeIsReactElementClass > type:' , this . typeName ) ; }
87+ if ( DEBUG ) {
88+ console . log ( 'ReactNode > tryResolveTypeIsReactElementClass > type:' , this . typeName ) ;
89+ }
8490 }
8591 }
8692
8793 setAttribute ( name : string , value : any ) {
8894 this . setAttributes ( {
89- [ name ] : value
95+ [ name ] : value ,
9096 } ) ;
9197 }
9298
@@ -96,7 +102,7 @@ export class ReactNode {
96102
97103 setProperty ( name : string , value : any ) {
98104 this . setProperties ( {
99- [ name ] : value
105+ [ name ] : value ,
100106 } ) ;
101107 }
102108
@@ -156,16 +162,20 @@ export class ReactNode {
156162 // parent.
157163 if ( ! isReactNode ( this . _parent ) ) {
158164 if ( this . isDestroyPending && this . _parent ) {
159- if ( DEBUG ) { console . log ( 'ReactNode > render > destroy > node:' , this . toString ( ) , 'parent:' , this . parent ) ; }
165+ if ( DEBUG ) {
166+ console . log ( 'ReactNode > render > destroy > node:' , this . toString ( ) , 'parent:' , this . parent ) ;
167+ }
160168 ReactDOM . unmountComponentAtNode ( this . _parent ) ;
161169 return this ;
162170 }
163171
164172 if ( this . isRenderPending ) {
165- if ( DEBUG ) { console . log ( 'ReactNode > render > node:' , this . toString ( ) , 'parent:' , this . parent ) ; }
173+ if ( DEBUG ) {
174+ console . log ( 'ReactNode > render > node:' , this . toString ( ) , 'parent:' , this . parent ) ;
175+ }
166176 // It is expected that the element will be recreated and re-rendered with each attribute change.
167177 // See: https://reactjs.org/docs/rendering-elements.html
168- ReactDOM . render ( this . renderRecursive ( ) as any , this . _parent ) ;
178+ ReactDOM . render ( this . renderRecursive ( ) as React . ReactElement < { } > , this . _parent ) ;
169179 this . isRenderPending = false ;
170180 }
171181 }
@@ -174,10 +184,7 @@ export class ReactNode {
174184 }
175185
176186 private renderRecursive ( key ?: string ) : React . ReactElement < { } > | string {
177- const children =
178- this . children
179- ? this . children . map ( ( child , index ) => child . renderRecursive ( index . toString ( ) ) )
180- : [ ] ;
187+ const children = this . children ? this . children . map ( ( child , index ) => child . renderRecursive ( index . toString ( ) ) ) : [ ] ;
181188
182189 if ( this . text ) {
183190 return this . text ;
@@ -187,11 +194,11 @@ export class ReactNode {
187194
188195 if ( key ) this . props [ 'key' ] = key ;
189196
190- const clearedProps = this . transformProps (
191- removeUndefinedProperties ( this . props )
192- ) ;
197+ const clearedProps = this . transformProps ( removeUndefinedProperties ( this . props ) ) ;
193198
194- if ( DEBUG ) { console . warn ( 'ReactNode > renderRecursive > type:' , this . toString ( ) , 'props:' , this . props , 'children:' , children ) ; }
199+ if ( DEBUG ) {
200+ console . warn ( 'ReactNode > renderRecursive > type:' , this . toString ( ) , 'props:' , this . props , 'children:' , children ) ;
201+ }
195202 return React . createElement ( this . type , clearedProps , children . length > 0 ? children : undefined ) ;
196203 }
197204
@@ -220,7 +227,14 @@ export class ReactNode {
220227
221228 // This is called by Angular core when projected content is being added.
222229 appendChild ( projectedContent : HTMLElement ) {
223- if ( DEBUG ) { console . error ( 'ReactNode > appendChild > node:' , this . toString ( ) , 'projectedContent:' , projectedContent . toString ( ) . trim ( ) ) ; }
230+ if ( DEBUG ) {
231+ console . error (
232+ 'ReactNode > appendChild > node:' ,
233+ this . toString ( ) ,
234+ 'projectedContent:' ,
235+ projectedContent . toString ( ) . trim ( )
236+ ) ;
237+ }
224238 this . childrenToAppend . push ( projectedContent ) ;
225239 }
226240
@@ -239,5 +253,4 @@ export class ReactNode {
239253
240254 return '[undefined ReactNode]' ;
241255 }
242-
243256}
0 commit comments