d
This commit is contained in:
@@ -2,7 +2,6 @@ version: 2
|
|||||||
|
|
||||||
model:
|
model:
|
||||||
join: [Bool, false]
|
join: [Bool, false]
|
||||||
textApp: [String, ""]
|
|
||||||
textUI: [String, ""]
|
textUI: [String, ""]
|
||||||
|
|
||||||
service:
|
service:
|
||||||
@@ -10,10 +9,8 @@ service:
|
|||||||
busModel
|
busModel
|
||||||
pipes:
|
pipes:
|
||||||
join: [toggle, K.join]
|
join: [toggle, K.join]
|
||||||
textApp: [recent, K.textApp]
|
|
||||||
textUI: [recent, K.textUI]
|
textUI: [recent, K.textUI]
|
||||||
|
|
||||||
world:
|
world:
|
||||||
join: [ps]
|
join: [ps]
|
||||||
textApp: [ps]
|
|
||||||
textUI: [ps]
|
textUI: [ps]
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public extension MeetupId {
|
public extension MeetupId {
|
||||||
static func onlyAllowJoin(_ s: String) -> Bool? {
|
static func formatId(_ s: String) -> String? {
|
||||||
s.hasPrefix("123")
|
|
||||||
}
|
|
||||||
|
|
||||||
static func onlyFormat(_ s: String) -> String? {
|
|
||||||
let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 }
|
let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 }
|
||||||
var r = ""
|
var r = ""
|
||||||
var i = 0
|
var i = 0
|
||||||
29
Modules/MeetupIdX/src/MeetupId.Formatter.swift
Normal file
29
Modules/MeetupIdX/src/MeetupId.Formatter.swift
Normal 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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,6 @@ import UIKit
|
|||||||
|
|
||||||
public protocol MeetupIdContext {
|
public protocol MeetupIdContext {
|
||||||
var join: Bool { get }
|
var join: Bool { get }
|
||||||
var textApp: MPAK.Recent<String> { get }
|
|
||||||
var textUI: MPAK.Recent<String> { get }
|
var textUI: MPAK.Recent<String> { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ extension MeetupId {
|
|||||||
|
|
||||||
public struct Model: MeetupIdContext {
|
public struct Model: MeetupIdContext {
|
||||||
public var join: Bool = false
|
public var join: Bool = false
|
||||||
public var textApp: MPAK.Recent<String> = .init("")
|
|
||||||
public var textUI: MPAK.Recent<String> = .init("")
|
public var textUI: MPAK.Recent<String> = .init("")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +58,6 @@ extension MeetupId {
|
|||||||
|
|
||||||
public struct World {
|
public struct World {
|
||||||
let join = PassthroughSubject<Void, Never>()
|
let join = PassthroughSubject<Void, Never>()
|
||||||
let textApp = PassthroughSubject<String, Never>()
|
|
||||||
let textUI = PassthroughSubject<String, Never>()
|
let textUI = PassthroughSubject<String, Never>()
|
||||||
|
|
||||||
public init(
|
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(
|
ctrl.pipeValue(
|
||||||
dbg: "textUI",
|
dbg: "textUI",
|
||||||
sub: nil,
|
sub: nil,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ public extension MeetupId {
|
|||||||
static func shouldEnableJoin(_ c: MeetupIdContext) -> Bool? {
|
static func shouldEnableJoin(_ c: MeetupIdContext) -> Bool? {
|
||||||
if
|
if
|
||||||
c.textUI.isRecent,
|
c.textUI.isRecent,
|
||||||
let sid = onlyFormat(c.textUI.value)
|
let sid = formatId(c.textUI.value)
|
||||||
{
|
{
|
||||||
return sid.count > 2
|
return sid.count > 2
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import SwiftUI
|
|||||||
|
|
||||||
extension MeetupId {
|
extension MeetupId {
|
||||||
public struct V: View {
|
public struct V: View {
|
||||||
|
@StateObject var fmt = MeetupId.Formatter(K.textUI, K.textApp)
|
||||||
@StateObject var isJA = Cord.Receive(K.isJoinAvailable, false)
|
@StateObject var isJA = Cord.Receive(K.isJoinAvailable, false)
|
||||||
@StateObject var join = Cord.Button(K.join)
|
@StateObject var join = Cord.Button(K.join)
|
||||||
@StateObject var txtF = Cord.TextField(K.textApp, K.textUI)
|
@StateObject var txtF = Cord.TextField(K.textApp, K.textUI)
|
||||||
|
|||||||
Reference in New Issue
Block a user