Михаил Капелько 10 months ago
parent
commit
95be65e07a
6 changed files with 32 additions and 25 deletions
  1. +0
    -3
      Modules/MeetupIdX/MeetupId.yml
  2. +1
    -5
      Modules/MeetupIdX/src/MeetupId.Aux.swift
  3. +29
    -0
      Modules/MeetupIdX/src/MeetupId.Formatter.swift
  4. +0
    -16
      Modules/MeetupIdX/src/MeetupId.Generated.swift
  5. +1
    -1
      Modules/MeetupIdX/src/MeetupId.Shoulds.swift
  6. +1
    -0
      Modules/MeetupIdX/src/MeetupId.V.swift

+ 0
- 3
Modules/MeetupIdX/MeetupId.yml 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]

Modules/MeetupIdX/src/MeetupId.Onlys.swift → Modules/MeetupIdX/src/MeetupId.Aux.swift 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

+ 29
- 0
Modules/MeetupIdX/src/MeetupId.Formatter.swift 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
)
}
}
}

+ 0
- 16
Modules/MeetupIdX/src/MeetupId.Generated.swift 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,


+ 1
- 1
Modules/MeetupIdX/src/MeetupId.Shoulds.swift 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
}


+ 1
- 0
Modules/MeetupIdX/src/MeetupId.V.swift 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)


Loading…
Cancel
Save