From d2a948e7c7eac878c167edc1ebfb6699295162f3 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: Mon, 8 Jan 2024 18:12:59 +0300 Subject: [PATCH] d --- Modules/BusX/BusUI/src/BusUI.ManyButton.swift | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Modules/BusX/BusUI/src/BusUI.ManyButton.swift diff --git a/Modules/BusX/BusUI/src/BusUI.ManyButton.swift b/Modules/BusX/BusUI/src/BusUI.ManyButton.swift new file mode 100644 index 0000000..a82031d --- /dev/null +++ b/Modules/BusX/BusUI/src/BusUI.ManyButton.swift @@ -0,0 +1,35 @@ +import Combine + +extension BusUI { + public final class ManyButton: ObservableObject { + let key: String + public let v = PassthroughSubject() + @Published public var id: String? + var sub = [AnyCancellable]() + var subscriptions = [AnyCancellable]() + + public init(_ key: String) { + self.key = key + + $id + .sink { [weak self] id in self?.setup(id) } + .store(in: &sub) + } + + private func setup(_ id: String?) { + subscriptions = [] + + Bus.sendSync( + key, + v + .compactMap { v -> Any? in + guard let id else { return nil } + var d = [String: Bool]() + return MPAK.Many([id], d) + } + .eraseToAnyPublisher(), + &subscriptions + ) + } + } +}