Skip to content

Commit

Permalink
Remove unneeded code
Browse files Browse the repository at this point in the history
  • Loading branch information
aabewhite committed Sep 27, 2023
1 parent 0c5fb32 commit 962b57a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 210 deletions.
93 changes: 27 additions & 66 deletions Sources/SkipUI/SkipUI/Properties/Bindable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> {

/// 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<Value> { 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<Subject>(dynamicMember keyPath: ReferenceWritableKeyPath<Value, Subject>) -> Binding<Subject> { 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<Value>) { fatalError() }
}

#endif

// `Bindable` support is implemented in the Skip transpiler. Its code is not needed

//import Observation
//
//@dynamicMemberLookup @propertyWrapper public struct Bindable<Value> {
// public var wrappedValue: Value { get { fatalError() } }
// public var projectedValue: Bindable<Value> { get { fatalError() } }
// public init(wrappedValue: Value) { fatalError() }
//}
//
//extension Bindable where Value : AnyObject {
// public subscript<Subject>(dynamicMember keyPath: ReferenceWritableKeyPath<Value, Subject>) -> Binding<Subject> { 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<Value>) { fatalError() }
//}
9 changes: 4 additions & 5 deletions Sources/SkipUI/SkipUI/Properties/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,21 @@ extension Binding : RandomAccessCollection where Value : MutableCollection, Valu
//extension Binding {
// public subscript<Subject>(dynamicMember keyPath: WritableKeyPath<Value, Subject>) -> Binding<Subject> { get { fatalError() } }
//}

//
//@frozen @propertyWrapper @dynamicMemberLookup public struct Binding<Value> {
//}

//
//extension Binding {
// public init<V>(_ base: Binding<V>) where Value == V? { fatalError() }
// public init?(_ base: Binding<Value?>) { fatalError() }
// public init<V>(_ base: Binding<V>) where Value == AnyHashable, V : Hashable { fatalError() }
//}

//
//extension Binding {
// public func transaction(_ transaction: Transaction) -> Binding<Value> { fatalError() }
// public func animation(_ animation: Animation? = .default) -> Binding<Value> { fatalError() }
//}

//@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
//
//extension Binding : DynamicProperty {
//}

Expand Down
144 changes: 5 additions & 139 deletions Sources/SkipUI/SkipUI/Properties/ObservedObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectType> : 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<Subject>(dynamicMember keyPath: ReferenceWritableKeyPath<ObjectType, Subject>) -> Binding<Subject> { 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<ObjectType>.Wrapper { get { fatalError() } }
}

#endif

0 comments on commit 962b57a

Please sign in to comment.