diff --git a/Sources/TokamakCore/Binding.swift b/Sources/TokamakCore/Binding.swift index de6e8c38..672ddc90 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 084b39da..d804f179 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 87046190..199e5596 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 + } + }, ])) } }