@@ -40,16 +40,31 @@ export function withRegistry(...registries: Registry[]) {
40
40
} ;
41
41
}
42
42
43
+ export interface IComponentRegistryConsumer {
44
+ id : string ;
45
+ children : ( registry : any ) => React . ReactNode ;
46
+ }
47
+
48
+ export const ComponentRegistryConsumer : React . SFC < IComponentRegistryConsumer > = props => (
49
+ < RegistryConsumer >
50
+ { registries => props . children ( registries [ props . id ] . snapshot ( ) ) }
51
+ </ RegistryConsumer >
52
+ ) ;
53
+
43
54
export interface IRegistryOptions {
44
55
id : string ;
45
56
inverted ?: boolean ;
46
57
}
47
58
59
+ interface IRegistryComponents {
60
+ [ key : string ] : any ;
61
+ }
62
+
48
63
export class Registry {
49
64
id : string ;
50
65
inverted : boolean ;
51
66
52
- private components = new Map < string , any > ( ) ;
67
+ private components : IRegistryComponents = { } ;
53
68
54
69
constructor ( { id, inverted = false } : IRegistryOptions ) {
55
70
this . id = id ;
@@ -63,7 +78,7 @@ export class Registry {
63
78
* @param component valid react component
64
79
*/
65
80
set < T > ( id : string , component : ComponentType < T > ) {
66
- this . components . set ( id , component ) ;
81
+ this . components [ id ] = component ;
67
82
68
83
return this ;
69
84
}
@@ -75,11 +90,15 @@ export class Registry {
75
90
*/
76
91
get < T > ( id : string ) : ComponentType < T > {
77
92
if ( __DEV__ ) {
78
- if ( ! this . components . has ( id ) ) {
93
+ if ( ! this . components [ id ] ) {
79
94
throw new Error ( `Component with id '${ id } ' not found.` ) ;
80
95
}
81
96
}
82
97
83
- return this . components . get ( id ) ;
98
+ return this . components [ id ] ;
99
+ }
100
+
101
+ snapshot < RT > ( ) : RT {
102
+ return this . components as any ;
84
103
}
85
104
}
0 commit comments