-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move cached users from UserService to DataStore (#23865)
* Move cached users from UserService to DataStore * Repurpose UserServiceTests to test view model instead * Add unit tests for InMemoryDataStore
- Loading branch information
1 parent
f756703
commit e1061ff
Showing
12 changed files
with
308 additions
and
145 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Foundation | ||
import Combine | ||
|
||
public actor InMemoryUserDataStore: UserDataStore, InMemoryDataStore { | ||
public typealias T = DisplayUser | ||
|
||
public var storage: [T.ID: T] = [:] | ||
public let updates: PassthroughSubject<Set<T.ID>, Never> = .init() | ||
|
||
deinit { | ||
updates.send(completion: .finished) | ||
} | ||
|
||
public func list(query: Query) throws -> [T] { | ||
switch query { | ||
case .all: | ||
return Array(storage.values) | ||
case let .id(ids): | ||
return storage.reduce(into: []) { | ||
if ids.contains($1.key) { | ||
$0.append($1.value) | ||
} | ||
} | ||
case let .search(keyword): | ||
let theKeyword = keyword.trimmingCharacters(in: .whitespacesAndNewlines) | ||
if theKeyword.isEmpty { | ||
return Array(storage.values) | ||
} else { | ||
return storage.values.search(theKeyword, using: \.searchString) | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.