diff --git a/Modules/BusX/Bus/src/Bus.swift b/Modules/BusX/Bus/src/Bus.swift index 90c9d85..02798de 100644 --- a/Modules/BusX/Bus/src/Bus.swift +++ b/Modules/BusX/Bus/src/Bus.swift @@ -1,7 +1,9 @@ import Combine import Foundation -public enum Bus { } +public enum Bus { + static let e = PassthroughSubject<(key: String, value: Any), Never>() +} public extension Bus { enum Option { @@ -9,19 +11,7 @@ public extension Bus { } static var events: AnyPublisher<(key: String, value: Any), Never> { - Service.singleton.events.eraseToAnyPublisher() - } -} - -extension Bus { - final class Service { - static let singleton = Service() - let events = PassthroughSubject<(key: String, value: Any), Never>() - var subscriptions = [AnyCancellable]() - - func send(_ key: String, _ value: Any) { - events.send((key, value)) - } + Self.e.eraseToAnyPublisher() } } @@ -34,7 +24,7 @@ private extension Bus { if let sub = sub { sub.pointee.append(subscription) } else { - Service.singleton.subscriptions.append(subscription) + Self.subscriptions.append(subscription) } } } @@ -51,7 +41,7 @@ public extension Bus { // Async. if isAsync { - subscription = Service.singleton.events + subscription = Self.events .compactMap { convertKeyValue(keys, $0) } .receive(on: DispatchQueue.main) .sink { v in handler(v.0, v.1) } @@ -59,7 +49,7 @@ public extension Bus { // Async. if !isAsync { - subscription = Service.singleton.events + subscription = Self.events .compactMap { convertKeyValue(keys, $0) } .sink { v in handler(v.0, v.1) } } @@ -80,20 +70,20 @@ public extension Bus { if isAsync { subscription = node .receive(on: DispatchQueue.main) - .sink { v in Service.singleton.send(key, v) } + .sink { v in Self.e.send(key, v) } } // Sync. if !isAsync { subscription = node - .sink { v in Service.singleton.send(key, v) } + .sink { v in Self.e.send(key, v) } } subscribe(subscription, sub) } static func send(_ key: String, _ value: Any) { - Service.singleton.send(key, value) + Self.e.send(key, value) } } @@ -110,17 +100,17 @@ public extension Bus { // Async. if isAsync { - subscription = Service.singleton.events + subscription = Self.events .compactMap { processKeysValue($0, keysIn, handler) } .receive(on: DispatchQueue.main) - .sink { vOut in Service.singleton.send(keyOut, vOut) } + .sink { vOut in Self.e.send(keyOut, vOut) } } // Sync. if !isAsync { - subscription = Service.singleton.events + subscription = Self.events .compactMap { processKeysValue($0, keysIn, handler) } - .sink { vOut in Service.singleton.send(keyOut, vOut) } + .sink { vOut in Self.e.send(keyOut, vOut) } } subscribe(subscription, sub) diff --git a/Modules/BusX/Package.swift b/Modules/BusX/Package.swift deleted file mode 100644 index 11f39c3..0000000 --- a/Modules/BusX/Package.swift +++ /dev/null @@ -1,25 +0,0 @@ -// swift-tools-version: 5.9 - -import PackageDescription - -let package = Package( - name: "BusX", - platforms: [.iOS(.v14)], - products: [ - .library( - name: "BusX", - type: .dynamic, - targets: ["BusX"] - ), - ], - dependencies: [ - ], - targets: [ - .target( - name: "BusX", - dependencies: [ - ], - path: "src" - ), - ] -)