Remove observable support

This commit is contained in:
david-swift 2024-07-19 21:33:59 +02:00
parent cd543da08d
commit 5b3e66ed37
5 changed files with 1 additions and 61 deletions

View File

@ -6,7 +6,6 @@
// //
import Foundation import Foundation
import Observation
/// A property wrapper for properties in a view that should be stored throughout view updates. /// A property wrapper for properties in a view that should be stored throughout view updates.
@propertyWrapper @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. /// The state's identifier for the stored value.
var id: UUID = .init() var id: UUID = .init()

View File

@ -12,7 +12,5 @@ protocol StateProtocol {
/// The identifier for the state property's value. /// The identifier for the state property's value.
var id: UUID { get set } var id: UUID { get set }
/// Whether the state value is an observable object.
var isObservable: Bool { get }
} }

View File

@ -5,8 +5,6 @@
// Created by david-swift on 01.07.24. // Created by david-swift on 01.07.24.
// //
import Observation
/// A structure conforming to `App` is the entry point of your app. /// A structure conforming to `App` is the entry point of your app.
/// ///
/// ```swift /// ```swift
@ -91,9 +89,6 @@ extension App {
StateManager.appID = appInstance.id StateManager.appID = appInstance.id
let state = appInstance.getState() let state = appInstance.getState()
appInstance.app.storage.stateStorage = state appInstance.app.storage.stateStorage = state
if #available(macOS 14, *), #available(iOS 17, *), state.contains(where: { $0.value.isObservable }) {
appInstance.observe()
}
return appInstance return appInstance
} }
@ -107,17 +102,4 @@ extension App {
return state 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()
}
}
} }

View File

@ -5,8 +5,6 @@
// Created by david-swift on 09.06.24. // Created by david-swift on 09.06.24.
// //
import Observation
/// A storage for `@State` properties. /// A storage for `@State` properties.
struct StateWrapper: ConvenienceWidget { struct StateWrapper: ConvenienceWidget {
@ -72,24 +70,7 @@ struct StateWrapper: ConvenienceWidget {
let content = content().storage(modifiers: modifiers, type: type) let content = content().storage(modifiers: modifiers, type: type)
let storage = ViewStorage(content.pointer, content: [.mainContent: [content]]) let storage = ViewStorage(content.pointer, content: [.mainContent: [content]])
storage.state = state storage.state = state
if #available(macOS 14, *), #available(iOS 17, *), state.contains(where: { $0.value.isObservable }) {
observe(storage: storage)
}
return 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)
}
}
} }

View File

@ -1,11 +1,8 @@
import Foundation import Foundation
@testable import Meta @testable import Meta
import Observation
import SampleBackends import SampleBackends
@main @main
@available(macOS 14, *)
@available(iOS 17, *)
struct TestExecutable { struct TestExecutable {
public static func main() { public static func main() {
@ -15,8 +12,6 @@ struct TestExecutable {
} }
@available(macOS 14, *)
@available(iOS 17, *)
struct DemoApp: App { struct DemoApp: App {
let id = "io.github.AparokshaUI.DemoApp" let id = "io.github.AparokshaUI.DemoApp"
@ -34,8 +29,6 @@ struct DemoApp: App {
} }
@available(macOS 14, *)
@available(iOS 17, *)
struct DemoView: View { struct DemoView: View {
@State private var model = TestModel() @State private var model = TestModel()
@ -60,7 +53,6 @@ struct DemoView: View {
} }
@available(macOS 14, *)
struct TestView: View { struct TestView: View {
@State private var test = TestModel() @State private var test = TestModel()
@ -74,10 +66,7 @@ struct TestView: View {
} }
@available(macOS 14, *) struct TestModel {
@available(iOS 17, *)
@Observable
class TestModel {
var test = "Label" var test = "Label"