From 676a1ada1729905967fdb045587e4040bf0067e7 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: Sat, 6 Jan 2024 18:35:45 +0300 Subject: [PATCH] d --- Modules/BusX/Bus/src/Bus.swift | 3 +-- Modules/BusX/BusUI/src/BusUI.Button.swift | 12 ++------- Modules/BusX/BusUI/src/BusUI.TextField.swift | 14 +++------- Modules/BusX/BusUI/src/BusUI.Value.swift | 11 ++------ .../MeetupIdX/src/MeetupId.Component.swift | 23 ---------------- Modules/MeetupIdX/src/MeetupId.V.swift | 27 ++++++++++--------- src/App.swift | 4 +-- 7 files changed, 24 insertions(+), 70 deletions(-) delete mode 100644 Modules/MeetupIdX/src/MeetupId.Component.swift diff --git a/Modules/BusX/Bus/src/Bus.swift b/Modules/BusX/Bus/src/Bus.swift index 86bd66e..33ae467 100644 --- a/Modules/BusX/Bus/src/Bus.swift +++ b/Modules/BusX/Bus/src/Bus.swift @@ -45,13 +45,12 @@ public extension Bus { _ subscriptions: inout [AnyCancellable] ) { node - .sink { v in send(key, v) } + .sink { v in e.send((key, v)) } .store(in: &subscriptions) } /// Единоразово синхронно отправляем событие в шину. static func send(_ key: String, _ value: Any) { - /**/print("ИГР Bus.send k/v: '\(key)'/'\(value)'") e.send((key, value)) } } diff --git a/Modules/BusX/BusUI/src/BusUI.Button.swift b/Modules/BusX/BusUI/src/BusUI.Button.swift index 69c23b9..44166aa 100644 --- a/Modules/BusX/BusUI/src/BusUI.Button.swift +++ b/Modules/BusX/BusUI/src/BusUI.Button.swift @@ -5,17 +5,9 @@ extension BusUI { public let v = PassthroughSubject() var subscriptions = [AnyCancellable]() - public init( - _ key: String, - _ id: String? = nil - ) { - var k = key - if let id { - k = k + id - } - + public init(_ key: String) { Bus.sendSync( - k, + key, v.map { true }.eraseToAnyPublisher(), &subscriptions ) diff --git a/Modules/BusX/BusUI/src/BusUI.TextField.swift b/Modules/BusX/BusUI/src/BusUI.TextField.swift index dbeba8b..c48ffd7 100644 --- a/Modules/BusX/BusUI/src/BusUI.TextField.swift +++ b/Modules/BusX/BusUI/src/BusUI.TextField.swift @@ -8,18 +8,10 @@ extension BusUI { public init( _ textApp: String, - _ textUI: String, - _ id: String? = nil + _ textUI: String ) { - var ka = textApp - var ku = textUI - if let id { - ka = ka + id - ku = ku + id - } - Bus.sendSync( - ku, + textUI, $v .removeDuplicates() .compactMap(onlyUIText) @@ -28,7 +20,7 @@ extension BusUI { ) Bus.receiveSync( - [ka], + [textApp], { [weak self] (_, v: String) in self?.v = "a:\(v)" }, &subscriptions ) diff --git a/Modules/BusX/BusUI/src/BusUI.Value.swift b/Modules/BusX/BusUI/src/BusUI.Value.swift index 203461e..558e4af 100644 --- a/Modules/BusX/BusUI/src/BusUI.Value.swift +++ b/Modules/BusX/BusUI/src/BusUI.Value.swift @@ -7,18 +7,11 @@ extension BusUI { public init( _ key: String, - _ defaultValue: T, - _ id: String? = nil + _ defaultValue: T ) { v = defaultValue - - var k = key - if let id { - k = k + id - } - Bus.receiveSync( - [k], + [key], { [weak self] (_, v: T) in self?.v = v }, &subscriptions ) diff --git a/Modules/MeetupIdX/src/MeetupId.Component.swift b/Modules/MeetupIdX/src/MeetupId.Component.swift deleted file mode 100644 index 958dc34..0000000 --- a/Modules/MeetupIdX/src/MeetupId.Component.swift +++ /dev/null @@ -1,23 +0,0 @@ -import BusX - -extension MeetupId { - final class Component: ObservableObject { - var isJoinAvailable: BusUI.Value - var isLoading: BusUI.Value - var join: BusUI.Button - var textField: BusUI.TextField - - deinit { - /**/print("ИГР MeetupIC.deinit") - } - - public init(_ id: String) { - /**/print("ИГР MeetupIC.init") - isJoinAvailable = .init(K.isJoinAvailable, false, id) - isLoading = .init(K.isLoading, false, id) - join = .init(K.join, id) - textField = .init(K.textApp, K.textUI, id) - } - } -} - diff --git a/Modules/MeetupIdX/src/MeetupId.V.swift b/Modules/MeetupIdX/src/MeetupId.V.swift index 2c640e9..0c76631 100644 --- a/Modules/MeetupIdX/src/MeetupId.V.swift +++ b/Modules/MeetupIdX/src/MeetupId.V.swift @@ -3,38 +3,39 @@ import SwiftUI extension MeetupId { public struct V: View { - @StateObject private var cmp: Component + @StateObject var isJoinAvailable = BusUI.Value(K.isJoinAvailable, false) + @StateObject var isLoading = BusUI.Value(K.isLoading, false) + @StateObject var join = BusUI.Button(K.join) + @StateObject var textField = BusUI.TextField(K.textApp, K.textUI) - public init(_ id: String) { - // https://stackoverflow.com/a/62636048 - _cmp = StateObject(wrappedValue: Component(id)) + public init() { } public var body: some View { VStack(spacing: 8) { HStack { - TextField("Binding-3", value: $cmp.textField.v, formatter: BusUI.TextFieldSource()) - .disabled(cmp.isLoading.v) + TextField("Binding-3", value: $textField.v, formatter: BusUI.TextFieldSource()) + .disabled(isLoading.v) .padding(8) .border( - !cmp.isLoading.v ? Color.black : Color.gray, - width: !cmp.isLoading.v ? 2 : 1 + !isLoading.v ? Color.black : Color.gray, + width: !isLoading.v ? 2 : 1 ) - if cmp.isLoading.v { + if isLoading.v { ProgressView() .padding(8) } } - Button(action: cmp.join.v.send) { + Button(action: join.v.send) { Text("Join") .padding(8) .border( - cmp.isJoinAvailable.v ? Color.green : Color.gray, - width: cmp.isJoinAvailable.v ? 2 : 1 + isJoinAvailable.v ? Color.green : Color.gray, + width: isJoinAvailable.v ? 2 : 1 ) } - .disabled(!cmp.isJoinAvailable.v) + .disabled(!isJoinAvailable.v) } .frame(width: 320) .padding() diff --git a/src/App.swift b/src/App.swift index 119c4a8..ddf2865 100644 --- a/src/App.swift +++ b/src/App.swift @@ -4,9 +4,9 @@ import UIKit struct Content: View { var body: some View { - MeetupId.V("") + MeetupId.V() Divider() - MeetupId.V("abc") + MeetupId.V() } }