Skip to content

Commit

Permalink
update ObserveKeyed to accept any property and wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximBazarov committed Aug 10, 2023
1 parent 1c5266f commit 708c2d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Decide-Tests/SwiftUI_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ import DecideTesting

struct ViewUnderTest: View {
@BindKeyed(\State.$strMutable) var strMutable
@ObserveKeyed(\State.$str) var str
@ObserveKeyed(\State.$strMutable) var strMutableObserved

var body: some View {
TextField("", text: strMutable[1])
Text(str[1])
Text(strMutableObserved[1])
}
}

Expand Down
8 changes: 7 additions & 1 deletion Decide/Accessor/SwiftUI/ObserveKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ import SwiftUI

let propertyKeyPath: KeyPath<S, Property<Value>>

public init(_ propertyKeyPath: KeyPath<S, Mutable<Value>>) {
public init(_ propertyKeyPath: KeyPath<S, Property<Value>>) {
self.propertyKeyPath = propertyKeyPath
}

public init<P: PropertyModifier>(
_ propertyKeyPath: KeyPath<S, P>
) where P.Value == Value {
self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue)
}

Expand Down

0 comments on commit 708c2d0

Please sign in to comment.