Skip to content

Commit 1970f9e

Browse files
committed
ObservableValue.action
1 parent b732a4d commit 1970f9e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Samples/TicTacToe/Sources/Authentication/LoginScreen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ struct LoginScreen: SwiftUIScreen {
4545
get: \.password,
4646
set: Action.passwordUpdated
4747
),
48-
onCommit: { model.value.actionSink.send(.login) }
48+
onCommit: model.action(.login)
4949
)
5050

51-
Button("Login", action: { model.value.actionSink.send(.login) })
51+
Button("Login", action: model.action(.login))
5252
}
5353
.frame(maxWidth: 400)
5454
}

WorkflowSwiftUI/Sources/ObservableValue.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,14 @@ public final class ObservableValue<Value>: ObservableObject {
104104
return subject.removeDuplicates(by: isDuplicate).eraseToAnyPublisher()
105105
}
106106
}
107+
108+
#if canImport(UIKit)
109+
110+
public extension ObservableValue where Value: SwiftUIScreen {
111+
func action(_ action: Value.Action) -> () -> Void {
112+
// TODO: Should this closure capture the current `actionSink` instead?
113+
{ [weak self] in self?.value.actionSink.send(action) }
114+
}
115+
}
116+
117+
#endif

0 commit comments

Comments
 (0)