File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,24 @@ registry.set('Header', Header)
4848registry .set (' Footer' , Footer )
4949```
5050
51+ or
52+
53+ ``` ts
54+ registry .fill ({
55+ Header ,
56+ Footer ,
57+ })
58+ ```
59+
60+ or
61+
62+ ``` ts
63+ registry .fill ({
64+ ' id-1' : Header ,
65+ ' id-2' : Footer ,
66+ })
67+ ```
68+
51693 . Export the App version with its registry of components:
5270
5371``` ts
Original file line number Diff line number Diff line change @@ -103,6 +103,20 @@ export class Registry {
103103 return this
104104 }
105105
106+ /**
107+ * Set react components in registry via object literal.
108+ *
109+ * @param componentsSet set of valid react components
110+ */
111+ fill ( componentsSet : IRegistryComponents ) {
112+ this . components = {
113+ ...this . components ,
114+ ...componentsSet ,
115+ }
116+
117+ return this
118+ }
119+
106120 /**
107121 * Get react component from registry by id.
108122 *
Original file line number Diff line number Diff line change @@ -31,6 +31,23 @@ describe('@bem-react/di', () => {
3131 expect ( registry . get ( 'id-2' ) ) . to . eq ( Component2 )
3232 } )
3333
34+ it ( 'should fill components via object literal' , ( ) => {
35+ const registry = new Registry ( { id : 'registry' } )
36+ const Component1 = ( ) => null
37+ const Component2 = ( ) => < span />
38+
39+ registry . fill ( {
40+ Component1,
41+ Component2,
42+ } )
43+
44+ const snapshot : any = { }
45+ snapshot [ 'Component1' ] = Component1
46+ snapshot [ 'Component2' ] = Component2
47+
48+ expect ( registry . snapshot ( ) ) . to . eql ( snapshot )
49+ } )
50+
3451 it ( 'should return list of components' , ( ) => {
3552 const registry = new Registry ( { id : 'registry' } )
3653 const Component1 = ( ) => null
You can’t perform that action at this time.
0 commit comments