d
This commit is contained in:
@@ -3,7 +3,6 @@ import UIKit
|
|||||||
@UIApplicationMain
|
@UIApplicationMain
|
||||||
class AppDelegate: UIResponder, UIApplicationDelegate
|
class AppDelegate: UIResponder, UIApplicationDelegate
|
||||||
{
|
{
|
||||||
let bus = Bus.Service()
|
|
||||||
let fmt = MeetupId.MeetupIdFormatter()
|
let fmt = MeetupId.MeetupIdFormatter()
|
||||||
var window: UIWindow?
|
var window: UIWindow?
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,13 @@
|
|||||||
import Combine
|
import Combine
|
||||||
import SwiftUI
|
import Foundation
|
||||||
|
|
||||||
public enum Bus { }
|
public enum Bus { }
|
||||||
|
|
||||||
extension Bus {
|
extension Bus {
|
||||||
public final class Service {
|
final class Service {
|
||||||
static private(set) weak var singleton: Service?
|
static let singleton = Service()
|
||||||
let broadcaster = PassthroughSubject<(key: String, value: Any), Never>()
|
let broadcaster = PassthroughSubject<(key: String, value: Any), Never>()
|
||||||
|
var subscriptions = Set<AnyCancellable>()
|
||||||
deinit {
|
|
||||||
Self.singleton = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
public init() {
|
|
||||||
Self.singleton = self
|
|
||||||
}
|
|
||||||
|
|
||||||
func send(_ key: String, _ value: Any) {
|
func send(_ key: String, _ value: Any) {
|
||||||
/**/print("ИГР BusS.send key/value: '\(key)'/'\(value)'")
|
/**/print("ИГР BusS.send key/value: '\(key)'/'\(value)'")
|
||||||
@@ -29,7 +22,7 @@ public extension Bus {
|
|||||||
_ keys: Set<String>,
|
_ keys: Set<String>,
|
||||||
_ handler: @escaping ((String, T) -> Void)
|
_ handler: @escaping ((String, T) -> Void)
|
||||||
) {
|
) {
|
||||||
Service.singleton?.broadcaster
|
Service.singleton.broadcaster
|
||||||
.compactMap { v -> (String, T)? in
|
.compactMap { v -> (String, T)? in
|
||||||
guard
|
guard
|
||||||
keys.contains(v.key),
|
keys.contains(v.key),
|
||||||
@@ -49,7 +42,7 @@ public extension Bus {
|
|||||||
_ keys: Set<String>,
|
_ keys: Set<String>,
|
||||||
_ handler: @escaping ((String, T) -> Void)
|
_ handler: @escaping ((String, T) -> Void)
|
||||||
) {
|
) {
|
||||||
Service.singleton?.broadcaster
|
Service.singleton.broadcaster
|
||||||
.compactMap { v -> (String, T)? in
|
.compactMap { v -> (String, T)? in
|
||||||
guard
|
guard
|
||||||
keys.contains(v.key),
|
keys.contains(v.key),
|
||||||
@@ -70,7 +63,7 @@ public extension Bus {
|
|||||||
) {
|
) {
|
||||||
node
|
node
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { v in Service.singleton?.send(key, v) }
|
.sink { v in Service.singleton.send(key, v) }
|
||||||
.store(in: &subscriptions)
|
.store(in: &subscriptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,12 +73,12 @@ public extension Bus {
|
|||||||
_ node: AnyPublisher<T, Never>
|
_ node: AnyPublisher<T, Never>
|
||||||
) {
|
) {
|
||||||
node
|
node
|
||||||
.sink { v in Service.singleton?.send(key, v) }
|
.sink { v in Service.singleton.send(key, v) }
|
||||||
.store(in: &subscriptions)
|
.store(in: &subscriptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func sendOnce(_ key: String, _ value: Any) {
|
static func sendOnce(_ key: String, _ value: Any) {
|
||||||
Service.singleton?.send(key, value)
|
Service.singleton.send(key, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +89,7 @@ public extension Bus {
|
|||||||
_ keyOut: String,
|
_ keyOut: String,
|
||||||
_ handler: @escaping ((Src) -> Dst?)
|
_ handler: @escaping ((Src) -> Dst?)
|
||||||
) {
|
) {
|
||||||
Service.singleton?.broadcaster
|
Service.singleton.broadcaster
|
||||||
.compactMap {
|
.compactMap {
|
||||||
guard
|
guard
|
||||||
$0.key == keyIn,
|
$0.key == keyIn,
|
||||||
@@ -106,7 +99,7 @@ public extension Bus {
|
|||||||
}
|
}
|
||||||
return handler(vIn)
|
return handler(vIn)
|
||||||
}
|
}
|
||||||
.sink { vOut in Service.singleton?.send(keyOut, vOut) }
|
.sink { vOut in Service.singleton.send(keyOut, vOut) }
|
||||||
.store(in: &subscriptions)
|
.store(in: &subscriptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user