84 lines
1.9 KiB
Swift
84 lines
1.9 KiB
Swift
////
|
|
//// Published.swift
|
|
//// VDS
|
|
////
|
|
//// Created by Matt Bruce on 7/28/22.
|
|
////
|
|
//
|
|
//import Foundation
|
|
//
|
|
////https://www.swiftbysundell.com/articles/published-properties-in-swift/
|
|
//@propertyWrapper
|
|
//public struct Published<Value> {
|
|
// public var projectedValue: Published { self }
|
|
// public var wrappedValue: Value {
|
|
// didSet {
|
|
// valueDidChange()
|
|
// }
|
|
// }
|
|
//
|
|
// private var observations = MutableReference(
|
|
// value: List<(Value) -> Void>()
|
|
// )
|
|
//
|
|
// public init(wrappedValue: Value) {
|
|
// self.wrappedValue = wrappedValue
|
|
// }
|
|
//}
|
|
//
|
|
//private extension Published {
|
|
// func valueDidChange() {
|
|
// for closure in observations.value {
|
|
// closure(wrappedValue)
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//extension Published {
|
|
// public func observe(with closure: @escaping (Value) -> Void) -> Cancellable {
|
|
// // To further mimmic Combine's behaviors, we'll call
|
|
// // each observation closure as soon as it's attached to
|
|
// // our property:
|
|
// closure(wrappedValue)
|
|
//
|
|
// let node = observations.value.append(closure)
|
|
//
|
|
// return Cancellable { [weak observations] in
|
|
// observations?.value.remove(node)
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//public class Cancellable {
|
|
// private var closure: (() -> Void)?
|
|
//
|
|
// public init(closure: @escaping () -> Void) {
|
|
// self.closure = closure
|
|
// }
|
|
//
|
|
// deinit {
|
|
// cancel()
|
|
// }
|
|
//
|
|
// public func cancel() {
|
|
// closure?()
|
|
// closure = nil
|
|
// }
|
|
//}
|
|
//
|
|
//
|
|
/////https://www.swiftbysundell.com/articles/combining-value-and-reference-types-in-swift/
|
|
//public class Reference<Value> {
|
|
// fileprivate(set) var value: Value
|
|
//
|
|
// public init(value: Value) {
|
|
// self.value = value
|
|
// }
|
|
//}
|
|
//
|
|
//public class MutableReference<Value>: Reference<Value> {
|
|
// public func update(with value: Value) {
|
|
// self.value = value
|
|
// }
|
|
//}
|