@@ -14,18 +14,20 @@ @interface WXComponentConfig : NSObject
14
14
15
15
@property (nonatomic , strong ) NSString *name;
16
16
@property (nonatomic , strong ) NSString *clazz;
17
+ @property (nonatomic , strong ) NSDictionary *properties;
17
18
18
- - (instancetype )initWithName : (NSString *)name class : (NSString *)clazz ;
19
+ - (instancetype )initWithName : (NSString *)name class : (NSString *)clazz pros : ( NSDictionary *) pros ;
19
20
20
21
@end
21
22
22
23
@implementation WXComponentConfig
23
24
24
- - (instancetype )initWithName : (NSString *)name class : (NSString *)clazz
25
+ - (instancetype )initWithName : (NSString *)name class : (NSString *)clazz pros : ( NSDictionary *) pros
25
26
{
26
27
if (self = [super init ]) {
27
28
_name = name;
28
29
_clazz = clazz;
30
+ _properties = pros;
29
31
}
30
32
31
33
return self;
@@ -66,9 +68,9 @@ + (Class)classWithComponentName:(NSString *)name
66
68
return [[self sharedInstance ] classWithComponentName: name];
67
69
}
68
70
69
- + (void )registerComponent : (NSString *)name withClass : (Class )clazz
71
+ + (void )registerComponent : (NSString *)name withClass : (Class )clazz withPros : ( NSDictionary *) pros
70
72
{
71
- [[self sharedInstance ] registerComponent: name withClass: clazz];
73
+ [[self sharedInstance ] registerComponent: name withClass: clazz withPros: pros ];
72
74
}
73
75
74
76
+ (void )registerComponents : (NSArray *)components
@@ -81,8 +83,28 @@ + (void)unregisterAllComponents
81
83
[[self sharedInstance ] unregisterAllComponents ];
82
84
}
83
85
86
+ + (NSDictionary *)componentConfigs {
87
+ return [[self sharedInstance ] getComponentConfigs ];
88
+ }
89
+
84
90
#pragma mark Private
85
91
92
+ - (NSDictionary *)getComponentConfigs {
93
+ NSMutableDictionary *componentDic = [[NSMutableDictionary alloc ] init ];
94
+ void (^componentBlock)(id , id , BOOL *) = ^(id mKey, id mObj, BOOL * mStop) {
95
+ WXComponentConfig *componentConfig = (WXComponentConfig *)mObj;
96
+ NSMutableDictionary *configDic = [[NSMutableDictionary alloc ] init ];
97
+ [configDic setObject: componentConfig.name forKey: @" name" ];
98
+ [configDic setObject: componentConfig.clazz forKey: @" clazz" ];
99
+ if (componentConfig.properties ) {
100
+ [configDic setObject: componentConfig.properties forKey: @" pros" ];
101
+ }
102
+ [componentDic setObject: configDic forKey: componentConfig.name];
103
+ };
104
+ [_componentConfigs enumerateKeysAndObjectsUsingBlock: componentBlock];
105
+ return componentDic;
106
+ }
107
+
86
108
- (Class )classWithComponentName : (NSString *)name
87
109
{
88
110
WXAssert (name, @" Can not find class for a nil component name" );
@@ -104,7 +126,7 @@ - (Class)classWithComponentName:(NSString *)name
104
126
return NSClassFromString (config.clazz );
105
127
}
106
128
107
- - (void )registerComponent : (NSString *)name withClass : (Class )clazz
129
+ - (void )registerComponent : (NSString *)name withClass : (Class )clazz withPros : ( NSDictionary *) pros
108
130
{
109
131
WXAssert (name && clazz, @" name or clazz must not be nil for registering component." );
110
132
@@ -117,7 +139,7 @@ - (void)registerComponent:(NSString *)name withClass:(Class)clazz
117
139
config.name , config.class , name, clazz);
118
140
}
119
141
120
- config = [[WXComponentConfig alloc ] initWithName: name class: NSStringFromClass (clazz)];
142
+ config = [[WXComponentConfig alloc ] initWithName: name class: NSStringFromClass (clazz) pros: pros ];
121
143
[_componentConfigs setValue: config forKey: name];
122
144
[_configLock unlock ];
123
145
}
@@ -133,7 +155,7 @@ - (void)registerComponents:(NSArray *)components
133
155
NSString *clazz = dict[@" class" ];
134
156
WXAssert (name && clazz, @" name or clazz must not be nil for registering components." );
135
157
136
- WXComponentConfig *config = [[WXComponentConfig alloc ] initWithName: name class: clazz];
158
+ WXComponentConfig *config = [[WXComponentConfig alloc ] initWithName: name class: clazz pros: nil ];
137
159
if (config){
138
160
[_componentConfigs setValue: config forKey: name];
139
161
}
0 commit comments