d
This commit is contained in:
@@ -3,7 +3,6 @@ import UIKit
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate
|
||||
{
|
||||
let fmt = MeetupId.MeetupIdFormatter()
|
||||
var window: UIWindow?
|
||||
|
||||
func application(
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>()
|
||||
|
||||
deinit {
|
||||
/**/print("ИГР MeetupIF.DEinit")
|
||||
}
|
||||
|
||||
init() {
|
||||
Bus.processSync(
|
||||
&subscriptions,
|
||||
Keys.meetupIdTextUI.rawValue,
|
||||
Keys.meetupIdTextApp.rawValue,
|
||||
shouldFormat
|
||||
Bus.processSyncG(
|
||||
shouldFormat, K.meetupIdTextUI.rawValue, K.meetupIdTextApp.rawValue
|
||||
)
|
||||
/**/print("ИГР MeetupIF.init")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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)" }
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user