Skip to content

Commit

Permalink
Merge pull request #110 from ZoMinster/server_opt
Browse files Browse the repository at this point in the history
Server opt,ok
  • Loading branch information
SoXeon committed Feb 4, 2018
2 parents ff7aef5 + 23981f4 commit 0ec908a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion BeeHive/BHModuleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ - (void)handleModulesInitEventForTarget:(id<BHModuleProtocol>)target

[moduleInstances enumerateObjectsUsingBlock:^(id<BHModuleProtocol> moduleInstance, NSUInteger idx, BOOL * _Nonnull stop) {
__weak typeof(&*self) wself = self;
void ( ^ bk )();
void ( ^ bk )(void);
bk = ^(){
__strong typeof(&*self) sself = wself;
if (sself) {
Expand Down
6 changes: 3 additions & 3 deletions BeeHive/BHRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ + (BOOL)canOpenURL:(NSURL *)URL
!selector ||
![mClass conformsToProtocol:@protocol(BHServiceProtocol)] ||
![mClass conformsToProtocol:protocol] ||
![mClass respondsToSelector:selector]) {
![mClass instancesRespondToSelector:selector]) {
flag = NO;
*stop = NO;
return;
}
} break;
case BHRUsageJumpViewControler: {
if (![mClass isKindOfClass:[UIViewController class]]) {
if (![mClass isSubclassOfClass:[UIViewController class]]) {
flag = NO;
*stop = NO;
return;
Expand Down Expand Up @@ -591,7 +591,7 @@ + (id)safePerformAction:(SEL)action
forTarget:(NSObject *)target
withParams:(NSDictionary *)params
{
NSMethodSignature * sig = [self methodSignatureForSelector:action];
NSMethodSignature * sig = [target methodSignatureForSelector:action];
if (!sig) { return nil; }
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
if (!inv) { return nil; }
Expand Down
5 changes: 5 additions & 0 deletions BeeHive/BHServiceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
- (void)registerService:(Protocol *)service implClass:(Class)implClass;

- (id)createService:(Protocol *)service;
- (id)createService:(Protocol *)service withServiceName:(NSString *)serviceName;
- (id)createService:(Protocol *)service withServiceName:(NSString *)serviceName shouldCache:(BOOL)shouldCache;

- (id)getServiceInstanceFromServiceName:(NSString *)serviceName;
- (void)removeServiceWithServiceName:(NSString *)serviceName;

@end
42 changes: 34 additions & 8 deletions BeeHive/BHServiceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ - (void)registerService:(Protocol *)service implClass:(Class)implClass

- (id)createService:(Protocol *)service
{
return [self createService:service withServiceName:nil];
}

- (id)createService:(Protocol *)service withServiceName:(NSString *)serviceName {
return [self createService:service withServiceName:serviceName shouldCache:YES];
}

- (id)createService:(Protocol *)service withServiceName:(NSString *)serviceName shouldCache:(BOOL)shouldCache {
if (!serviceName.length) {
serviceName = NSStringFromProtocol(service);
}
id implInstance = nil;

if (![self checkValidService:service]) {
Expand All @@ -95,10 +106,12 @@ - (id)createService:(Protocol *)service

}

NSString *serviceStr = NSStringFromProtocol(service);
id protocolImpl = [[BHContext shareInstance] getServiceInstanceFromServiceName:serviceStr];
if (protocolImpl) {
return protocolImpl;
NSString *serviceStr = serviceName;
if (shouldCache) {
id protocolImpl = [[BHContext shareInstance] getServiceInstanceFromServiceName:serviceStr];
if (protocolImpl) {
return protocolImpl;
}
}

Class implClass = [self serviceImplClass:service];
Expand All @@ -108,15 +121,28 @@ - (id)createService:(Protocol *)service
implInstance = [[implClass class] shareInstance];
else
implInstance = [[implClass alloc] init];

[[BHContext shareInstance] addServiceWithImplInstance:implInstance serviceName:serviceStr];
return implInstance;
if (shouldCache) {
[[BHContext shareInstance] addServiceWithImplInstance:implInstance serviceName:serviceStr];
return implInstance;
} else {
return implInstance;
}
}
}

return [[implClass alloc] init];
}

- (id)getServiceInstanceFromServiceName:(NSString *)serviceName
{
return [[BHContext shareInstance] getServiceInstanceFromServiceName:serviceName];
}

- (void)removeServiceWithServiceName:(NSString *)serviceName
{
[[BHContext shareInstance] removeServiceWithServiceName:serviceName];
}


#pragma mark - private
- (Class)serviceImplClass:(Protocol *)service
{
Expand Down

0 comments on commit 0ec908a

Please sign in to comment.