From fd34122e8c6b2158cf7827852a84925f0341758a Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 13 Jul 2020 13:42:28 +0100 Subject: [PATCH 1/2] Implement `static func Binding.constant` --- Sources/TokamakCore/Binding.swift | 4 ++++ Sources/TokamakDOM/Views/SecureField.swift | 8 ++++---- Sources/TokamakDOM/Views/TextField.swift | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Sources/TokamakCore/Binding.swift b/Sources/TokamakCore/Binding.swift index de6e8c38d..da13e96f5 100644 --- a/Sources/TokamakCore/Binding.swift +++ b/Sources/TokamakCore/Binding.swift @@ -46,4 +46,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 + } + }, ])) } } From 352b35d8ceae26810dc69c664d821b0fcbeabbd6 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Mon, 13 Jul 2020 13:47:21 +0100 Subject: [PATCH 2/2] Fix line_length warning in Binding.swift --- Sources/TokamakCore/Binding.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/TokamakCore/Binding.swift b/Sources/TokamakCore/Binding.swift index da13e96f5..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]