diff --git a/Modules/MeetupIdX/MeetupId.yml b/Modules/MeetupIdX/MeetupId.yml index 56f4e94..d2f6d5f 100644 --- a/Modules/MeetupIdX/MeetupId.yml +++ b/Modules/MeetupIdX/MeetupId.yml @@ -2,7 +2,6 @@ version: 2 model: join: [Bool, false] - textApp: [String, ""] textUI: [String, ""] service: @@ -10,10 +9,8 @@ service: busModel pipes: join: [toggle, K.join] - textApp: [recent, K.textApp] textUI: [recent, K.textUI] world: join: [ps] - textApp: [ps] textUI: [ps] diff --git a/Modules/MeetupIdX/src/MeetupId.Onlys.swift b/Modules/MeetupIdX/src/MeetupId.Aux.swift similarity index 79% rename from Modules/MeetupIdX/src/MeetupId.Onlys.swift rename to Modules/MeetupIdX/src/MeetupId.Aux.swift index 633fe59..884cfa9 100644 --- a/Modules/MeetupIdX/src/MeetupId.Onlys.swift +++ b/Modules/MeetupIdX/src/MeetupId.Aux.swift @@ -1,11 +1,7 @@ import Foundation public extension MeetupId { - static func onlyAllowJoin(_ s: String) -> Bool? { - s.hasPrefix("123") - } - - static func onlyFormat(_ s: String) -> String? { + static func formatId(_ s: String) -> String? { let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 } var r = "" var i = 0 diff --git a/Modules/MeetupIdX/src/MeetupId.Formatter.swift b/Modules/MeetupIdX/src/MeetupId.Formatter.swift new file mode 100644 index 0000000..481fb66 --- /dev/null +++ b/Modules/MeetupIdX/src/MeetupId.Formatter.swift @@ -0,0 +1,29 @@ +import BusX +import Combine + +extension MeetupId { + final class Formatter: ObservableObject { + let text = PassthroughSubject() + var subscriptions = [AnyCancellable]() + + init( + _ src: String, + _ dst: String + ) { + Bus.receive( + [src], + { [weak self] _, v in self?.text.send(v) }, + sub: &subscriptions + ) + + Bus.send( + dst, + text + .debounce(for: .seconds(0.2), scheduler: DispatchQueue.main) + .compactMap(formatId) + .eraseToAnyPublisher(), + sub: &subscriptions + ) + } + } +} diff --git a/Modules/MeetupIdX/src/MeetupId.Generated.swift b/Modules/MeetupIdX/src/MeetupId.Generated.swift index 1b80785..d6d27a4 100644 --- a/Modules/MeetupIdX/src/MeetupId.Generated.swift +++ b/Modules/MeetupIdX/src/MeetupId.Generated.swift @@ -13,7 +13,6 @@ import UIKit public protocol MeetupIdContext { var join: Bool { get } - var textApp: MPAK.Recent { get } var textUI: MPAK.Recent { get } } @@ -36,7 +35,6 @@ extension MeetupId { public struct Model: MeetupIdContext { public var join: Bool = false - public var textApp: MPAK.Recent = .init("") public var textUI: MPAK.Recent = .init("") } @@ -60,7 +58,6 @@ extension MeetupId { public struct World { let join = PassthroughSubject() - let textApp = PassthroughSubject() let textUI = PassthroughSubject() public init( @@ -103,19 +100,6 @@ extension MeetupId { - ctrl.pipeValue( - dbg: "textA", - sub: nil, - Bus.events.compactMap { Bus.convertKeyValue(K.textApp, $0) }.map { (k: String, v: String) in v }.eraseToAnyPublisher(), - { - $0.textApp.value = $1 - $0.textApp.isRecent = true - }, - { m, _ in m.textApp.isRecent = false } - ) - - - ctrl.pipeValue( dbg: "textUI", sub: nil, diff --git a/Modules/MeetupIdX/src/MeetupId.Shoulds.swift b/Modules/MeetupIdX/src/MeetupId.Shoulds.swift index 9ccfc51..90afc03 100644 --- a/Modules/MeetupIdX/src/MeetupId.Shoulds.swift +++ b/Modules/MeetupIdX/src/MeetupId.Shoulds.swift @@ -4,7 +4,7 @@ public extension MeetupId { static func shouldEnableJoin(_ c: MeetupIdContext) -> Bool? { if c.textUI.isRecent, - let sid = onlyFormat(c.textUI.value) + let sid = formatId(c.textUI.value) { return sid.count > 2 } diff --git a/Modules/MeetupIdX/src/MeetupId.V.swift b/Modules/MeetupIdX/src/MeetupId.V.swift index d5d16c4..66ec048 100644 --- a/Modules/MeetupIdX/src/MeetupId.V.swift +++ b/Modules/MeetupIdX/src/MeetupId.V.swift @@ -4,6 +4,7 @@ import SwiftUI extension MeetupId { public struct V: View { + @StateObject var fmt = MeetupId.Formatter(K.textUI, K.textApp) @StateObject var isJA = Cord.Receive(K.isJoinAvailable, false) @StateObject var join = Cord.Button(K.join) @StateObject var txtF = Cord.TextField(K.textApp, K.textUI)