Михаил Капелько pirms 10 mēnešiem
vecāks
revīzija
d2a948e7c7
1 mainītis faili ar 35 papildinājumiem un 0 dzēšanām
  1. +35
    -0
      Modules/BusX/BusUI/src/BusUI.ManyButton.swift

+ 35
- 0
Modules/BusX/BusUI/src/BusUI.ManyButton.swift Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt