This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Mode { | |
case small | |
case medium | |
struct Dimensions { | |
let colorDepth: Int | |
let width: Int | |
let height: Int | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let authenticator = Authenticator() | |
authenticator.authenticateSuccessfully() | |
//authenticator.authenticateUnsuccessfully() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoginContainer.instance.register(plugin: PostLoginSuccessPlugin.self, with: UserProfilePostLoginPluginImplementation()) | |
LoginContainer.instance.register(plugin: PostLoginSuccessPlugin.self, with: UserFeedPostLoginPluginImplementation()) | |
LoginContainer.instance.register(plugin: PostLoginSuccessPlugin.self, with: LocalStoragePostLoginPluginImplementation()) | |
LoginContainer.instance.register(plugin: PostLoginFailurePlugin.self, with: LocalStoragePostLoginPluginImplementation()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class UserProfilePostLoginPluginImplementation: PostLoginSuccessPlugin { | |
func successfulLogin(userId: String) { | |
print("Fetching user profile with id \(userId)...") | |
} | |
} | |
final class UserFeedPostLoginPluginImplementation: PostLoginSuccessPlugin { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Authenticator { | |
public init() {} | |
public func authenticateSuccessfully() { | |
print("Logging in...") | |
print("Logged in successfully...") | |
LoginContainer.instance.resolve(forPlugin: PostLoginSuccessPlugin.self).forEach(successfulLogin) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class LoginContainer { | |
private var registry = [String: [() -> Any]]() | |
private init() {} | |
} | |
public extension LoginContainer { | |
static let instance = LoginContainer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum FailedLogin: Error { | |
case userNotFound | |
} | |
public protocol PostLoginFailurePlugin { | |
func failedLogin(error: FailedLogin) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public typealias UserId = String | |
public protocol PostLoginSuccessPlugin { | |
func successfulLogin(userId: UserId) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Authenticator { | |
public init() {} | |
public func authenticateSuccessfully() { | |
print("Logging in...") | |
print("Logged in successfully...") | |
} | |
public func authenticateUnsuccessfully() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getCurrentUser() -> Promise<User> { | |
if let existing = cache.getCurrentUser() { return existing } | |
let user = Promise<User> { fulfill, reject in | |
DispatchQueue.global(qos: .background).async { | |
let user = self.dummyServiceCall() | |
DispatchQueue.main.asyncAfter(deadline: self.delay) { | |
fulfill(user) | |
} | |
} |
NewerOlder