Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Sources/NeedleFoundation/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,21 @@ open class Component<DependencyType>: Scope {

public var localTable = [String:()->Any]()
public var keyPathToName = [PartialKeyPath<DependencyType>:String]()


/// Fully qualified name of the Component, such as `"MyParentClass.EnumThatIsAComponent"`
///
/// The default implementation uses `String(describing: self)`, which can be a bit slow. Override this
/// with a faster implementation (such as a hard-coded `String`) if you've identified slowness due to this property.
open var fullyQualifiedName: String {
String(describing: self)
}

// MARK: - Private

private let sharedInstanceLock = NSRecursiveLock()
private var sharedInstances = [String: Any]()
private lazy var name: String = {
let fullyQualifiedSelfName = String(describing: self)
let fullyQualifiedSelfName = fullyQualifiedName
let parts = fullyQualifiedSelfName.components(separatedBy: ".")
return parts.last ?? fullyQualifiedSelfName
}()
Expand Down Expand Up @@ -266,12 +274,20 @@ open class Component<DependencyType>: Scope {
return dependency[keyPath: keyPath]
}

/// Fully qualified name of the Component, such as `"MyParentClass.EnumThatIsAComponent"`
///
/// The default implementation uses `String(describing: self)`, which can be a bit slow. Override this
/// with a faster implementation (such as a hard-coded `String`) if you've identified slowness due to this property.
open var fullyQualifiedName: String {
String(describing: self)
}

// MARK: - Private

private let sharedInstanceLock = NSRecursiveLock()
private var sharedInstances = [String: Any]()
private lazy var name: String = {
let fullyQualifiedSelfName = String(describing: self)
let fullyQualifiedSelfName = fullyQualifiedName
let parts = fullyQualifiedSelfName.components(separatedBy: ".")
return parts.last ?? fullyQualifiedSelfName
}()
Expand Down