import Combine import MPAKX 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 sub = [AnyCancellable]() var subscriptions = [AnyCancellable]() public init( _ textApp: String, _ textUI: String ) { self.textApp = textApp self.textUI = textUI $id .sink { [weak self] id in self?.setup(id) } .store(in: &sub) } private func setup(_ id: String?) { subscriptions = [] Bus.sendSync( textUI, $v .removeDuplicates() .compactMap { v -> Any? in guard let id, let text = onlyUIText(v) else { return nil } var d = [String: String]() d[id] = text return MPAK.Many([id], d) } .eraseToAnyPublisher(), &subscriptions ) Bus.receiveSync( [textApp], { [weak self] (_, m: MPAK.Many) in guard let id, m.keys.contains(id), let text = m.dict[id] else { return } self?.v = "a:\(text)" }, &subscriptions ) } } }