Last active
November 7, 2017 15:45
-
-
Save soxjke/9d2f0605cb5a6eb713084e09fcc687e7 to your computer and use it in GitHub Desktop.
This file contains 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 AuthError: Error { | |
case wrongAuthData, | |
case wrongDeauthData | |
} | |
class AuthManager { | |
let networkManager: // injected dependency | |
func deauthenticateUser(user: User) -> SignalProducer<User, AuthError> { | |
// perhaps go to network: | |
return SignalProducer { (observer, disposable) in | |
let netOperationToken = networkManager.deauthenticate(user: user) { (user, error) in | |
if let error = error { | |
observer.send(error: error) | |
} else { | |
observer.send(user) | |
observer.sendCompleted() | |
} | |
} | |
return AnyDisposable { | |
networkManager.cancel(netOperationToken) | |
} | |
} | |
} | |
func authenticateUser(user: User) -> SignalProducer<User, AuthError> { | |
// pretty same shit | |
} | |
} | |
class AuthManager2 { | |
private let innerAuthenticatedUsers = MutableProperty<[User], NoError>([]) | |
public let authenticatedUsers: = Property<[User], NoError>(capturing: innerAuthenticatedUsers) | |
public func authenticate(user: User) { | |
// at some point of time: | |
innerAuthenticatedUsers.value = innerAuthenticatedUsers.value + [user] | |
} | |
} | |
// client code: | |
AuthManager2.shared.authenticatedUsers.producer.startWithValues { (authenticatedUsersArray) in | |
// here will go array of authenticated users updates | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment