forked from aparoksha/adwaita-swift
Add property rawValue to State
Modify the wrapped value without updating the view
This commit is contained in:
parent
8eb004c9ea
commit
26b46e3338
@ -13,6 +13,10 @@ Access the stored value. This updates the views when being changed.
|
|||||||
|
|
||||||
Get the value as a binding using the `$` prefix.
|
Get the value as a binding using the `$` prefix.
|
||||||
|
|
||||||
|
### `rawValue`
|
||||||
|
|
||||||
|
Get and set the value without updating the views.
|
||||||
|
|
||||||
### `content`
|
### `content`
|
||||||
|
|
||||||
The stored value.
|
The stored value.
|
||||||
|
|||||||
@ -11,18 +11,16 @@ import Foundation
|
|||||||
@propertyWrapper
|
@propertyWrapper
|
||||||
public struct State<Value>: StateProtocol {
|
public struct State<Value>: StateProtocol {
|
||||||
|
|
||||||
// swiftlint:disable force_cast
|
|
||||||
/// Access the stored value. This updates the views when being changed.
|
/// Access the stored value. This updates the views when being changed.
|
||||||
public var wrappedValue: Value {
|
public var wrappedValue: Value {
|
||||||
get {
|
get {
|
||||||
content.storage.value as! Value
|
rawValue
|
||||||
}
|
}
|
||||||
nonmutating set {
|
nonmutating set {
|
||||||
content.storage.value = newValue
|
rawValue = newValue
|
||||||
Self.updateViews()
|
Self.updateViews()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// swiftlint:enable force_cast
|
|
||||||
|
|
||||||
/// Get the value as a binding using the `$` prefix.
|
/// Get the value as a binding using the `$` prefix.
|
||||||
public var projectedValue: Binding<Value> {
|
public var projectedValue: Binding<Value> {
|
||||||
@ -33,6 +31,18 @@ public struct State<Value>: StateProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swiftlint:disable force_cast
|
||||||
|
/// Get and set the value without updating the views.
|
||||||
|
public var rawValue: Value {
|
||||||
|
get {
|
||||||
|
content.storage.value as! Value
|
||||||
|
}
|
||||||
|
nonmutating set {
|
||||||
|
content.storage.value = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// swiftlint:enable force_cast
|
||||||
|
|
||||||
/// The stored value.
|
/// The stored value.
|
||||||
public let content: State<Any>.Content
|
public let content: State<Any>.Content
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user