From 2ab746413c799fc1071831574745c99144eb8e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Fri, 29 Dec 2023 13:43:53 +0300 Subject: [PATCH] d --- Modules/MeetupIdX/src/MeetupId.Delay.swift | 31 ++++++++++++++++++++++ Modules/MeetupIdX/src/MeetupId.V.swift | 4 +-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Modules/MeetupIdX/src/MeetupId.Delay.swift diff --git a/Modules/MeetupIdX/src/MeetupId.Delay.swift b/Modules/MeetupIdX/src/MeetupId.Delay.swift new file mode 100644 index 0000000..78243d8 --- /dev/null +++ b/Modules/MeetupIdX/src/MeetupId.Delay.swift @@ -0,0 +1,31 @@ +import BusX +import Combine + +extension MeetupId { + final class Delay { + let v = PassthroughSubject() + 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 + ) + } + } +} diff --git a/Modules/MeetupIdX/src/MeetupId.V.swift b/Modules/MeetupIdX/src/MeetupId.V.swift index a68e81b..0b58370 100644 --- a/Modules/MeetupIdX/src/MeetupId.V.swift +++ b/Modules/MeetupIdX/src/MeetupId.V.swift @@ -4,13 +4,13 @@ import SwiftUI extension MeetupId { public struct V: View { - let fmt = MeetupId.Debounce(5, formatId, K.textUI, K.textApp) @StateObject var isJoinAvailable = Cord.Receive(K.isJoinAvailable, false) @StateObject var isLoading = Cord.Receive(K.isLoading, false) @StateObject var join = Cord.Button(K.join) @StateObject var textField = Cord.TextField(K.textApp, K.textUI) - let procs: [Any] = [ + let processors: [Any] = [ Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable), + MeetupId.Debounce(5, formatId, K.textUI, K.textApp), ] public init() { }