Skip to content

Commit 57b3012

Browse files
authored
Wrap view store binding (#1802)
1 parent 5811712 commit 57b3012

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/ComposableArchitecture/ViewStore.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,10 @@ public final class ViewStore<ViewState, ViewAction>: ObservableObject {
466466
get: @escaping (ViewState) -> Value,
467467
send valueToAction: @escaping (Value) -> ViewAction
468468
) -> Binding<Value> {
469-
ObservedObject(wrappedValue: self)
469+
let base = ObservedObject(wrappedValue: self)
470470
.projectedValue[get: .init(rawValue: get), send: .init(rawValue: valueToAction)]
471+
472+
return Binding(get: { base.wrappedValue }, set: { base.transaction($1).wrappedValue = $0 })
471473
}
472474

473475
/// Derives a binding from the store that prevents direct writes to state and instead sends

0 commit comments

Comments
 (0)