mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Fix Suggestion Pattern when text is empty (#1943)
* fix + debounce improvement * comment * improved existing function to be more generic
This commit is contained in:
@@ -25,16 +25,23 @@ extension Publisher where Self.Failure == Never {
|
||||
}
|
||||
}
|
||||
|
||||
extension Publisher where Output == String, Failure == Never {
|
||||
/// Debounce text queries and remove duplicates.
|
||||
/// Clearing the text publishes the update immediately.
|
||||
func debounceAndRemoveDuplicates() -> AnyPublisher<String, Never> {
|
||||
extension Publisher where Output: Equatable, Failure == Never {
|
||||
func debounceAndRemoveDuplicates<S: Scheduler>(on scheduler: S, delay: @escaping (Output) -> S.SchedulerTimeType.Stride) -> AnyPublisher<Output, Never> {
|
||||
map { query in
|
||||
let milliseconds = query.isEmpty ? 0 : 250
|
||||
return Just(query).delay(for: .milliseconds(milliseconds), scheduler: DispatchQueue.main)
|
||||
Just(query).delay(for: delay(query), scheduler: scheduler)
|
||||
}
|
||||
.switchToLatest()
|
||||
.removeDuplicates()
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
||||
extension Publisher where Output == String, Failure == Never {
|
||||
/// Debounce text queries and remove duplicates.
|
||||
/// Clearing the text publishes the update immediately.
|
||||
func debounceTextQueriesAndRemoveDuplicates() -> AnyPublisher<String, Never> {
|
||||
debounceAndRemoveDuplicates(on: DispatchQueue.main) { query in
|
||||
query.isEmpty ? .milliseconds(0) : .milliseconds(250)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user