Skip to content

Commit

Permalink
Implement static func Binding<Value>.constant (#178)
Browse files Browse the repository at this point in the history
Unrelated formatting changes were added by the SwiftFormat pre-commit hook.
  • Loading branch information
MaxDesiatov authored Jul 13, 2020
1 parent 2b3010a commit 9cf606e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 7 additions & 1 deletion Sources/TokamakCore/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -46,4 +48,8 @@ typealias Updater<T> = (inout T) -> ()
}
)
}

static func constant(_ value: Value) -> Self {
.init(get: { value }, set: { _ in })
}
}
8 changes: 4 additions & 4 deletions Sources/TokamakDOM/Views/SecureField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
]))
}
}
8 changes: 4 additions & 4 deletions Sources/TokamakDOM/Views/TextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
]))
}
}

0 comments on commit 9cf606e

Please sign in to comment.