Михаил Капелько 11 months ago
parent
commit
a77e1c82b4
4 changed files with 28 additions and 22 deletions
  1. +0
    -1
      src/App.swift
  2. +21
    -2
      src/Bus.swift
  3. +5
    -17
      src/MeetupId.swift
  4. +2
    -2
      src/VM.swift

+ 0
- 1
src/App.swift View File

@@ -3,7 +3,6 @@ import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
let fmt = MeetupId.MeetupIdFormatter()
var window: UIWindow?

func application(


+ 21
- 2
src/Bus.swift View File

@@ -85,9 +85,9 @@ public extension Bus {
public extension Bus {
static func processSync<Src, Dst>(
_ subscriptions: inout Set<AnyCancellable>,
_ handler: @escaping ((Src) -> Dst?),
_ keyIn: String,
_ keyOut: String,
_ handler: @escaping ((Src) -> Dst?)
_ keyOut: String
) {
Service.singleton.broadcaster
.compactMap {
@@ -102,4 +102,23 @@ public extension Bus {
.sink { vOut in Service.singleton.send(keyOut, vOut) }
.store(in: &subscriptions)
}

static func processSyncG<Src, Dst>(
_ handler: @escaping ((Src) -> Dst?),
_ keyIn: String,
_ keyOut: String
) {
Service.singleton.broadcaster
.compactMap {
guard
$0.key == keyIn,
let vIn = $0.value as? Src
else {
return nil
}
return handler(vIn)
}
.sink { vOut in Service.singleton.send(keyOut, vOut) }
.store(in: &Service.singleton.subscriptions)
}
}

+ 5
- 17
src/MeetupId.swift View File

@@ -2,7 +2,7 @@ import Combine
import Foundation

enum MeetupId {
enum Keys: String, RawRepresentable {
enum K: String, RawRepresentable {
case meetupIdTextApp
case meetupIdTextUI
}
@@ -24,21 +24,9 @@ enum MeetupId {
return r
}

final class MeetupIdFormatter {
var subscriptions = Set<AnyCancellable>()
Bus.processSyncG(
shouldFormat, K.meetupIdTextUI.rawValue, K.meetupIdTextApp.rawValue
)
}

deinit {
/**/print("ИГР MeetupIF.DEinit")
}

init() {
Bus.processSync(
&subscriptions,
Keys.meetupIdTextUI.rawValue,
Keys.meetupIdTextApp.rawValue,
shouldFormat
)
/**/print("ИГР MeetupIF.init")
}
}
}

+ 2
- 2
src/VM.swift View File

@@ -9,7 +9,7 @@ final class VM: ObservableObject {
init() {
Bus.sendSync(
&subscriptions,
MeetupId.Keys.meetupIdTextUI.rawValue,
MeetupId.K.meetupIdTextUI.rawValue,
$text
// Исключаем конфликты от UI и App путём игнорирования спама.
.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main)
@@ -22,7 +22,7 @@ final class VM: ObservableObject {

Bus.receiveAsync(
&subscriptions,
[MeetupId.Keys.meetupIdTextApp.rawValue],
[MeetupId.K.meetupIdTextApp.rawValue],
{ [weak self] (_, v: String) in self?.text = "a:\(v)" }
)
}


Loading…
Cancel
Save