From 1779eb3efec5615b781f0ae04a3d3cc01265bbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 15 Jan 2024 18:41:58 +0300 Subject: [PATCH] d --- Modules/BusX | 1 + Modules/BusX/Bus/src/Bus.Async.swift | 31 ---------- Modules/BusX/Bus/src/Bus.Aux.swift | 29 ---------- Modules/BusX/Bus/src/Bus.Debounce.swift | 31 ---------- Modules/BusX/Bus/src/Bus.Delay.swift | 31 ---------- Modules/BusX/Bus/src/Bus.Sync.swift | 29 ---------- Modules/BusX/Bus/src/Bus.swift | 56 ------------------- Modules/BusX/BusUI/src/BusUI.Aux.swift | 9 --- Modules/BusX/BusUI/src/BusUI.Button.swift | 16 ------ Modules/BusX/BusUI/src/BusUI.TextField.swift | 29 ---------- .../BusUI/src/BusUI.TextFieldSource.swift | 22 -------- Modules/BusX/BusUI/src/BusUI.Value.swift | 20 ------- Modules/BusX/BusUI/src/BusUI.swift | 1 - Modules/BusX/BusX.podspec | 14 ----- app/Podfile.lock | 4 +- 15 files changed, 3 insertions(+), 320 deletions(-) create mode 120000 Modules/BusX delete mode 100644 Modules/BusX/Bus/src/Bus.Async.swift delete mode 100644 Modules/BusX/Bus/src/Bus.Aux.swift delete mode 100644 Modules/BusX/Bus/src/Bus.Debounce.swift delete mode 100644 Modules/BusX/Bus/src/Bus.Delay.swift delete mode 100644 Modules/BusX/Bus/src/Bus.Sync.swift delete mode 100644 Modules/BusX/Bus/src/Bus.swift delete mode 100644 Modules/BusX/BusUI/src/BusUI.Aux.swift delete mode 100644 Modules/BusX/BusUI/src/BusUI.Button.swift delete mode 100644 Modules/BusX/BusUI/src/BusUI.TextField.swift delete mode 100644 Modules/BusX/BusUI/src/BusUI.TextFieldSource.swift delete mode 100644 Modules/BusX/BusUI/src/BusUI.Value.swift delete mode 100644 Modules/BusX/BusUI/src/BusUI.swift delete mode 100644 Modules/BusX/BusX.podspec diff --git a/Modules/BusX b/Modules/BusX new file mode 120000 index 0000000..f83fa56 --- /dev/null +++ b/Modules/BusX @@ -0,0 +1 @@ +../../../../u/Modules/BusX \ No newline at end of file diff --git a/Modules/BusX/Bus/src/Bus.Async.swift b/Modules/BusX/Bus/src/Bus.Async.swift deleted file mode 100644 index 111df2b..0000000 --- a/Modules/BusX/Bus/src/Bus.Async.swift +++ /dev/null @@ -1,31 +0,0 @@ -import Combine - -public extension Bus { - final class Async { - let v = PassthroughSubject() - var subscriptions = [AnyCancellable]() - - public init( - _ handler: @escaping ((Src) -> Dst?), - _ src: String, - _ dst: String - ) { - // Вход. - Bus.receiveSync( - [src], - { [weak self] _, v in self?.v.send(v) }, - &subscriptions - ) - // Выход. - Bus.sendSync( - dst, - v - .compactMap { (v: Src) in handler(v) } - // Асинхронно. - .receive(on: DispatchQueue.main) - .eraseToAnyPublisher(), - &subscriptions - ) - } - } -} diff --git a/Modules/BusX/Bus/src/Bus.Aux.swift b/Modules/BusX/Bus/src/Bus.Aux.swift deleted file mode 100644 index 01c0d98..0000000 --- a/Modules/BusX/Bus/src/Bus.Aux.swift +++ /dev/null @@ -1,29 +0,0 @@ -public extension Bus { - /// Пропускаем далее единственный ключ. - static func convertKeyValue( - _ key: String, - _ v: (key: String, value: Any) - ) -> (String, T)? { - guard - key == v.key, - let value = v.value as? T - else { - return nil - } - return (key, value) - } - - /// Пропускаем далее множество ключей. - static func convertKeyValue( - _ keys: Set, - _ v: (key: String, value: Any) - ) -> (String, T)? { - guard - keys.contains(v.key), - let value = v.value as? T - else { - return nil - } - return (v.key, value) - } -} diff --git a/Modules/BusX/Bus/src/Bus.Debounce.swift b/Modules/BusX/Bus/src/Bus.Debounce.swift deleted file mode 100644 index 8cd0030..0000000 --- a/Modules/BusX/Bus/src/Bus.Debounce.swift +++ /dev/null @@ -1,31 +0,0 @@ -import Combine - -public extension Bus { - final class Debounce { - let v = PassthroughSubject() - var subscriptions = [AnyCancellable]() - - public init( - _ handler: @escaping ((Src) -> Dst?), - _ sec: Double, - _ src: String, - _ dst: String - ) { - // Вход. - Bus.receiveSync( - [src], - { [weak self] _, v in self?.v.send(v) }, - &subscriptions - ) - // Выход. - Bus.sendSync( - dst, - v - .debounce(for: .seconds(sec), scheduler: DispatchQueue.main) - .compactMap { (v: Src) in handler(v) } - .eraseToAnyPublisher(), - &subscriptions - ) - } - } -} diff --git a/Modules/BusX/Bus/src/Bus.Delay.swift b/Modules/BusX/Bus/src/Bus.Delay.swift deleted file mode 100644 index cf37370..0000000 --- a/Modules/BusX/Bus/src/Bus.Delay.swift +++ /dev/null @@ -1,31 +0,0 @@ -import Combine - -public extension Bus { - final class Delay { - let v = PassthroughSubject() - var subscriptions = [AnyCancellable]() - - public init( - _ handler: @escaping ((Src) -> Dst?), - _ sec: Double, - _ src: String, - _ dst: String - ) { - // Вход. - Bus.receiveSync( - [src], - { [weak self] _, v in self?.v.send(v) }, - &subscriptions - ) - // Выход. - Bus.sendSync( - dst, - v - .delay(for: .seconds(sec), scheduler: DispatchQueue.main) - .compactMap { (v: Src) in handler(v) } - .eraseToAnyPublisher(), - &subscriptions - ) - } - } -} diff --git a/Modules/BusX/Bus/src/Bus.Sync.swift b/Modules/BusX/Bus/src/Bus.Sync.swift deleted file mode 100644 index 4e5b317..0000000 --- a/Modules/BusX/Bus/src/Bus.Sync.swift +++ /dev/null @@ -1,29 +0,0 @@ -import Combine - -public extension Bus { - final class Sync { - let v = PassthroughSubject() - var subscriptions = [AnyCancellable]() - - public init( - _ handler: @escaping ((Src) -> Dst?), - _ src: String, - _ dst: String - ) { - // Вход. - Bus.receiveSync( - [src], - { [weak self] _, v in self?.v.send(v) }, - &subscriptions - ) - // Выход. - Bus.sendSync( - dst, - v - .compactMap { (v: Src) in handler(v) } - .eraseToAnyPublisher(), - &subscriptions - ) - } - } -} diff --git a/Modules/BusX/Bus/src/Bus.swift b/Modules/BusX/Bus/src/Bus.swift deleted file mode 100644 index 33ae467..0000000 --- a/Modules/BusX/Bus/src/Bus.swift +++ /dev/null @@ -1,56 +0,0 @@ -import Combine -import Foundation - -public enum Bus { - private static let e = PassthroughSubject<(key: String, value: Any), Never>() - - public static var events: AnyPublisher<(key: String, value: Any), Never> { - e.eraseToAnyPublisher() - } -} - -public extension Bus { - /// Асинхронно обрабатываем входящие события из шины. - static func receiveAsync( - _ keys: Set, - _ handler: @escaping ((String, T) -> Void), - _ subscriptions: inout [AnyCancellable] - ) { - e - .compactMap { convertKeyValue(keys, $0) } - .receive(on: DispatchQueue.main) - .sink { v in handler(v.0, v.1) } - .store(in: &subscriptions) - } - - /// Синхронно обрабатываем входящие события из шины. - static func receiveSync( - _ keys: Set, - _ handler: @escaping ((String, T) -> Void), - _ subscriptions: inout [AnyCancellable] - ) { - e - .compactMap { convertKeyValue(keys, $0) } - .sink { v in handler(v.0, v.1) } - .store(in: &subscriptions) - } - - /// Синхронно отправляем события из узла в шину. - /// - /// Для асинхронной отправки достаточно добавить оператор `receive(on:)` - /// в цепочке параметра `node` - static func sendSync( - _ key: String, - _ node: AnyPublisher, - _ subscriptions: inout [AnyCancellable] - ) { - node - .sink { v in e.send((key, v)) } - .store(in: &subscriptions) - } - - /// Единоразово синхронно отправляем событие в шину. - static func send(_ key: String, _ value: Any) { - e.send((key, value)) - } -} diff --git a/Modules/BusX/BusUI/src/BusUI.Aux.swift b/Modules/BusX/BusUI/src/BusUI.Aux.swift deleted file mode 100644 index 72d3261..0000000 --- a/Modules/BusX/BusUI/src/BusUI.Aux.swift +++ /dev/null @@ -1,9 +0,0 @@ -extension BusUI { - /// Пропускаем лишь значения от UI - /// - /// - Returns: Значение без префиксов "a:"/"u:" - static func onlyUIText(_ s: String) -> String? { - guard s.hasPrefix("u:") else { return nil } - return String(s.dropFirst(2)) - } -} diff --git a/Modules/BusX/BusUI/src/BusUI.Button.swift b/Modules/BusX/BusUI/src/BusUI.Button.swift deleted file mode 100644 index 44166aa..0000000 --- a/Modules/BusX/BusUI/src/BusUI.Button.swift +++ /dev/null @@ -1,16 +0,0 @@ -import Combine - -extension BusUI { - public final class Button: ObservableObject { - public let v = PassthroughSubject() - var subscriptions = [AnyCancellable]() - - public init(_ key: String) { - Bus.sendSync( - key, - v.map { true }.eraseToAnyPublisher(), - &subscriptions - ) - } - } -} diff --git a/Modules/BusX/BusUI/src/BusUI.TextField.swift b/Modules/BusX/BusUI/src/BusUI.TextField.swift deleted file mode 100644 index c48ffd7..0000000 --- a/Modules/BusX/BusUI/src/BusUI.TextField.swift +++ /dev/null @@ -1,29 +0,0 @@ -import Combine -import SwiftUI - -extension BusUI { - public final class TextField: ObservableObject { - @Published public var v = "a:" - var subscriptions = [AnyCancellable]() - - public init( - _ textApp: String, - _ textUI: String - ) { - Bus.sendSync( - textUI, - $v - .removeDuplicates() - .compactMap(onlyUIText) - .eraseToAnyPublisher(), - &subscriptions - ) - - Bus.receiveSync( - [textApp], - { [weak self] (_, v: String) in self?.v = "a:\(v)" }, - &subscriptions - ) - } - } -} diff --git a/Modules/BusX/BusUI/src/BusUI.TextFieldSource.swift b/Modules/BusX/BusUI/src/BusUI.TextFieldSource.swift deleted file mode 100644 index 80230a0..0000000 --- a/Modules/BusX/BusUI/src/BusUI.TextFieldSource.swift +++ /dev/null @@ -1,22 +0,0 @@ -import Foundation - -extension BusUI { - public final class TextFieldSource: Formatter { - /// Выдаём для отображения очищенную от источника строку. - public override func string(for obj: Any?) -> String? { - guard let str = obj as? String else { return nil } - return String(str.dropFirst(2)) - } - - /// Выдаём для использования кодом строку с указанием источника - /// в виде пользователя `u:` - public override func getObjectValue( - _ obj: AutoreleasingUnsafeMutablePointer?, - for string: String, - errorDescription error: AutoreleasingUnsafeMutablePointer? - ) -> Bool { - obj?.pointee = "u:\(string)" as AnyObject - return true - } - } -} diff --git a/Modules/BusX/BusUI/src/BusUI.Value.swift b/Modules/BusX/BusUI/src/BusUI.Value.swift deleted file mode 100644 index 558e4af..0000000 --- a/Modules/BusX/BusUI/src/BusUI.Value.swift +++ /dev/null @@ -1,20 +0,0 @@ -import Combine - -extension BusUI { - public final class Value: ObservableObject { - @Published public var v: T - var subscriptions = [AnyCancellable]() - - public init( - _ key: String, - _ defaultValue: T - ) { - v = defaultValue - Bus.receiveSync( - [key], - { [weak self] (_, v: T) in self?.v = v }, - &subscriptions - ) - } - } -} diff --git a/Modules/BusX/BusUI/src/BusUI.swift b/Modules/BusX/BusUI/src/BusUI.swift deleted file mode 100644 index 9c2ef3b..0000000 --- a/Modules/BusX/BusUI/src/BusUI.swift +++ /dev/null @@ -1 +0,0 @@ -public enum BusUI { } diff --git a/Modules/BusX/BusX.podspec b/Modules/BusX/BusX.podspec deleted file mode 100644 index 62b1ee1..0000000 --- a/Modules/BusX/BusX.podspec +++ /dev/null @@ -1,14 +0,0 @@ -Pod::Spec.new do |s| - -s.name = 'BusX' -s.version = '2023.12.30' -s.license = 'IVCS' -s.summary = 'Шина общения элементов приложения' -s.homepage = 'IVCS' -s.author = 'IVCS' -s.source = { :git => 'https://fake.com/FAKE.git', :tag => s.version } -s.source_files = '**/**/*.swift' -s.swift_version = '5.2' -s.ios.deployment_target = '14.0' - -end diff --git a/app/Podfile.lock b/app/Podfile.lock index 2be7d2a..73b5162 100644 --- a/app/Podfile.lock +++ b/app/Podfile.lock @@ -1,6 +1,6 @@ PODS: - AELog (0.6.3) - - BusX (2023.12.30) + - BusX (2024.01.15) - MeetupIdX (2023.12.31): - AELog - BusX @@ -27,7 +27,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: AELog: f732b70f7a9d1b4c6a3676304192b3908f362133 - BusX: d11e857e9cb762f649ee9f88fd5a4f8fbf5bf96b + BusX: 1db5cf8652f7b206af468cc115cab3326efd1ced MeetupIdX: 2fa9fb27717aa8878ff495c1abe960c96e524308 MPAKX: dc592434f55edf34709f6e4f37c9ec90dcd95185