Remove observable support
This commit is contained in:
parent
cd543da08d
commit
5b3e66ed37
@ -6,7 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
/// A property wrapper for properties in a view that should be stored throughout view updates.
|
||||
@propertyWrapper
|
||||
@ -48,15 +47,6 @@ public struct State<Value>: StateProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the value is an observable object.
|
||||
var isObservable: Bool {
|
||||
if #available(macOS 14, *), #available(iOS 17, *) {
|
||||
return Value.self as? Observable.Type != nil
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/// The state's identifier for the stored value.
|
||||
var id: UUID = .init()
|
||||
|
||||
|
@ -12,7 +12,5 @@ protocol StateProtocol {
|
||||
|
||||
/// The identifier for the state property's value.
|
||||
var id: UUID { get set }
|
||||
/// Whether the state value is an observable object.
|
||||
var isObservable: Bool { get }
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
// Created by david-swift on 01.07.24.
|
||||
//
|
||||
|
||||
import Observation
|
||||
|
||||
/// A structure conforming to `App` is the entry point of your app.
|
||||
///
|
||||
/// ```swift
|
||||
@ -91,9 +89,6 @@ extension App {
|
||||
StateManager.appID = appInstance.id
|
||||
let state = appInstance.getState()
|
||||
appInstance.app.storage.stateStorage = state
|
||||
if #available(macOS 14, *), #available(iOS 17, *), state.contains(where: { $0.value.isObservable }) {
|
||||
appInstance.observe()
|
||||
}
|
||||
return appInstance
|
||||
}
|
||||
|
||||
@ -107,17 +102,4 @@ extension App {
|
||||
return state
|
||||
}
|
||||
|
||||
/// Observe the observable properties accessed in the app.
|
||||
@available(macOS, introduced: 14)
|
||||
@available(iOS, introduced: 17)
|
||||
func observe() {
|
||||
withObservationTracking {
|
||||
_ = scene
|
||||
} onChange: {
|
||||
StateManager.updateState(id: app.storage.stateStorage.first?.value.id ?? .init())
|
||||
StateManager.updateViews()
|
||||
observe()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
// Created by david-swift on 09.06.24.
|
||||
//
|
||||
|
||||
import Observation
|
||||
|
||||
/// A storage for `@State` properties.
|
||||
struct StateWrapper: ConvenienceWidget {
|
||||
|
||||
@ -72,24 +70,7 @@ struct StateWrapper: ConvenienceWidget {
|
||||
let content = content().storage(modifiers: modifiers, type: type)
|
||||
let storage = ViewStorage(content.pointer, content: [.mainContent: [content]])
|
||||
storage.state = state
|
||||
if #available(macOS 14, *), #available(iOS 17, *), state.contains(where: { $0.value.isObservable }) {
|
||||
observe(storage: storage)
|
||||
}
|
||||
return storage
|
||||
}
|
||||
|
||||
/// Observe the observable properties accessed in the view.
|
||||
/// - Parameter storage: The view storage
|
||||
@available(macOS, introduced: 14)
|
||||
@available(iOS, introduced: 17)
|
||||
func observe(storage: ViewStorage) {
|
||||
withObservationTracking {
|
||||
_ = content()
|
||||
} onChange: {
|
||||
StateManager.updateState(id: storage.state.first?.value.id ?? .init())
|
||||
StateManager.updateViews()
|
||||
observe(storage: storage)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
import Foundation
|
||||
@testable import Meta
|
||||
import Observation
|
||||
import SampleBackends
|
||||
|
||||
@main
|
||||
@available(macOS 14, *)
|
||||
@available(iOS 17, *)
|
||||
struct TestExecutable {
|
||||
|
||||
public static func main() {
|
||||
@ -15,8 +12,6 @@ struct TestExecutable {
|
||||
|
||||
}
|
||||
|
||||
@available(macOS 14, *)
|
||||
@available(iOS 17, *)
|
||||
struct DemoApp: App {
|
||||
|
||||
let id = "io.github.AparokshaUI.DemoApp"
|
||||
@ -34,8 +29,6 @@ struct DemoApp: App {
|
||||
|
||||
}
|
||||
|
||||
@available(macOS 14, *)
|
||||
@available(iOS 17, *)
|
||||
struct DemoView: View {
|
||||
|
||||
@State private var model = TestModel()
|
||||
@ -60,7 +53,6 @@ struct DemoView: View {
|
||||
|
||||
}
|
||||
|
||||
@available(macOS 14, *)
|
||||
struct TestView: View {
|
||||
|
||||
@State private var test = TestModel()
|
||||
@ -74,10 +66,7 @@ struct TestView: View {
|
||||
|
||||
}
|
||||
|
||||
@available(macOS 14, *)
|
||||
@available(iOS 17, *)
|
||||
@Observable
|
||||
class TestModel {
|
||||
struct TestModel {
|
||||
|
||||
var test = "Label"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user