Refactoring

This commit is contained in:
Justin Mazzocchi 2020-10-03 13:55:07 -07:00
parent 758c375547
commit 9507343511
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 3 additions and 10 deletions

View file

@ -218,17 +218,12 @@ public extension ContentDatabase {
.eraseToAnyPublisher() .eraseToAnyPublisher()
} }
func accountObservation(id: String) -> AnyPublisher<Account?, Error> { func accountObservation(id: String) -> AnyPublisher<Account, Error> {
ValueObservation.tracking(AccountInfo.request(AccountRecord.filter(AccountRecord.Columns.id == id)).fetchOne) ValueObservation.tracking(AccountInfo.request(AccountRecord.filter(AccountRecord.Columns.id == id)).fetchOne)
.removeDuplicates() .removeDuplicates()
.map {
if let info = $0 {
return Account(info: info)
} else {
return nil
}
}
.publisher(in: databaseWriter) .publisher(in: databaseWriter)
.compactMap { $0 }
.map(Account.init(info:))
.eraseToAnyPublisher() .eraseToAnyPublisher()
} }

View file

@ -35,8 +35,6 @@ public struct ProfileService {
self.contentDatabase = contentDatabase self.contentDatabase = contentDatabase
var accountPublisher = contentDatabase.accountObservation(id: accountID) var accountPublisher = contentDatabase.accountObservation(id: accountID)
.compactMap { $0 }
.eraseToAnyPublisher()
if let account = account { if let account = account {
accountPublisher = accountPublisher accountPublisher = accountPublisher