Skip to content

Commit

Permalink
update moduleManager get context way
Browse files Browse the repository at this point in the history
  • Loading branch information
SoXeon committed Feb 9, 2017
1 parent 36ee6db commit 4e9cd7b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 68 deletions.
3 changes: 1 addition & 2 deletions BeeHive/BHContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ typedef enum
//user Activity Model
@property (nonatomic, strong) BHUserActivityItem *userActivityItem;

+(instancetype) shareInstance;

+ (instancetype)shareInstance;

@end
36 changes: 15 additions & 21 deletions BeeHive/BHContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@
#import "BHContext.h"


@interface BHContext()

@implementation BHContext

+ (instancetype)shareInstance
{
static dispatch_once_t p;
static id BHInstance = nil;

dispatch_once(&p, ^{
BHInstance = [[[self class] alloc] init];
if ([BHInstance isKindOfClass:[BHContext class]]) {
((BHContext *) BHInstance).config = [BHConfig shareInstance];
}
});

return BHInstance;
}

@end

@implementation BHContext

-(instancetype)init
{
Expand All @@ -38,20 +48,4 @@ -(instancetype)init
return self;
}

+(instancetype) shareInstance
{
static dispatch_once_t p;
static id BHInstance = nil;

dispatch_once(&p, ^{
BHInstance = [[[self class] alloc] init];
if ([BHInstance isKindOfClass:[BHContext class]]) {
((BHContext *) BHInstance).config = [BHConfig shareInstance];
}
});

return BHInstance;
}


@end
7 changes: 0 additions & 7 deletions BeeHive/BHModuleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#import <Foundation/Foundation.h>

@class BHContext;

typedef NS_ENUM(NSUInteger, BHModuleLevel)
{
BHModuleBasic = 0,
Expand Down Expand Up @@ -48,11 +46,6 @@ typedef NS_ENUM(NSInteger, BHModuleEventType)

@interface BHModuleManager : NSObject

@property (nonatomic, strong) NSString *modulesConfigFilename;

@property (nonatomic, strong) BHContext *wholeContext;


+ (instancetype)sharedManager;

// If you do not comply with set Level protocol, the default Normal
Expand Down
22 changes: 5 additions & 17 deletions BeeHive/BHModuleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ @interface BHModuleManager()

@property(nonatomic, strong) NSMutableArray *BHModules;


@end

@implementation BHModuleManager
Expand All @@ -59,15 +58,15 @@ + (instancetype)sharedManager
static id sharedManager = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
sharedManager = [[self alloc] init];
sharedManager = [[BHModuleManager alloc] init];
});
return sharedManager;
}

- (void)loadLocalModules
{

NSString *plistPath = [[NSBundle mainBundle] pathForResource:self.modulesConfigFilename ofType:@"plist"];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:[BHContext shareInstance].moduleConfigName ofType:@"plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
return;
}
Expand Down Expand Up @@ -285,17 +284,6 @@ - (void)addModuleFromObject:(id)object

#pragma mark - property setter or getter

- (void)setModulesConfigFilename:(NSString *)modulesConfigFilename
{
_modulesConfigFilename = modulesConfigFilename;
}

- (void)setWholeContext:(BHContext *)wholeContext
{
_wholeContext = wholeContext;
self.modulesConfigFilename = _wholeContext.moduleConfigName;
}

- (NSMutableArray *)BHModules
{
if (!_BHModules) {
Expand All @@ -316,7 +304,7 @@ - (void)handleModulesInitEvent
__strong typeof(&*self) sself = wself;
if (sself) {
if ([moduleInstance respondsToSelector:@selector(modInit:)]) {
[moduleInstance modInit:sself.wholeContext];
[moduleInstance modInit:[BHContext shareInstance]];
}
}
};
Expand Down Expand Up @@ -346,7 +334,7 @@ - (void)handleModulesTearDownEvent
for (int i = (int)self.BHModules.count - 1; i >= 0; i--) {
id<BHModuleProtocol> moduleInstance = [self.BHModules objectAtIndex:i];
if (moduleInstance && [moduleInstance respondsToSelector:@selector(modTearDown:)]) {
[moduleInstance modTearDown:self.wholeContext];
[moduleInstance modTearDown:[BHContext shareInstance]];
}
}
}
Expand All @@ -358,7 +346,7 @@ - (void)handleModuleEvent:(NSString *)selectorStr
if ([moduleInstance respondsToSelector:seletor]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[moduleInstance performSelector:seletor withObject:self.wholeContext];
[moduleInstance performSelector:seletor withObject:[BHContext shareInstance]];
#pragma clang diagnostic pop

[[BHTimeProfiler sharedTimeProfiler] recordEventTime:[NSString stringWithFormat:@"%@ --- %@", [moduleInstance class], NSStringFromSelector(seletor)]];
Expand Down
19 changes: 7 additions & 12 deletions BeeHive/BeeHive.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

#import "BeeHive.h"


//BootLoader

@interface BeeHive()

@end


@implementation BeeHive

#pragma mark - public
Expand Down Expand Up @@ -63,7 +55,6 @@ -(void)setContext:(BHContext *)context

- (void)loadStaticModules
{
[[BHModuleManager sharedManager] setWholeContext:self.context];

[[BHModuleManager sharedManager] loadLocalModules];

Expand All @@ -84,9 +75,13 @@ -(void)loadStaticServices
[[BHServiceManager sharedManager] registerAnnotationServices];

}
- (void)tiggerCustomEvent:(NSInteger)eventType{
if(eventType<1000)
return;

- (void)tiggerCustomEvent:(NSInteger)eventType
{
if(eventType < 1000) {
return;
}

[[BHModuleManager sharedManager] triggerEvent:eventType];
}

Expand Down
22 changes: 13 additions & 9 deletions Example/BeeHive/Launch Screen.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10089" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2657" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10072.1"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -15,23 +19,23 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright © 2016年 一渡. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text=" Copyright © 2017年 Alibaba. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="20" y="559" width="560" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="BeeHive" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="BeeHive" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<rect key="frame" x="20" y="180" width="560" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
<constraint firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
Expand Down

0 comments on commit 4e9cd7b

Please sign in to comment.