Михаил Капелько 10 月之前
父節點
當前提交
d2a948e7c7
共有 1 個文件被更改,包括 35 次插入0 次删除
  1. +35
    -0
      Modules/BusX/BusUI/src/BusUI.ManyButton.swift

+ 35
- 0
Modules/BusX/BusUI/src/BusUI.ManyButton.swift 查看文件

@@ -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…
取消
儲存