@@ -3,7 +3,6 @@ import UIKit | |||||
@UIApplicationMain | @UIApplicationMain | ||||
class AppDelegate: UIResponder, UIApplicationDelegate | class AppDelegate: UIResponder, UIApplicationDelegate | ||||
{ | { | ||||
let fmt = MeetupId.MeetupIdFormatter() | |||||
var window: UIWindow? | var window: UIWindow? | ||||
func application( | func application( | ||||
@@ -85,9 +85,9 @@ public extension Bus { | |||||
public extension Bus { | public extension Bus { | ||||
static func processSync<Src, Dst>( | static func processSync<Src, Dst>( | ||||
_ subscriptions: inout Set<AnyCancellable>, | _ subscriptions: inout Set<AnyCancellable>, | ||||
_ handler: @escaping ((Src) -> Dst?), | |||||
_ keyIn: String, | _ keyIn: String, | ||||
_ keyOut: String, | |||||
_ handler: @escaping ((Src) -> Dst?) | |||||
_ keyOut: String | |||||
) { | ) { | ||||
Service.singleton.broadcaster | Service.singleton.broadcaster | ||||
.compactMap { | .compactMap { | ||||
@@ -102,4 +102,23 @@ public extension Bus { | |||||
.sink { vOut in Service.singleton.send(keyOut, vOut) } | .sink { vOut in Service.singleton.send(keyOut, vOut) } | ||||
.store(in: &subscriptions) | .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 | import Foundation | ||||
enum MeetupId { | enum MeetupId { | ||||
enum Keys: String, RawRepresentable { | |||||
enum K: String, RawRepresentable { | |||||
case meetupIdTextApp | case meetupIdTextApp | ||||
case meetupIdTextUI | case meetupIdTextUI | ||||
} | } | ||||
@@ -24,21 +24,9 @@ enum MeetupId { | |||||
return r | 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") | |||||
} | |||||
} | |||||
} |
@@ -9,7 +9,7 @@ final class VM: ObservableObject { | |||||
init() { | init() { | ||||
Bus.sendSync( | Bus.sendSync( | ||||
&subscriptions, | &subscriptions, | ||||
MeetupId.Keys.meetupIdTextUI.rawValue, | |||||
MeetupId.K.meetupIdTextUI.rawValue, | |||||
$text | $text | ||||
// Исключаем конфликты от UI и App путём игнорирования спама. | // Исключаем конфликты от UI и App путём игнорирования спама. | ||||
.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main) | .debounce(for: .seconds(0.3), scheduler: DispatchQueue.main) | ||||
@@ -22,7 +22,7 @@ final class VM: ObservableObject { | |||||
Bus.receiveAsync( | Bus.receiveAsync( | ||||
&subscriptions, | &subscriptions, | ||||
[MeetupId.Keys.meetupIdTextApp.rawValue], | |||||
[MeetupId.K.meetupIdTextApp.rawValue], | |||||
{ [weak self] (_, v: String) in self?.text = "a:\(v)" } | { [weak self] (_, v: String) in self?.text = "a:\(v)" } | ||||
) | ) | ||||
} | } | ||||