11import { DOM , createElement } from 'react' ;
22
3- export default class ReactJsonSchema {
3+ const _componentMap = new WeakMap ( ) ;
44
5- constructor ( ) {
6- this . _componentMap = null ;
7- }
5+ export default class ReactJsonSchema {
86
97 parseSchema ( schema ) {
108 let element = null ;
@@ -29,20 +27,20 @@ export default class ReactJsonSchema {
2927 }
3028
3129 createComponent ( schema ) {
32- const { component, children, text, ...rest } = schema ;
30+ const { component, children, text, ...rest } = schema ;
3331 const Component = this . resolveComponent ( schema ) ;
3432 const Children = typeof text !== 'undefined' ? text : this . resolveComponentChildren ( schema ) ;
3533 return createElement ( Component , rest , Children ) ;
3634 }
3735
3836 resolveComponent ( schema ) {
39- const _componentMap = this . _componentMap ;
37+ const componentMap = this . getComponentMap ( ) ;
4038 let Component = null ;
4139 if ( schema . hasOwnProperty ( 'component' ) ) {
4240 if ( schema . component === Object ( schema . component ) ) {
4341 Component = schema . component ;
44- } else if ( _componentMap && _componentMap [ schema . component ] ) {
45- Component = _componentMap [ schema . component ] ;
42+ } else if ( componentMap && componentMap [ schema . component ] ) {
43+ Component = componentMap [ schema . component ] ;
4644 } else if ( DOM . hasOwnProperty ( schema . component ) ) {
4745 Component = schema . component ;
4846 }
@@ -58,10 +56,10 @@ export default class ReactJsonSchema {
5856 }
5957
6058 getComponentMap ( ) {
61- return this . _componentMap ;
59+ return _componentMap . get ( this ) ;
6260 }
6361
6462 setComponentMap ( componentMap ) {
65- this . _componentMap = componentMap ;
63+ _componentMap . set ( this , componentMap ) ;
6664 }
6765}
0 commit comments