This commit is contained in:
Михаил Капелько
2023-12-16 11:00:13 +03:00
parent 769ade70c9
commit 1e36ef3d71
4 changed files with 72 additions and 134 deletions

View File

@@ -22,73 +22,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate
return true
}
}
/*
// Bus.Pipe.swift
public extension Bus {
final class BindingPipe<T: Equatable>: ObservableObject {
public let input = PassthroughSubject<T, Never>()
public let output = PassthroughSubject<T, Never>()
@Published var value: T
var isInput = false
var subscriptions = [AnyCancellable]()
deinit {
print("ИГР BusBP.DEinit(\(Unmanaged.passUnretained(self).toOpaque()))")
}
init(
_ defaultValue: T,
_ keyApp: String,
_ keyUI: String
) {
value = defaultValue
/**/dbg("ИГР BusBP.init(\(Unmanaged.passUnretained(self).toOpaque())) keyA: '\(keyApp)'")
// TextField -> output.
$value
.sink { [weak self] v in
assert(Thread.isMainThread)
// Ignore values received from input.
// Only accept UI provided values.
guard
let self,
!self.isInput
else {
return
}
self.output.send(v)
}
.store(in: &subscriptions)
// input -> TextField.
input
.sink { [weak self] v in
assert(Thread.isMainThread)
guard let self else { return }
/**/dbg("ИГР BusBP.init input: '\(v)'")
self.isInput = true
self.value = v
self.isInput = false
}
.store(in: &subscriptions)
// Оповещаем в мир об изменениях от UI.
Bus.sendAsync(
&subscriptions,
keyUI,
output.eraseToAnyPublisher()
)
Bus.receive(
&subscriptions,
[keyApp],
{ [weak self] _, v in
self?.input.send(v)
/**/print("ИГР BusBP.init receive: '\(v)'")
}
)
}
}
}
*/