From e551fc078a77940e14d0dd7b9dae596b7b27fd32 Mon Sep 17 00:00:00 2001 From: david-swift Date: Mon, 29 Jul 2024 20:35:24 +0200 Subject: [PATCH] Integrate model with binding system --- Sources/Model/Data Flow/Model.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/Model/Data Flow/Model.swift b/Sources/Model/Data Flow/Model.swift index 5b72fde..5ab11a2 100644 --- a/Sources/Model/Data Flow/Model.swift +++ b/Sources/Model/Data Flow/Model.swift @@ -69,6 +69,20 @@ public struct ModelData { extension Model { + /// Get the value as a binding using the `$` prefix. + public var binding: Binding { + .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.