Михаил Капелько 11 months ago
parent
commit
4ae712be4c
6 changed files with 32 additions and 12 deletions
  1. +2
    -0
      Modules/MeetupIdX/MeetupId.yml
  2. +8
    -6
      Modules/MeetupIdX/src/MeetupId.Debounce.swift
  3. +1
    -0
      Modules/MeetupIdX/src/MeetupId.K.swift
  4. +9
    -0
      Modules/MeetupIdX/src/MeetupId.Shoulds.swift
  5. +10
    -4
      Modules/MeetupIdX/src/MeetupId.V.swift
  6. +2
    -2
      app/Podfile.lock

+ 2
- 0
Modules/MeetupIdX/MeetupId.yml View File

@@ -1,6 +1,7 @@
version: 2

model:
finishLoading: [Bool, false]
isLoading: [Bool, false]
join: [Bool, false]
textUI: [String, ""]
@@ -10,6 +11,7 @@ service:
busModel
🚀shouldResetLoading: Bus.send(K.isLoading, v)
pipes:
finishLoading: [toggle, K.finishLoading]
isLoading: [recent, K.isLoading]
join: [toggle, K.join]
textUI: [recent, K.textUI]


Modules/MeetupIdX/src/MeetupId.Formatter.swift → Modules/MeetupIdX/src/MeetupId.Debounce.swift View File

@@ -2,25 +2,27 @@ import BusX
import Combine

extension MeetupId {
final class Formatter: ObservableObject {
let text = PassthroughSubject<String, Never>()
final class Debounce<Src, Dst> {
let v = PassthroughSubject<Src, Never>()
var subscriptions = [AnyCancellable]()

init(
_ sec: Double,
_ handler: @escaping ((Src) -> Dst?),
_ src: String,
_ dst: String
) {
Bus.receive(
[src],
{ [weak self] _, v in self?.text.send(v) },
{ [weak self] _, v in self?.v.send(v) },
sub: &subscriptions
)

Bus.send(
dst,
text
.debounce(for: .seconds(0.2), scheduler: DispatchQueue.main)
.compactMap(formatId)
v
.debounce(for: .seconds(sec), scheduler: DispatchQueue.main)
.compactMap { (v: Src) in handler(v) }
.eraseToAnyPublisher(),
sub: &subscriptions
)

+ 1
- 0
Modules/MeetupIdX/src/MeetupId.K.swift View File

@@ -1,5 +1,6 @@
public extension MeetupId {
enum K {
static let finishLoading = "MeetupId.finishLoading"
static let isJoinAvailable = "MeetupId.isJoinAvailable"
static let isLoading = "MeetupId.isLoading"
static let join = "MeetupId.join"


+ 9
- 0
Modules/MeetupIdX/src/MeetupId.Shoulds.swift View File

@@ -2,6 +2,8 @@ import Foundation

public extension MeetupId {
static func shouldEnableJoin(_ c: MeetupIdContext) -> Bool? {
guard !c.isLoading.value else { return nil }

if
c.textUI.isRecent,
let sid = formatId(c.textUI.value)
@@ -12,6 +14,13 @@ public extension MeetupId {
if c.join {
return false
}
if
c.isLoading.isRecent,
!c.isLoading.value
{
return true
}
return nil
}


+ 10
- 4
Modules/MeetupIdX/src/MeetupId.V.swift View File

@@ -4,12 +4,14 @@ import SwiftUI

extension MeetupId {
public struct V: View {
@StateObject var fmt = MeetupId.Formatter(K.textUI, K.textApp)
let fmt = MeetupId.Debounce(5, formatId, K.textUI, K.textApp)
@StateObject var isJoinAvailable = Cord.Receive(K.isJoinAvailable, false)
@StateObject var isLoading = Cord.Receive(K.isLoading, false)
@StateObject var join = Cord.Button(K.join)
@StateObject var textField = Cord.TextField(K.textApp, K.textUI)
let pSEJ = Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable)
let procs: [Any] = [
Bus.Processor(shouldEnableJoin, K.M, K.isJoinAvailable),
]
public init() { }
@@ -17,8 +19,12 @@ extension MeetupId {
VStack(spacing: 8) {
HStack {
TextField("Binding-3", value: $textField.v, formatter: Cord.TextFieldValueOwner())
.disabled(isLoading.v)
.padding(8)
.border(Color.blue, width: 2)
.border(
!isLoading.v ? Color.black : Color.gray,
width: !isLoading.v ? 2 : 1
)
if isLoading.v {
ProgressView()
.padding(8)
@@ -30,7 +36,7 @@ extension MeetupId {
.padding(8)
.border(
isJoinAvailable.v ? Color.green : Color.gray,
width: isJoinAvailable.v ? 4 : 1
width: isJoinAvailable.v ? 2 : 1
)
}
.disabled(!isJoinAvailable.v)


+ 2
- 2
app/Podfile.lock View File

@@ -1,7 +1,7 @@
PODS:
- AELog (0.6.3)
- BusX (2023.12.28)
- CordX (2023.12.28):
- CordX (2023.12.29):
- BusX
- MeetupIdX (2023.12.28):
- AELog
@@ -34,7 +34,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AELog: f732b70f7a9d1b4c6a3676304192b3908f362133
BusX: fd22c04ad544d131e66315c1a33d87d85b19712e
CordX: 63515d366b217366b9562edcfef34630a7be1171
CordX: f8ba6a8db42f9f27142948b536b9b8272f9b977c
MeetupIdX: b214163e32acffd0a5283062e9d69aaf5a5b66e6
MPAKX: dc592434f55edf34709f6e4f37c9ec90dcd95185



Loading…
Cancel
Save