From 99603193b95610d1675c95527c29a0e950965064 Mon Sep 17 00:00:00 2001 From: david-swift Date: Sun, 20 Oct 2024 13:57:44 +0200 Subject: [PATCH] Fix latest binding change making binding view-only --- Sources/Model/Data Flow/Binding.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/Model/Data Flow/Binding.swift b/Sources/Model/Data Flow/Binding.swift index c11b605..9b3f9b6 100644 --- a/Sources/Model/Data Flow/Binding.swift +++ b/Sources/Model/Data Flow/Binding.swift @@ -44,7 +44,7 @@ public struct Binding { /// The value. public var wrappedValue: Value { get { - value + getValue() } nonmutating set { setValue(newValue) @@ -64,6 +64,8 @@ public struct Binding { } /// The closure for getting the value. + private let getValue: () -> Value + /// The cached value for comparison purposes. private let value: Value /// The closure for settings the value. private let setValue: (Value) -> Void @@ -86,6 +88,7 @@ public struct Binding { /// - get: The closure for getting the value. /// - set: The closure for setting the value. public init(get: @escaping () -> Value, set: @escaping (Value) -> Void) { + self.getValue = get self.value = get() self.setValue = set } @@ -114,7 +117,7 @@ public struct Binding { extension Binding: Equatable where Value: Equatable { - /// Whether to binding values are equal. + /// Whether two binding values were equal when they were initialized. /// - Parameters: /// - lhs: The first binding. /// - rhs: The second binding.