Skip to content

Commit

Permalink
Incapsulated the preattached components registration logic in a separ…
Browse files Browse the repository at this point in the history
…ate class
  • Loading branch information
Egor Tolstoy committed Nov 7, 2015
1 parent 0abfa13 commit a84c7b2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
21 changes: 4 additions & 17 deletions Source/Factory/Internal/TyphoonBlockComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "TyphoonTypeConverter.h"
#import "TyphoonInstancePostProcessor.h"
#import "TyphoonComponentFactory+TyphoonDefinitionRegisterer.h"
#import "TyphoonPreattachedComponentsRegisterer.h"

@interface TyphoonComponentFactory (Private)

Expand Down Expand Up @@ -62,7 +63,10 @@ - (id)initWithAssemblies:(NSArray *)assemblies
self = [super init];
if (self) {
[self attachDefinitionPostProcessor:[TyphoonAssemblyPropertyInjectionPostProcessor new]];
TyphoonPreattachedComponentsRegisterer *preattachedComponentsRegisterer = [[TyphoonPreattachedComponentsRegisterer alloc] initWithComponentFactory:self];

for (TyphoonAssembly *assembly in assemblies) {
[preattachedComponentsRegisterer doRegistrationForAssembly:assembly];
[self buildAssembly:assembly];
}
}
Expand All @@ -76,7 +80,6 @@ - (void)buildAssembly:(TyphoonAssembly*)assembly

[assembly prepareForUse];

[self registerAllPreattachedInfrastructureComponents:assembly];
[self registerAllDefinitions:assembly];
}

Expand All @@ -97,22 +100,6 @@ - (void)registerAllDefinitions:(TyphoonAssembly *)assembly
}
}

- (void)registerAllPreattachedInfrastructureComponents:(TyphoonAssembly *)assembly {
NSArray *infrastructureComponents = [assembly preattachedInfrastructureComponents];

for (id component in infrastructureComponents) {
if ([component conformsToProtocol:@protocol(TyphoonDefinitionPostProcessor)]) {
[self attachDefinitionPostProcessor:component];
}
else if ([component conformsToProtocol:@protocol(TyphoonInstancePostProcessor)]) {
[self attachInstancePostProcessor:component];
}
else if ([component conformsToProtocol:@protocol(TyphoonTypeConverter)]) {
[self attachTypeConverter:component];
}
}
}

//-------------------------------------------------------------------------------------------
#pragma mark - Overridden Methods
//-------------------------------------------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions Source/Factory/TyphoonPreattachedComponentsRegisterer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2015, Typhoon Framework Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

#import <Foundation/Foundation.h>

@class TyphoonComponentFactory;
@class TyphoonAssembly;

@interface TyphoonPreattachedComponentsRegisterer : NSObject

- (instancetype)initWithComponentFactory:(TyphoonComponentFactory *)componentFactory;

- (void)doRegistrationForAssembly:(TyphoonAssembly *)assembly;

@end
48 changes: 48 additions & 0 deletions Source/Factory/TyphoonPreattachedComponentsRegisterer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2015, Typhoon Framework Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

#import "TyphoonPreattachedComponentsRegisterer.h"
#import "TyphoonComponentFactory.h"
#import "TyphoonAssembly+TyphoonAssemblyFriend.h"

@interface TyphoonPreattachedComponentsRegisterer ()

@property (strong, nonatomic) TyphoonComponentFactory *factory;

@end

@implementation TyphoonPreattachedComponentsRegisterer

- (instancetype)initWithComponentFactory:(TyphoonComponentFactory *)componentFactory {
self = [super init];
if (self) {
_factory = componentFactory;
}
return self;
}

- (void)doRegistrationForAssembly:(TyphoonAssembly *)assembly {
NSArray *infrastructureComponents = [assembly preattachedInfrastructureComponents];

for (id component in infrastructureComponents) {
if ([component conformsToProtocol:@protocol(TyphoonDefinitionPostProcessor)]) {
[self.factory attachDefinitionPostProcessor:component];
}
else if ([component conformsToProtocol:@protocol(TyphoonInstancePostProcessor)]) {
[self.factory attachInstancePostProcessor:component];
}
else if ([component conformsToProtocol:@protocol(TyphoonTypeConverter)]) {
[self.factory attachTypeConverter:component];
}
}
}

@end
12 changes: 12 additions & 0 deletions Typhoon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@
9F0F25331BEA2845002AD880 /* TyphoonNSColorTypeConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F0F25241BEA2327002AD880 /* TyphoonNSColorTypeConverter.h */; };
9F0F25341BEA2859002AD880 /* TyphoonColorConversionUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F0F252E1BEA2571002AD880 /* TyphoonColorConversionUtils.h */; };
9F0F25351BEA37B0002AD880 /* TyphoonTypeConversionUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F0F25131BEA1267002AD880 /* TyphoonTypeConversionUtils.m */; };
9F1187A11BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F1187A01BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.m */; };
9F1187A21BEE2521008859E0 /* TyphoonPreattachedComponentsRegisterer.h in Headers */ = {isa = PBXBuildFile; fileRef = 9F11879F1BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.h */; };
9F1187A31BEE2536008859E0 /* TyphoonPreattachedComponentsRegisterer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F1187A01BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.m */; };
9F1187A41BEE253E008859E0 /* TyphoonPreattachedComponentsRegisterer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F1187A01BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.m */; };
9F2C08A81BA0C7AF0049D751 /* TyphoonCollaboratingAssembliesCollector.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F2C08A71BA0C7AF0049D751 /* TyphoonCollaboratingAssembliesCollector.m */; };
9F5E6FAC1BA15073000356A0 /* TyphoonCollaboratingAssembliesCollectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F5E6FAB1BA15073000356A0 /* TyphoonCollaboratingAssembliesCollectorTests.m */; };
9F65CEDA1BA153850015765B /* TyphoonCollaboratingAssembliesCollector.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F2C08A71BA0C7AF0049D751 /* TyphoonCollaboratingAssembliesCollector.m */; };
Expand Down Expand Up @@ -1104,6 +1108,8 @@
9F0F252A1BEA23E6002AD880 /* TyphoonNSColorTypeConverterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TyphoonNSColorTypeConverterTests.m; path = Tests/OSX/TypeConversion/TyphoonNSColorTypeConverterTests.m; sourceTree = SOURCE_ROOT; };
9F0F252E1BEA2571002AD880 /* TyphoonColorConversionUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TyphoonColorConversionUtils.h; path = Helpers/TyphoonColorConversionUtils.h; sourceTree = "<group>"; };
9F0F252F1BEA2571002AD880 /* TyphoonColorConversionUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TyphoonColorConversionUtils.m; path = Helpers/TyphoonColorConversionUtils.m; sourceTree = "<group>"; };
9F11879F1BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonPreattachedComponentsRegisterer.h; sourceTree = "<group>"; };
9F1187A01BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonPreattachedComponentsRegisterer.m; sourceTree = "<group>"; };
9F2C08A61BA0C7AF0049D751 /* TyphoonCollaboratingAssembliesCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TyphoonCollaboratingAssembliesCollector.h; sourceTree = "<group>"; };
9F2C08A71BA0C7AF0049D751 /* TyphoonCollaboratingAssembliesCollector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonCollaboratingAssembliesCollector.m; sourceTree = "<group>"; };
9F5E6FAB1BA15073000356A0 /* TyphoonCollaboratingAssembliesCollectorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TyphoonCollaboratingAssembliesCollectorTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1547,6 +1553,8 @@
6B076F491936F63A0083714E /* TyphoonComponentFactory.m */,
6B076F4A1936F63A0083714E /* TyphoonDefinitionRegisterer.h */,
6B076F4B1936F63A0083714E /* TyphoonDefinitionRegisterer.m */,
9F11879F1BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.h */,
9F1187A01BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.m */,
);
path = Factory;
sourceTree = "<group>";
Expand Down Expand Up @@ -2562,6 +2570,7 @@
BA79830373597A7AA358C2D8 /* TyphoonCollaboratingAssemblyProxy.h in Headers */,
9F0591E11BE88408007CCB9C /* TyphoonStoryboardProvider.h in Headers */,
9F0591E01BE88404007CCB9C /* TyphoonViewHelpers.h in Headers */,
9F1187A21BEE2521008859E0 /* TyphoonPreattachedComponentsRegisterer.h in Headers */,
BA798EB0684A45DDBA818962 /* TyphoonBlockComponentFactory.h in Headers */,
BA79808B1AE811F764E7B14F /* TyphoonCircularDependencyTerminator.h in Headers */,
BA798A97C60EC12681B6AAF4 /* TyphoonAssemblyDefinitionBuilder.h in Headers */,
Expand Down Expand Up @@ -2908,6 +2917,7 @@
6B0770A41936F9000083714E /* TyphoonInjectionByCollection.m in Sources */,
6B0770A51936F9000083714E /* TyphoonInjectionByComponentFactory.m in Sources */,
9FDF58CE1BA4162100678B2B /* TyphoonStoryboardProvider.m in Sources */,
9F1187A11BEE22F2008859E0 /* TyphoonPreattachedComponentsRegisterer.m in Sources */,
6B0770A61936F9000083714E /* TyphoonInjectionByConfig.m in Sources */,
6B0770A71936F9000083714E /* TyphoonInjectionByDictionary.m in Sources */,
6B0770A81936F9000083714E /* TyphoonInjectionByFactoryReference.m in Sources */,
Expand Down Expand Up @@ -3142,6 +3152,7 @@
6B0773B51937831B0083714E /* TyphoonAssembly.m in Sources */,
6B0773BF1937831B0083714E /* NSInvocation+TCFInstanceBuilder.m in Sources */,
6B0773C01937831B0083714E /* NSInvocation+TCFUnwrapValues.m in Sources */,
9F1187A31BEE2536008859E0 /* TyphoonPreattachedComponentsRegisterer.m in Sources */,
6B0773C11937831B0083714E /* NSMethodSignature+TCFUnwrapValues.m in Sources */,
6B0773C21937831B0083714E /* NSValue+TCFUnwrapValues.m in Sources */,
6B0773C31937831B0083714E /* TyphoonCallStack.m in Sources */,
Expand Down Expand Up @@ -3318,6 +3329,7 @@
90ABC4051A36B1B4008D8162 /* TyphoonOptionMatcher.m in Sources */,
90ABC4061A36B1B4008D8162 /* TyphoonDefinition+Option.m in Sources */,
90ABC4071A36B1B4008D8162 /* TyphoonConfigPostProcessor.m in Sources */,
9F1187A41BEE253E008859E0 /* TyphoonPreattachedComponentsRegisterer.m in Sources */,
90ABC4081A36B1B4008D8162 /* TyphoonJsonStyleConfiguration.m in Sources */,
90ABC4091A36B1B4008D8162 /* TyphoonPlistStyleConfiguration.m in Sources */,
90ABC40A1A36B1B4008D8162 /* TyphoonPropertyStyleConfiguration.m in Sources */,
Expand Down

0 comments on commit a84c7b2

Please sign in to comment.