-
-
Notifications
You must be signed in to change notification settings - Fork 60
Renamed StateProperty to ObservableProperty and made the protocol public #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import Foundation | |
| // - It supports ObservableObject | ||
| // - It supports Optional<ObservableObject> | ||
| @propertyWrapper | ||
| public struct State<Value>: DynamicProperty, StateProperty { | ||
| public struct State<Value>: DynamicProperty, ObservableProperty { | ||
| class Storage { | ||
| // This inner box is what stays constant between view updates. The | ||
| // outer box (Storage) is used so that we can assign this box to | ||
|
|
@@ -55,7 +55,7 @@ public struct State<Value>: DynamicProperty, StateProperty { | |
|
|
||
| var storage: Storage | ||
|
|
||
| var didChange: Publisher { | ||
| public var didChange: Publisher { | ||
| storage.box.didChange | ||
| } | ||
|
|
||
|
|
@@ -109,7 +109,7 @@ public struct State<Value>: DynamicProperty, StateProperty { | |
| } | ||
| } | ||
|
|
||
| func tryRestoreFromSnapshot(_ snapshot: Data) { | ||
| public func tryRestoreFromSnapshot(_ snapshot: Data) { | ||
| guard | ||
| let decodable = Value.self as? Codable.Type, | ||
| let state = try? JSONDecoder().decode(decodable, from: snapshot) | ||
|
|
@@ -120,7 +120,7 @@ public struct State<Value>: DynamicProperty, StateProperty { | |
| storage.box.value = state as! Value | ||
| } | ||
|
|
||
| func snapshot() throws -> Data? { | ||
| public func snapshot() throws -> Data? { | ||
| if let value = storage.box as? Codable { | ||
| return try JSONEncoder().encode(value) | ||
| } else { | ||
|
|
@@ -129,7 +129,10 @@ public struct State<Value>: DynamicProperty, StateProperty { | |
| } | ||
| } | ||
|
|
||
| protocol StateProperty { | ||
| /// Declaring conformance to ObservableProperty is required for | ||
| /// SwiftCrossUI to automatically register an observer on the | ||
| /// conforming object's Publisher. | ||
| public protocol ObservableProperty { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this protocol its own file now that it's part of the public API.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that |
||
| var didChange: Publisher { get } | ||
| func tryRestoreFromSnapshot(_ snapshot: Data) | ||
| func snapshot() throws -> Data? | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to;