Last active
May 8, 2020 20:42
-
-
Save garsdle/a7ffa568e83a95e05f0d9ef6f0e80dac to your computer and use it in GitHub Desktop.
ObservedStorePath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
struct ObservedStorePath<Value: Equatable>: DynamicProperty { | |
@ObservedObject private var observableFilter: ObservableStoreFilter<Value> | |
var wrappedValue: Value { | |
get { | |
observableFilter.value | |
} | |
nonmutating set { | |
observableFilter.value = newValue | |
} | |
} | |
var projectedValue: Binding<Value> { | |
$observableFilter.value | |
} | |
init(_ filterPath: WritableKeyPath<AppState, Value>) { | |
self._observableFilter = ObservedObject<ObservableStoreFilter<Value>>(initialValue: ObservableStoreFilter(filterPath)) | |
} | |
} | |
struct TickerView: View { | |
@ObservedStorePath(\.ticker) var ticker | |
var body: some View { | |
Form { | |
Text("\(ticker)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment