This commit is contained in:
Михаил Капелько
2023-12-29 12:35:31 +03:00
parent 22a6dcfcc0
commit 95be65e07a
6 changed files with 32 additions and 25 deletions

View File

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

View File

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

View File

@@ -0,0 +1,29 @@
import BusX
import Combine
extension MeetupId {
final class Formatter: ObservableObject {
let text = PassthroughSubject<String, Never>()
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
)
}
}
}

View File

@@ -13,7 +13,6 @@ import UIKit
public protocol MeetupIdContext {
var join: Bool { get }
var textApp: MPAK.Recent<String> { get }
var textUI: MPAK.Recent<String> { get }
}
@@ -36,7 +35,6 @@ extension MeetupId {
public struct Model: MeetupIdContext {
public var join: Bool = false
public var textApp: MPAK.Recent<String> = .init("")
public var textUI: MPAK.Recent<String> = .init("")
}
@@ -60,7 +58,6 @@ extension MeetupId {
public struct World {
let join = PassthroughSubject<Void, Never>()
let textApp = PassthroughSubject<String, Never>()
let textUI = PassthroughSubject<String, Never>()
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,

View File

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

View File

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