Update the template screen to use the new(ish) Observation framework. (#4077)

* Update the template screen to use the new(ish) Observation framework.

* Add a variant of deferFulfillment that supports observables.

* Update snapshot fulfilment to work with either a publisher or a stream.
This commit is contained in:
Doug
2025-04-30 16:49:23 +01:00
committed by GitHub
parent 0620bd45fc
commit 61a427b8e5
12 changed files with 297 additions and 25 deletions
@@ -8,7 +8,7 @@
import Combine
import SwiftUI
typealias TemplateScreenViewModelType = StateStoreViewModel<TemplateScreenViewState, TemplateScreenViewAction>
typealias TemplateScreenViewModelType = StateStoreViewModelV2<TemplateScreenViewState, TemplateScreenViewAction>
class TemplateScreenViewModel: TemplateScreenViewModelType, TemplateScreenViewModelProtocol {
private let actionsSubject: PassthroughSubject<TemplateScreenViewModelAction, Never> = .init()
@@ -32,6 +32,16 @@ class TemplateScreenViewModel: TemplateScreenViewModelType, TemplateScreenViewMo
actionsSubject.send(.done)
case .textChanged:
MXLog.info("View model: composer text changed to: \(state.bindings.composerText)")
case .incrementCounter:
Task {
try await Task.sleep(for: .seconds(.random(in: 1.0...2.0)))
state.counter += 1
}
case .decrementCounter:
Task {
try await Task.sleep(for: .seconds(.random(in: 1.0...2.0)))
state.counter -= 1
}
}
}
}