Implement `static func Binding<Value>.constant` (#178)

Unrelated formatting changes were added by the SwiftFormat pre-commit hook.
This commit is contained in:
Max Desiatov 2020-07-13 16:36:27 +01:00 committed by GitHub
parent 2b3010a631
commit 9cf606ef0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 9 deletions

View File

@ -37,7 +37,9 @@ typealias Updater<T> = (inout T) -> ()
self.set = set
}
public subscript<Subject>(dynamicMember keyPath: WritableKeyPath<Value, Subject>) -> Binding<Subject> {
public subscript<Subject>(
dynamicMember keyPath: WritableKeyPath<Value, Subject>
) -> Binding<Subject> {
.init(
get: {
self.wrappedValue[keyPath: keyPath]
@ -46,4 +48,8 @@ typealias Updater<T> = (inout T) -> ()
}
)
}
static func constant(_ value: Value) -> Self {
.init(get: { value }, set: { _ in })
}
}

View File

@ -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
}
},
]))
}
}

View File

@ -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
}
},
]))
}
}