Михаил Капелько 11 months ago
parent
commit
d2a948e7c7
1 changed files with 35 additions and 0 deletions
  1. +35
    -0
      Modules/BusX/BusUI/src/BusUI.ManyButton.swift

+ 35
- 0
Modules/BusX/BusUI/src/BusUI.ManyButton.swift View File

@@ -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
)
}
}
}

Loading…
Cancel
Save