-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3404070
commit 887f789
Showing
10 changed files
with
116 additions
and
29 deletions.
There are no files selected for viewing
29 changes: 27 additions & 2 deletions
29
Core/Sources/HostApp/AdvancedSettings/EnterpriseSection.swift
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
25 changes: 25 additions & 0 deletions
25
Core/Sources/HostApp/SharedComponents/DebouncedBinding.swift
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,25 @@ | ||
import Combine | ||
import SwiftUI | ||
|
||
class DebouncedBinding<T> { | ||
private let subject = PassthroughSubject<T, Never>() | ||
private let cancellable: AnyCancellable | ||
private let wrappedBinding: Binding<T> | ||
|
||
init(_ binding: Binding<T>, handler: @escaping (T) -> Void) { | ||
self.wrappedBinding = binding | ||
self.cancellable = subject | ||
.debounce(for: .seconds(1.0), scheduler: RunLoop.main) | ||
.sink { handler($0) } | ||
} | ||
|
||
var binding: Binding<T> { | ||
return Binding( | ||
get: { self.wrappedBinding.wrappedValue }, | ||
set: { | ||
self.wrappedBinding.wrappedValue = $0 | ||
self.subject.send($0) | ||
} | ||
) | ||
} | ||
} |
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
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