diff --git a/Sources/TokamakCore/Binding.swift b/Sources/TokamakCore/Binding.swift index de6e8c38d..672ddc90d 100644 --- a/Sources/TokamakCore/Binding.swift +++ b/Sources/TokamakCore/Binding.swift @@ -37,7 +37,9 @@ typealias Updater = (inout T) -> () self.set = set } - public subscript(dynamicMember keyPath: WritableKeyPath) -> Binding { + public subscript( + dynamicMember keyPath: WritableKeyPath + ) -> Binding { .init( get: { self.wrappedValue[keyPath: keyPath] @@ -46,4 +48,8 @@ typealias Updater = (inout T) -> () } ) } + + static func constant(_ value: Value) -> Self { + .init(get: { value }, set: { _ in }) + } } diff --git a/Sources/TokamakDOM/Views/SecureField.swift b/Sources/TokamakDOM/Views/SecureField.swift index 084b39da0..d804f179a 100644 --- a/Sources/TokamakDOM/Views/SecureField.swift +++ b/Sources/TokamakDOM/Views/SecureField.swift @@ -29,10 +29,10 @@ extension SecureField: ViewDeferredToRenderer where Label == Text { ], listeners: [ "keypress": { event in if event.key == "Enter" { proxy.onCommit() } }, "input": { event in - if let newValue = event.target.object?.value.string { - proxy.textBinding.wrappedValue = newValue - } - }, + if let newValue = event.target.object?.value.string { + proxy.textBinding.wrappedValue = newValue + } + }, ])) } } diff --git a/Sources/TokamakDOM/Views/TextField.swift b/Sources/TokamakDOM/Views/TextField.swift index 870461902..199e55962 100644 --- a/Sources/TokamakDOM/Views/TextField.swift +++ b/Sources/TokamakDOM/Views/TextField.swift @@ -44,10 +44,10 @@ extension TextField: ViewDeferredToRenderer where Label == Text { "blur": { _ in proxy.onEditingChanged(false) }, "keypress": { event in if event.key == "Enter" { proxy.onCommit() } }, "input": { event in - if let newValue = event.target.object?.value.string { - proxy.textBinding.wrappedValue = newValue - } - }, + if let newValue = event.target.object?.value.string { + proxy.textBinding.wrappedValue = newValue + } + }, ])) } }