Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Merge 6b510d8 into f8fd844
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelikespie committed Jul 20, 2016
2 parents f8fd844 + 6b510d8 commit 5fa86c3
Show file tree
Hide file tree
Showing 31 changed files with 749 additions and 314 deletions.
44 changes: 31 additions & 13 deletions Cleanse.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
F61191361CD30B3300686C0C /* ErrorTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F61191351CD30B3300686C0C /* ErrorTest.swift */; };
F61191381CD329F500686C0C /* Tags.swift in Sources */ = {isa = PBXBuildFile; fileRef = F61191371CD329F500686C0C /* Tags.swift */; };
F611913A1CD3331400686C0C /* Module.swift in Sources */ = {isa = PBXBuildFile; fileRef = F61191391CD3331400686C0C /* Module.swift */; };
F611913C1CD34F1E00686C0C /* StressTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F611913B1CD34F1E00686C0C /* StressTests.swift */; };
F61B15121CD1596400A42C01 /* LegacyObjectGraph.swift in Sources */ = {isa = PBXBuildFile; fileRef = F61B15111CD1596400A42C01 /* LegacyObjectGraph.swift */; };
F61B15141CD15E6F00A42C01 /* LegacyKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = F61B15131CD15E6F00A42C01 /* LegacyKey.swift */; };
F624D2941D40172A00C36F98 /* WeakProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F624D2931D40172A00C36F98 /* WeakProvider.swift */; };
F624D2961D4023D900C36F98 /* CycleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F624D2951D4023D900C36F98 /* CycleTests.swift */; };
F62C69F51CD8481200137422 /* ComponentVisitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F62C69F41CD8481200137422 /* ComponentVisitor.swift */; };
F62C69F91CD86B9500137422 /* Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F62C69F81CD86B9500137422 /* Provider.swift */; };
F62C69FD1CD8927400137422 /* CanonicalRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F62C69FC1CD8927400137422 /* CanonicalRepresentable.swift */; };
Expand All @@ -40,7 +41,6 @@
F6760C5C1D2DF67F009C6F8A /* Finalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6760C5B1D2DF67F009C6F8A /* Finalizable.swift */; };
F6760C5E1D2DF698009C6F8A /* ScopedProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6760C5D1D2DF698009C6F8A /* ScopedProvider.swift */; };
F6760C601D2DF9BA009C6F8A /* Scoped.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6760C5F1D2DF9BA009C6F8A /* Scoped.swift */; };
F6760C621D2DFA1E009C6F8A /* ScopedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6760C611D2DFA1E009C6F8A /* ScopedTests.swift */; };
F6760C641D2E0B6A009C6F8A /* ComponentFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6760C631D2E0B6A009C6F8A /* ComponentFactory.swift */; };
F69A20621CD1941D00B954F8 /* CombinedHashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F69A205F1CD1941D00B954F8 /* CombinedHashable.swift */; };
F69D1A971CDDAFF7009132B4 /* CollectionBindingBuilderDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F69D1A961CDDAFF7009132B4 /* CollectionBindingBuilderDecorator.swift */; };
Expand All @@ -65,6 +65,7 @@
F6B387921CE18CB1001CBC4F /* BindingBuilderDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6B387911CE18CB1001CBC4F /* BindingBuilderDecorator.swift */; };
F6B387951CE18E53001CBC4F /* SingularCollectionBindingBuilderDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6B387941CE18E53001CBC4F /* SingularCollectionBindingBuilderDecorator.swift */; };
F6B3879B1CE1A03C001CBC4F /* SubcomponentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F62C69EE1CD7F42B00137422 /* SubcomponentTests.swift */; };
F6D589EF1D3ED57900B99F7D /* SatisfiedDependenciesValidationVisitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6D589EE1D3ED57900B99F7D /* SatisfiedDependenciesValidationVisitor.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -89,9 +90,10 @@
F61191351CD30B3300686C0C /* ErrorTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTest.swift; sourceTree = "<group>"; };
F61191371CD329F500686C0C /* Tags.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tags.swift; sourceTree = "<group>"; };
F61191391CD3331400686C0C /* Module.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Module.swift; sourceTree = "<group>"; };
F611913B1CD34F1E00686C0C /* StressTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StressTests.swift; sourceTree = "<group>"; };
F61B15111CD1596400A42C01 /* LegacyObjectGraph.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LegacyObjectGraph.swift; sourceTree = "<group>"; };
F61B15131CD15E6F00A42C01 /* LegacyKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LegacyKey.swift; sourceTree = "<group>"; };
F624D2931D40172A00C36F98 /* WeakProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakProvider.swift; sourceTree = "<group>"; };
F624D2951D4023D900C36F98 /* CycleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CycleTests.swift; sourceTree = "<group>"; };
F62C69EE1CD7F42B00137422 /* SubcomponentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubcomponentTests.swift; sourceTree = "<group>"; };
F62C69F41CD8481200137422 /* ComponentVisitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComponentVisitor.swift; sourceTree = "<group>"; };
F62C69F81CD86B9500137422 /* Provider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Provider.swift; sourceTree = "<group>"; };
Expand All @@ -113,7 +115,6 @@
F6760C5B1D2DF67F009C6F8A /* Finalizable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Finalizable.swift; sourceTree = "<group>"; };
F6760C5D1D2DF698009C6F8A /* ScopedProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScopedProvider.swift; sourceTree = "<group>"; };
F6760C5F1D2DF9BA009C6F8A /* Scoped.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Scoped.swift; sourceTree = "<group>"; };
F6760C611D2DFA1E009C6F8A /* ScopedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScopedTests.swift; sourceTree = "<group>"; };
F6760C631D2E0B6A009C6F8A /* ComponentFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComponentFactory.swift; sourceTree = "<group>"; };
F69A205F1CD1941D00B954F8 /* CombinedHashable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CombinedHashable.swift; sourceTree = "<group>"; };
F69D1A961CDDAFF7009132B4 /* CollectionBindingBuilderDecorator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionBindingBuilderDecorator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -141,6 +142,7 @@
F6B3878F1CE18BB2001CBC4F /* BaseBindingBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseBindingBuilder.swift; sourceTree = "<group>"; };
F6B387911CE18CB1001CBC4F /* BindingBuilderDecorator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BindingBuilderDecorator.swift; sourceTree = "<group>"; };
F6B387941CE18E53001CBC4F /* SingularCollectionBindingBuilderDecorator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingularCollectionBindingBuilderDecorator.swift; sourceTree = "<group>"; };
F6D589EE1D3ED57900B99F7D /* SatisfiedDependenciesValidationVisitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SatisfiedDependenciesValidationVisitor.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -182,6 +184,7 @@
F61191391CD3331400686C0C /* Module.swift */,
F6760C581D2DEFFC009C6F8A /* Configurable.swift */,
F6760C651D2E0B6D009C6F8A /* ComponentBase */,
F6D589ED1D3ED55100B99F7D /* Validations */,
F6AB45161CD9E8B40021AF36 /* Components */,
F6760C531D2DED20009C6F8A /* Subcomponents */,
F6760C5A1D2DF577009C6F8A /* Scopes */,
Expand Down Expand Up @@ -237,6 +240,7 @@
children = (
F62C69F81CD86B9500137422 /* Provider.swift */,
F62C69FE1CD897D200137422 /* TaggedProvider.swift */,
F624D2931D40172A00C36F98 /* WeakProvider.swift */,
);
name = Providers;
sourceTree = "<group>";
Expand Down Expand Up @@ -354,23 +358,22 @@
F6A660DB1CCB07C3004DD6E3 /* Info.plist */,
F6615D1C1CD00FC10079DE8D /* PropertyInjectionTests.swift */,
F61191351CD30B3300686C0C /* ErrorTest.swift */,
F611913B1CD34F1E00686C0C /* StressTests.swift */,
F61133C01CD7B36600069972 /* MemoryManagementTests.swift */,
F62C69EE1CD7F42B00137422 /* SubcomponentTests.swift */,
F6AB45141CD9D1F90021AF36 /* NoopVisitor.swift */,
F6A82B7C1CE2858B007C3A32 /* LegacyObjectGraphTests.swift */,
F6A82B7E1CE2E299007C3A32 /* CanonicalRepresentableTests.swift */,
F6A82B801CE2F182007C3A32 /* DebuggingTests.swift */,
F6760C611D2DFA1E009C6F8A /* ScopedTests.swift */,
F624D2951D4023D900C36F98 /* CycleTests.swift */,
);
path = CleanseTests;
sourceTree = "<group>";
};
F6AB45161CD9E8B40021AF36 /* Components */ = {
isa = PBXGroup;
children = (
F62C69F41CD8481200137422 /* ComponentVisitor.swift */,
F61133C41CD7B5A900069972 /* Component.swift */,
F62C69F41CD8481200137422 /* ComponentVisitor.swift */,
);
name = Components;
sourceTree = "<group>";
Expand All @@ -384,6 +387,14 @@
name = "Collection Binding";
sourceTree = "<group>";
};
F6D589ED1D3ED55100B99F7D /* Validations */ = {
isa = PBXGroup;
children = (
F6D589EE1D3ED57900B99F7D /* SatisfiedDependenciesValidationVisitor.swift */,
);
name = Validations;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -495,6 +506,7 @@
F6615D231CD026890079DE8D /* ProviderProvider.swift in Sources */,
F6A660F31CCB1B6B004DD6E3 /* Scope.swift in Sources */,
F6B387951CE18E53001CBC4F /* SingularCollectionBindingBuilderDecorator.swift in Sources */,
F6D589EF1D3ED57900B99F7D /* SatisfiedDependenciesValidationVisitor.swift in Sources */,
F62C6A061CD919A100137422 /* OverrideModule.swift in Sources */,
F61191381CD329F500686C0C /* Tags.swift in Sources */,
F62C69FF1CD897D200137422 /* TaggedProvider.swift in Sources */,
Expand Down Expand Up @@ -536,6 +548,7 @@
F69D1AA01CDDE229009132B4 /* BinderArities.swift in Sources */,
F63EF7961CD2F8430016306D /* SourceLocation.swift in Sources */,
F6B387901CE18BB2001CBC4F /* BaseBindingBuilder.swift in Sources */,
F624D2941D40172A00C36F98 /* WeakProvider.swift in Sources */,
F62C69FD1CD8927400137422 /* CanonicalRepresentable.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -544,14 +557,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F624D2961D4023D900C36F98 /* CycleTests.swift in Sources */,
F6615D1D1CD00FC10079DE8D /* PropertyInjectionTests.swift in Sources */,
F6A82B811CE2F182007C3A32 /* DebuggingTests.swift in Sources */,
F6A660DA1CCB07C3004DD6E3 /* CleanseTests.swift in Sources */,
F6A82B7D1CE2858B007C3A32 /* LegacyObjectGraphTests.swift in Sources */,
F6760C621D2DFA1E009C6F8A /* ScopedTests.swift in Sources */,
F61191361CD30B3300686C0C /* ErrorTest.swift in Sources */,
F6AB45151CD9D1F90021AF36 /* NoopVisitor.swift in Sources */,
F611913C1CD34F1E00686C0C /* StressTests.swift in Sources */,
F6B3879B1CE1A03C001CBC4F /* SubcomponentTests.swift in Sources */,
F61133C11CD7B36600069972 /* MemoryManagementTests.swift in Sources */,
F6A82B7F1CE2E299007C3A32 /* CanonicalRepresentableTests.swift in Sources */,
Expand Down Expand Up @@ -610,9 +622,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "-DSUPPORT_LEGACY_OBJECT_GRAPH -suppress-warnings";
OTHER_SWIFT_FLAGS = "-DSUPPORT_LEGACY_OBJECT_GRAPH";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SUPPRESS_WARNINGS = YES;
SWIFT_VERSION = 2.3;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -654,8 +667,9 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_SWIFT_FLAGS = "-DSUPPORT_LEGACY_OBJECT_GRAPH -suppress-warnings";
OTHER_SWIFT_FLAGS = "-DSUPPORT_LEGACY_OBJECT_GRAPH";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx";
SWIFT_SUPPRESS_WARNINGS = YES;
SWIFT_VERSION = 2.3;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
Expand All @@ -667,6 +681,7 @@
F6A660DF1CCB07C3004DD6E3 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -686,6 +701,7 @@
F6A660E01CCB07C3004DD6E3 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -704,9 +720,10 @@
F6A660E21CCB07C3004DD6E3 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = CleanseTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.squareup.CleanseTests;
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -715,9 +732,10 @@
F6A660E31CCB07C3004DD6E3 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = CleanseTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.squareup.CleanseTests;
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand Down
5 changes: 4 additions & 1 deletion Cleanse/BaseComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public protocol _AnyBaseComponent : Configurable {
/// Base protocol for both Components and Subcomponenents

public protocol _BaseComponent : _AnyBaseComponent {
/// This is the binding required to construct a new subcomponent
associatedtype Seed = Void

/// This should be set to the root type of object that is created.
associatedtype Root

associatedtype Scope: Cleanse.Scope
}
}
15 changes: 5 additions & 10 deletions Cleanse/BindingBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ extension Binder {
public protocol _StandardProvider : ProviderProtocol {
}

extension Provider : _StandardProvider {
protocol _AnyStandardProvider : AnyProvider {
}

extension Provider : _StandardProvider, _AnyStandardProvider {
}

/// MARK: Building steps
Expand Down Expand Up @@ -126,14 +129,6 @@ extension BindingBuilder {
anyCollectionMergeFunc = nil
}

let componentOrSubcomponentProvider: AnyProvider?

if MaybeComponentOrSubcomponent.self is _AnyBaseComponent.Type && Input.self == MaybeComponentOrSubcomponent.self {
componentOrSubcomponentProvider = provider.asProvider()
} else {
componentOrSubcomponentProvider = nil
}

let scope: Scope.Type?

// If we explicitely declared our scope (e.g. `scopedIn(
Expand All @@ -149,7 +144,7 @@ extension BindingBuilder {
scope: scope,
provider: mappedProvider as! AnyProvider,
collectionMergeFunc: anyCollectionMergeFunc,
componentOrSubcomponentProvider: componentOrSubcomponentProvider
sourceLocation: SourceLocation(file: file, line: line, function: function)
)

binder._internalBind(binding: rpb)
Expand Down
2 changes: 0 additions & 2 deletions Cleanse/BindingBuilderDecorator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public protocol BindingBuilderDecorator : BindingBuilder {

associatedtype CollectionOrUnique: _CollectionOrUniqueBindingBase = Wrapped.CollectionOrUnique

associatedtype MaybeComponentOrSubcomponent: Any = Wrapped.MaybeComponentOrSubcomponent

static var collectionMergeFunc: Optional<[FinalProvider.Element] -> FinalProvider.Element> { get }
}

Expand Down
43 changes: 22 additions & 21 deletions Cleanse/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,36 @@ public protocol _AnyRootComponent : _AnyBaseComponent {
}


/// RootComponent has been renamed to RootComponent
#if swift(>=3.0)
@available(*, deprecated, renamed:"RootComponent")
public typealias Component = RootComponent
#else
@available(*, deprecated, renamed="RootComponent")
public typealias Component = RootComponent
#endif

public protocol RootComponent : Module, _BaseComponent, _AnyRootComponent {
/// This should be set to the root type of object that is created.
associatedtype Root

public protocol RootComponent : Component, _AnyRootComponent {
associatedtype Scope = Singleton
}

public extension RootComponent {
/// Builds the component and returns the root object.
/// - throws: `CleanseError` if the component fails validation.
public func build() throws -> Root {
let graph = Graph(scope: Self.Scope.scopeOrNil)
public extension ComponentFactoryProtocol {
public static func of(_ componentType: ComponentElement.Type, validate: Bool = true) throws -> ComponentFactory<ComponentElement> {

if validate {
let validator = SatisfiedDependenciesValidationVisitor()
validator.install(dependency: ComponentElement.self)
try validator.finalize()
}

let p = graph.provider(Root.self)
let graph = Graph(scope: nil)

graph.install(module: self)
let p = graph.provider(ComponentFactory<ComponentElement>.self)

try graph.finalize()
graph.install(dependency: ComponentElement.self)

try graph.finalize()

return p.get()
}
}



extension Component {
// Returns true if we're a RootComponents
static var isRootComponent: Bool {
return self is _AnyRootComponent.Type
}
}
Loading

0 comments on commit 5fa86c3

Please sign in to comment.