From 1f501d82764d543105f7cf20447ad16886be0043 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 10:14:18 +0300 Subject: [PATCH] d --- .../BusX/BusUI/src/BusUI.ManyTextField.swift | 49 +++++++++++++++++++ Modules/BusX/BusUI/src/BusUI.TextField.swift | 19 ------- 2 files changed, 49 insertions(+), 19 deletions(-) create mode 100644 Modules/BusX/BusUI/src/BusUI.ManyTextField.swift diff --git a/Modules/BusX/BusUI/src/BusUI.ManyTextField.swift b/Modules/BusX/BusUI/src/BusUI.ManyTextField.swift new file mode 100644 index 0000000..02c9949 --- /dev/null +++ b/Modules/BusX/BusUI/src/BusUI.ManyTextField.swift @@ -0,0 +1,49 @@ +import Combine +import SwiftUI + +extension BusUI { + public final class ManyTextField: ObservableObject { + let textApp: String + let textUI: String + @Published public var id: String? + @Published public var v = "a:" + var subscriptions = [AnyCancellable]() + var sub = [AnyCancellable]() + + public init( + _ textApp: String, + _ textUI: String + ) { + self.textApp = textApp + self.textUI = textUI + + /**///print("ИГР BusUTF(\(Unmanaged.passUnretained(self).toOpaque())).init textA/textU: '\(textApp)'/'\(textUI)'") + + $id + .sink { [weak self] v in self?.setup(v) } + .store(in: &sub) + } + + private func setup(_ id: String?) { + /**/print("ИГР BusUTF(\(Unmanaged.passUnretained(self).toOpaque())).setup id: '\(id)'") + + subscriptions = [] + + Bus.sendSync( + textUI, + $v + .removeDuplicates() + .compactMap(onlyUIText) + .compactMap { .... + id? } + .eraseToAnyPublisher(), + &subscriptions + ) + + Bus.receiveSync( + [textApp], + { [weak self] (_, v: String) in self?.v = "a:\(v)" }, + &subscriptions + ) + } + } +} diff --git a/Modules/BusX/BusUI/src/BusUI.TextField.swift b/Modules/BusX/BusUI/src/BusUI.TextField.swift index 2cd9faa..c48ffd7 100644 --- a/Modules/BusX/BusUI/src/BusUI.TextField.swift +++ b/Modules/BusX/BusUI/src/BusUI.TextField.swift @@ -3,32 +3,13 @@ import SwiftUI extension BusUI { public final class TextField: ObservableObject { - let textApp: String - let textUI: String - @Published public var id: String? @Published public var v = "a:" var subscriptions = [AnyCancellable]() - var sub = [AnyCancellable]() public init( _ textApp: String, _ textUI: String ) { - self.textApp = textApp - self.textUI = textUI - - /**///print("ИГР BusUTF(\(Unmanaged.passUnretained(self).toOpaque())).init textA/textU: '\(textApp)'/'\(textUI)'") - - $id - .sink { [weak self] v in self?.setup(v) } - .store(in: &sub) - } - - private func setup(_ id: String?) { - /**/print("ИГР BusUTF(\(Unmanaged.passUnretained(self).toOpaque())).setup id: '\(id)'") - - subscriptions = [] - Bus.sendSync( textUI, $v