From 962b57ac94ff207a52f4ff3d190883010d006b1e Mon Sep 17 00:00:00 2001 From: Abe White Date: Tue, 26 Sep 2023 23:19:52 -0500 Subject: [PATCH] Remove unneeded code --- .../SkipUI/SkipUI/Properties/Bindable.swift | 93 ++++------- .../SkipUI/SkipUI/Properties/Binding.swift | 9 +- .../SkipUI/Properties/ObservedObject.swift | 144 +----------------- 3 files changed, 36 insertions(+), 210 deletions(-) diff --git a/Sources/SkipUI/SkipUI/Properties/Bindable.swift b/Sources/SkipUI/SkipUI/Properties/Bindable.swift index e09b4675..6777a996 100644 --- a/Sources/SkipUI/SkipUI/Properties/Bindable.swift +++ b/Sources/SkipUI/SkipUI/Properties/Bindable.swift @@ -2,69 +2,30 @@ // under the terms of the GNU Lesser General Public License 3.0 // as published by the Free Software Foundation https://fsf.org -// TODO: Process for use in SkipUI - -#if !SKIP - -import Observation -//import protocol Observation.Observable - -/// A property wrapper type that supports creating bindings to the mutable -/// properties of observable objects. -@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) -@dynamicMemberLookup @propertyWrapper public struct Bindable { - - /// The wrapped object. - public var wrappedValue: Value { get { fatalError() } } - - /// The bindable wrapper for the object that creates bindings to its - /// properties using dynamic member lookup. - public var projectedValue: Bindable { get { fatalError() } } - - public init(wrappedValue: Value) { fatalError() } -} - -@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) -extension Bindable where Value : AnyObject { - - /// Returns a binding to the value of a given key path. - public subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> Binding { get { fatalError() } } -} - -@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) -extension Bindable : Identifiable where Value : Identifiable { - - /// The stable identity of the entity associated with this instance. - public var id: Value.ID { get { fatalError() } } - - /// A type representing the stable identity of the entity associated with - /// an instance. - public typealias ID = Value.ID -} - -@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) -extension Bindable : Sendable where Value : Sendable { -} - -@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) -extension Bindable where Value : AnyObject, Value : Observable { - - /// Creates a bindable object from an observable object. - /// - /// You should not call this initializer directly. Instead, declare a - /// property with the `@Bindable` attribute, and provide an initial value. - public init(wrappedValue: Value) { fatalError() } - - /// Creates a bindable object from an observable object. - /// - /// This initializer is equivalent to `init(wrappedValue:)`, but is more - /// succinct when directly creating bindable objects, e.g. - /// `Bindable(myModel)`. - public init(_ wrappedValue: Value) { fatalError() } - - /// Creates a bindable from the value of another bindable. - public init(projectedValue: Bindable) { fatalError() } -} - -#endif - +// `Bindable` support is implemented in the Skip transpiler. Its code is not needed + +//import Observation +// +//@dynamicMemberLookup @propertyWrapper public struct Bindable { +// public var wrappedValue: Value { get { fatalError() } } +// public var projectedValue: Bindable { get { fatalError() } } +// public init(wrappedValue: Value) { fatalError() } +//} +// +//extension Bindable where Value : AnyObject { +// public subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> Binding { get { fatalError() } } +//} +// +//extension Bindable : Identifiable where Value : Identifiable { +// public var id: Value.ID { get { fatalError() } } +// public typealias ID = Value.ID +//} +// +//extension Bindable : Sendable where Value : Sendable { +//} +// +//extension Bindable where Value : AnyObject, Value : Observable { +// public init(wrappedValue: Value) { fatalError() } +// public init(_ wrappedValue: Value) { fatalError() } +// public init(projectedValue: Bindable) { fatalError() } +//} diff --git a/Sources/SkipUI/SkipUI/Properties/Binding.swift b/Sources/SkipUI/SkipUI/Properties/Binding.swift index faed1a14..955a701b 100644 --- a/Sources/SkipUI/SkipUI/Properties/Binding.swift +++ b/Sources/SkipUI/SkipUI/Properties/Binding.swift @@ -95,22 +95,21 @@ extension Binding : RandomAccessCollection where Value : MutableCollection, Valu //extension Binding { // public subscript(dynamicMember keyPath: WritableKeyPath) -> Binding { get { fatalError() } } //} - +// //@frozen @propertyWrapper @dynamicMemberLookup public struct Binding { //} - +// //extension Binding { // public init(_ base: Binding) where Value == V? { fatalError() } // public init?(_ base: Binding) { fatalError() } // public init(_ base: Binding) where Value == AnyHashable, V : Hashable { fatalError() } //} - +// //extension Binding { // public func transaction(_ transaction: Transaction) -> Binding { fatalError() } // public func animation(_ animation: Animation? = .default) -> Binding { fatalError() } //} - -//@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) +// //extension Binding : DynamicProperty { //} diff --git a/Sources/SkipUI/SkipUI/Properties/ObservedObject.swift b/Sources/SkipUI/SkipUI/Properties/ObservedObject.swift index 54037622..4e8ce67e 100644 --- a/Sources/SkipUI/SkipUI/Properties/ObservedObject.swift +++ b/Sources/SkipUI/SkipUI/Properties/ObservedObject.swift @@ -2,155 +2,21 @@ // under the terms of the GNU Lesser General Public License 3.0 // as published by the Free Software Foundation https://fsf.org -// TODO: Process for use in SkipUI +// `ObservedObject` support is implemented in the Skip transpiler #if !SKIP + +// Stubs needed to compile this package + import protocol Combine.ObservableObject -/// A property wrapper type that subscribes to an observable object and -/// invalidates a view whenever the observable object changes. -/// -/// Add the `@ObservedObject` attribute to a parameter of a SkipUI ``View`` -/// when the input is an -/// -/// and you want the view to update when the object's published properties -/// change. You typically do this to pass a ``StateObject`` into a subview. -/// -/// The following example defines a data model as an observable object, -/// instantiates the model in a view as a state object, and then passes -/// the instance to a subview as an observed object: -/// -/// class DataModel: ObservableObject { -/// @Published var name = "Some Name" -/// @Published var isEnabled = false -/// } -/// -/// struct MyView: View { -/// @StateObject private var model = DataModel() -/// -/// var body: some View { -/// Text(model.name) -/// MySubView(model: model) -/// } -/// } -/// -/// struct MySubView: View { -/// @ObservedObject var model: DataModel -/// -/// var body: some View { -/// Toggle("Enabled", isOn: $model.isEnabled) -/// } -/// } -/// -/// When any published property of the observable object changes, SkipUI -/// updates any view that depends on the object. Subviews can -/// also make updates to the model properties, like the ``Toggle`` in the -/// above example, that propagate to other observers throughout the view -/// hierarchy. -/// -/// Don't specify a default or initial value for the observed object. Use the -/// attribute only for a property that acts as an input for a view, as in the -/// above example. -@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) @propertyWrapper @frozen public struct ObservedObject : DynamicProperty where ObjectType : ObservableObject { - - /// A wrapper of the underlying observable object that can create bindings - /// to its properties. @dynamicMemberLookup @frozen public struct Wrapper { - - /// Gets a binding to the value of a specified key path. - /// - /// - Parameter keyPath: A key path to a specific value. - /// - /// - Returns: A new binding. public subscript(dynamicMember keyPath: ReferenceWritableKeyPath) -> Binding { get { fatalError() } } } - /// Creates an observed object with an initial value. - /// - /// This initializer has the same behavior as the ``init(wrappedValue:)`` - /// initializer. See that initializer for more information. - /// - /// - Parameter initialValue: An initial value. - public init(initialValue: ObjectType) { fatalError() } - - /// Creates an observed object with an initial wrapped value. - /// - /// Don't call this initializer directly. Instead, declare - /// an input to a view with the `@ObservedObject` attribute, and pass a - /// value to this input when you instantiate the view. Unlike a - /// ``StateObject`` which manages data storage, you use an observed - /// object to refer to storage that you manage elsewhere, as in the - /// following example: - /// - /// class DataModel: ObservableObject { - /// @Published var name = "Some Name" - /// @Published var isEnabled = false - /// } - /// - /// struct MyView: View { - /// @StateObject private var model = DataModel() - /// - /// var body: some View { - /// Text(model.name) - /// MySubView(model: model) - /// } - /// } - /// - /// struct MySubView: View { - /// @ObservedObject var model: DataModel - /// - /// var body: some View { - /// Toggle("Enabled", isOn: $model.isEnabled) - /// } - /// } - /// - /// Explicitly calling the observed object initializer in `MySubView` would - /// behave correctly, but would needlessly recreate the same observed object - /// instance every time SkipUI calls the view's initializer to redraw the - /// view. - /// - /// - Parameter wrappedValue: An initial value for the observable object. - public init(wrappedValue: ObjectType) { fatalError() } - - /// The underlying value that the observed object references. - /// - /// The wrapped value property provides primary access to the observed - /// object's data. However, you don't typically access it by name. Instead, - /// SkipUI accesses this property for you when you refer to the variable - /// that you create with the `@ObservedObject` attribute. - /// - /// struct MySubView: View { - /// @ObservedObject var model: DataModel - /// - /// var body: some View { - /// Text(model.name) // Reads name from model's wrapped value. - /// } - /// } - /// - /// When you change a wrapped value, you can access the new value - /// immediately. However, SkipUI updates views that display the value - /// asynchronously, so the interface might not update immediately. + public init(wrappedValue initialValue: ObjectType) { fatalError() } @MainActor public var wrappedValue: ObjectType { get { fatalError() } } - - /// A projection of the observed object that creates bindings to its - /// properties. - /// - /// Use the projected value to get a ``Binding`` to a property of an - /// observed object. To access the projected value, prefix the property - /// variable with a dollar sign (`$`). For example, you can get a binding - /// to a model's `isEnabled` Boolean so that a ``Toggle`` can control its - /// value: - /// - /// struct MySubView: View { - /// @ObservedObject var model: DataModel - /// - /// var body: some View { - /// Toggle("Enabled", isOn: $model.isEnabled) - /// } - /// } - /// @MainActor public var projectedValue: ObservedObject.Wrapper { get { fatalError() } } } - #endif