Михаил Капелько 10 months ago
parent
commit
676a1ada17
7 changed files with 24 additions and 70 deletions
  1. +1
    -2
      Modules/BusX/Bus/src/Bus.swift
  2. +2
    -10
      Modules/BusX/BusUI/src/BusUI.Button.swift
  3. +3
    -11
      Modules/BusX/BusUI/src/BusUI.TextField.swift
  4. +2
    -9
      Modules/BusX/BusUI/src/BusUI.Value.swift
  5. +0
    -23
      Modules/MeetupIdX/src/MeetupId.Component.swift
  6. +14
    -13
      Modules/MeetupIdX/src/MeetupId.V.swift
  7. +2
    -2
      src/App.swift

+ 1
- 2
Modules/BusX/Bus/src/Bus.swift View File

@@ -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))
}
}

+ 2
- 10
Modules/BusX/BusUI/src/BusUI.Button.swift View File

@@ -5,17 +5,9 @@ extension BusUI {
public let v = PassthroughSubject<Void, Never>()
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
)


+ 3
- 11
Modules/BusX/BusUI/src/BusUI.TextField.swift View File

@@ -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
)


+ 2
- 9
Modules/BusX/BusUI/src/BusUI.Value.swift View File

@@ -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
)


+ 0
- 23
Modules/MeetupIdX/src/MeetupId.Component.swift View File

@@ -1,23 +0,0 @@
import BusX

extension MeetupId {
final class Component: ObservableObject {
var isJoinAvailable: BusUI.Value<Bool>
var isLoading: BusUI.Value<Bool>
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)
}
}
}


+ 14
- 13
Modules/MeetupIdX/src/MeetupId.V.swift View File

@@ -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()


+ 2
- 2
src/App.swift View File

@@ -4,9 +4,9 @@ import UIKit

struct Content: View {
var body: some View {
MeetupId.V("")
MeetupId.V()
Divider()
MeetupId.V("abc")
MeetupId.V()
}
}



Loading…
Cancel
Save