|
|
@@ -4,9 +4,42 @@ import SwiftUI |
|
|
|
final class VM: ObservableObject { |
|
|
|
@Published var text = "" |
|
|
|
let changeText = PassthroughSubject<String, Never>() |
|
|
|
|
|
|
|
@Published var t2 = "a:value" |
|
|
|
var bt2: Binding<String>! |
|
|
|
var subscriptions = Set<AnyCancellable>() |
|
|
|
|
|
|
|
init() { |
|
|
|
bt2 = Binding<String>( |
|
|
|
get: { [weak self] in |
|
|
|
String(self?.t2.dropFirst(2) ?? "") |
|
|
|
}, |
|
|
|
set: { [weak self] v in |
|
|
|
if v.hasPrefix("a:") { |
|
|
|
self?.t2 = v |
|
|
|
} else { |
|
|
|
self?.t2 = "u:\(v)" |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
$t2 |
|
|
|
.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main) |
|
|
|
.sink { v in |
|
|
|
/**/print("ИГР VM.init t2: '\(v)'") |
|
|
|
// Ignore repoting application initiated strings |
|
|
|
// Only report user initiated strings |
|
|
|
guard v.hasPrefix("u:") else { return } |
|
|
|
Bus.Service.singleton?.send(MeetupId.Keys.meetupIdTextUI.rawValue, String(v.dropFirst(2))) |
|
|
|
} |
|
|
|
.store(in: &subscriptions) |
|
|
|
|
|
|
|
Bus.receive( |
|
|
|
&subscriptions, |
|
|
|
[MeetupId.Keys.meetupIdTextApp.rawValue], |
|
|
|
{ [weak self] k, v in self?.handleAppValue(k, v) } |
|
|
|
) |
|
|
|
|
|
|
|
// Интерпретируем текст с задержкой, потому что: |
|
|
|
// 1. смена @Published в ту же секунду игнорируется |
|
|
|
// полем ввода, т.е. нужна задержка |
|
|
@@ -27,4 +60,14 @@ final class VM: ObservableObject { |
|
|
|
} |
|
|
|
.store(in: &subscriptions) |
|
|
|
} |
|
|
|
|
|
|
|
func handleAppValue(_: String, _ value: String) { |
|
|
|
/**/print("ИГР VM.handleAV value: '\(value)'") |
|
|
|
/* |
|
|
|
DispatchQueue.main.async { [weak self] in |
|
|
|
self?.t2 = value |
|
|
|
} |
|
|
|
*/ |
|
|
|
} |
|
|
|
|
|
|
|
} |