@@ -45,12 +45,13 @@ public extension Bus { | |||||
_ subscriptions: inout [AnyCancellable] | _ subscriptions: inout [AnyCancellable] | ||||
) { | ) { | ||||
node | node | ||||
.sink { v in e.send((key, v)) } | |||||
.sink { v in send(key, v) } | |||||
.store(in: &subscriptions) | .store(in: &subscriptions) | ||||
} | } | ||||
/// Единоразово синхронно отправляем событие в шину. | /// Единоразово синхронно отправляем событие в шину. | ||||
static func send(_ key: String, _ value: Any) { | static func send(_ key: String, _ value: Any) { | ||||
/**/print("ИГР Bus.send k/v: '\(key)'/'\(value)'") | |||||
e.send((key, value)) | e.send((key, value)) | ||||
} | } | ||||
} | } |
@@ -5,9 +5,17 @@ extension BusUI { | |||||
public let v = PassthroughSubject<Void, Never>() | public let v = PassthroughSubject<Void, Never>() | ||||
var subscriptions = [AnyCancellable]() | var subscriptions = [AnyCancellable]() | ||||
public init(_ key: String) { | |||||
public init( | |||||
_ key: String, | |||||
_ id: String? = nil | |||||
) { | |||||
var k = key | |||||
if let id { | |||||
k = k + id | |||||
} | |||||
Bus.sendSync( | Bus.sendSync( | ||||
key, | |||||
k, | |||||
v.map { true }.eraseToAnyPublisher(), | v.map { true }.eraseToAnyPublisher(), | ||||
&subscriptions | &subscriptions | ||||
) | ) | ||||
@@ -8,10 +8,18 @@ extension BusUI { | |||||
public init( | public init( | ||||
_ textApp: String, | _ textApp: String, | ||||
_ textUI: String | |||||
_ textUI: String, | |||||
_ id: String? = nil | |||||
) { | ) { | ||||
var ka = textApp | |||||
var ku = textUI | |||||
if let id { | |||||
ka = ka + id | |||||
ku = ku + id | |||||
} | |||||
Bus.sendSync( | Bus.sendSync( | ||||
textUI, | |||||
ku, | |||||
$v | $v | ||||
.removeDuplicates() | .removeDuplicates() | ||||
.compactMap(onlyUIText) | .compactMap(onlyUIText) | ||||
@@ -20,7 +28,7 @@ extension BusUI { | |||||
) | ) | ||||
Bus.receiveSync( | Bus.receiveSync( | ||||
[textApp], | |||||
[ka], | |||||
{ [weak self] (_, v: String) in self?.v = "a:\(v)" }, | { [weak self] (_, v: String) in self?.v = "a:\(v)" }, | ||||
&subscriptions | &subscriptions | ||||
) | ) | ||||
@@ -1,3 +1,5 @@ | |||||
import BusX | |||||
extension MeetupId { | extension MeetupId { | ||||
final class Component: ObservableObject { | final class Component: ObservableObject { | ||||
var isJoinAvailable: BusUI.Value<Bool> | var isJoinAvailable: BusUI.Value<Bool> | ||||
@@ -13,8 +15,8 @@ extension MeetupId { | |||||
/**/print("ИГР MeetupIC.init") | /**/print("ИГР MeetupIC.init") | ||||
isJoinAvailable = .init(K.isJoinAvailable, false, id) | isJoinAvailable = .init(K.isJoinAvailable, false, id) | ||||
isLoading = .init(K.isLoading, false, id) | isLoading = .init(K.isLoading, false, id) | ||||
join = .init(K.join) | |||||
textField = .init(K.textApp, K.textUI) | |||||
join = .init(K.join, id) | |||||
textField = .init(K.textApp, K.textUI, id) | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -4,9 +4,9 @@ import UIKit | |||||
struct Content: View { | struct Content: View { | ||||
var body: some View { | var body: some View { | ||||
MeetupId.V() | |||||
MeetupId.V("") | |||||
Divider() | Divider() | ||||
MeetupId.V() | |||||
MeetupId.V("abc") | |||||
} | } | ||||
} | } | ||||