|
@@ -0,0 +1,35 @@ |
|
|
|
|
|
import Combine |
|
|
|
|
|
|
|
|
|
|
|
extension BusUI { |
|
|
|
|
|
public final class ManyButton: ObservableObject { |
|
|
|
|
|
let key: String |
|
|
|
|
|
public let v = PassthroughSubject<Void, Never>() |
|
|
|
|
|
@Published public var id: String? |
|
|
|
|
|
var sub = [AnyCancellable]() |
|
|
|
|
|
var subscriptions = [AnyCancellable]() |
|
|
|
|
|
|
|
|
|
|
|
public init(_ key: String) { |
|
|
|
|
|
self.key = key |
|
|
|
|
|
|
|
|
|
|
|
$id |
|
|
|
|
|
.sink { [weak self] id in self?.setup(id) } |
|
|
|
|
|
.store(in: &sub) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func setup(_ id: String?) { |
|
|
|
|
|
subscriptions = [] |
|
|
|
|
|
|
|
|
|
|
|
Bus.sendSync( |
|
|
|
|
|
key, |
|
|
|
|
|
v |
|
|
|
|
|
.compactMap { v -> Any? in |
|
|
|
|
|
guard let id else { return nil } |
|
|
|
|
|
var d = [String: Bool]() |
|
|
|
|
|
return MPAK.Many([id], d) |
|
|
|
|
|
} |
|
|
|
|
|
.eraseToAnyPublisher(), |
|
|
|
|
|
&subscriptions |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |