d
This commit is contained in:
31
Modules/MeetupIdX/src/MeetupId.Delay.swift
Normal file
31
Modules/MeetupIdX/src/MeetupId.Delay.swift
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import BusX
|
||||||
|
import Combine
|
||||||
|
|
||||||
|
extension MeetupId {
|
||||||
|
final class Delay<Src, Dst> {
|
||||||
|
let v = PassthroughSubject<Src, Never>()
|
||||||
|
var subscriptions = [AnyCancellable]()
|
||||||
|
|
||||||
|
init(
|
||||||
|
_ sec: Double,
|
||||||
|
_ handler: @escaping ((Src) -> Dst?),
|
||||||
|
_ src: String,
|
||||||
|
_ dst: String
|
||||||
|
) {
|
||||||
|
Bus.receive(
|
||||||
|
[src],
|
||||||
|
{ [weak self] _, v in self?.v.send(v) },
|
||||||
|
sub: &subscriptions
|
||||||
|
)
|
||||||
|
|
||||||
|
Bus.send(
|
||||||
|
dst,
|
||||||
|
v
|
||||||
|
.delay(for: .seconds(sec), scheduler: DispatchQueue.main)
|
||||||
|
.compactMap { (v: Src) in handler(v) }
|
||||||
|
.eraseToAnyPublisher(),
|
||||||
|
sub: &subscriptions
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,13 +4,13 @@ import SwiftUI
|
|||||||
|
|
||||||
extension MeetupId {
|
extension MeetupId {
|
||||||
public struct V: View {
|
public struct V: View {
|
||||||
let fmt = MeetupId.Debounce(5, formatId, K.textUI, K.textApp)
|
|
||||||
@StateObject var isJoinAvailable = Cord.Receive(K.isJoinAvailable, false)
|
@StateObject var isJoinAvailable = Cord.Receive(K.isJoinAvailable, false)
|
||||||
@StateObject var isLoading = Cord.Receive(K.isLoading, false)
|
@StateObject var isLoading = Cord.Receive(K.isLoading, false)
|
||||||
@StateObject var join = Cord.Button(K.join)
|
@StateObject var join = Cord.Button(K.join)
|
||||||
@StateObject var textField = Cord.TextField(K.textApp, K.textUI)
|
@StateObject var textField = Cord.TextField(K.textApp, K.textUI)
|
||||||
let procs: [Any] = [
|
let processors: [Any] = [
|
||||||
Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable),
|
Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable),
|
||||||
|
MeetupId.Debounce(5, formatId, K.textUI, K.textApp),
|
||||||
]
|
]
|
||||||
|
|
||||||
public init() { }
|
public init() { }
|
||||||
|
|||||||
Reference in New Issue
Block a user