Integrate model with binding system

This commit is contained in:
david-swift 2024-07-29 20:35:24 +02:00
parent 23eba70702
commit e551fc078a

View File

@ -69,6 +69,20 @@ public struct ModelData {
extension Model {
/// Get the value as a binding using the `$` prefix.
public var binding: Binding<Self> {
.init {
getModel()
} set: { newValue in
guard let data = model else {
return
}
StateManager.setState(id: data.id, value: newValue)
StateManager.updateState(id: data.id)
StateManager.updateViews(force: data.force)
}
}
/// Set the model up.
///
/// At the point this function gets called, the model data is available.