dynamic
This commit is contained in:
parent
7ea07eb22d
commit
2eddd3c952
|
@ -61,4 +61,14 @@ open class NodeModelBase: NSObject, Identifiable, ObservableObject {
|
|||
open func middleContent() -> AnyView {
|
||||
return AnyView(Group{})
|
||||
}
|
||||
open func binding<W, T>(_ v: KeyPath<W, T>) -> Binding<T> {
|
||||
return Binding(
|
||||
get: {
|
||||
self.value(forKeyPath: NSExpression(forKeyPath: v).keyPath) as! T
|
||||
},
|
||||
set: {
|
||||
self.setValue($0, forKeyPath: NSExpression(forKeyPath: v).keyPath)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,23 +9,29 @@ import SwiftUI
|
|||
import Combine
|
||||
|
||||
@propertyWrapper
|
||||
public struct Input<Value> {
|
||||
private var value: Value
|
||||
public class Input<Value> : DynamicProperty {
|
||||
@Published private var value: Value
|
||||
public init(wrappedValue: Value) {
|
||||
value = wrappedValue
|
||||
_value = Published(wrappedValue: wrappedValue)
|
||||
}
|
||||
public var wrappedValue: Value {
|
||||
get {
|
||||
fatalError()
|
||||
value
|
||||
}
|
||||
set {
|
||||
fatalError()
|
||||
value = newValue
|
||||
}
|
||||
}
|
||||
public var projectedValue: Binding<Value> {
|
||||
Binding(
|
||||
get: {self.value},
|
||||
set: {self.value = $0}
|
||||
)
|
||||
}
|
||||
public static subscript<EnclosingSelf: ObservableObject>(
|
||||
_enclosingInstance object: EnclosingSelf,
|
||||
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
|
||||
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self>
|
||||
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Input>
|
||||
) -> Value {
|
||||
get {
|
||||
return object[keyPath: storageKeyPath].value
|
||||
|
|
|
@ -9,23 +9,29 @@ import SwiftUI
|
|||
import Combine
|
||||
|
||||
@propertyWrapper
|
||||
public struct Middle<Value> {
|
||||
private var value: Value
|
||||
public class Middle<Value> : DynamicProperty{
|
||||
@Published private var value: Value
|
||||
public init (wrappedValue: Value) {
|
||||
value = wrappedValue
|
||||
_value = Published(wrappedValue: wrappedValue)
|
||||
}
|
||||
public var wrappedValue: Value {
|
||||
get {
|
||||
fatalError()
|
||||
value
|
||||
}
|
||||
set {
|
||||
fatalError()
|
||||
value = newValue
|
||||
}
|
||||
}
|
||||
public var projectedValue: Binding<Value> {
|
||||
Binding(
|
||||
get: {self.value},
|
||||
set: {self.value = $0}
|
||||
)
|
||||
}
|
||||
public static subscript<EnclosingSelf: ObservableObject>(
|
||||
_enclosingInstance object: EnclosingSelf,
|
||||
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
|
||||
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self>
|
||||
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Middle>
|
||||
) -> Value {
|
||||
get {
|
||||
return object[keyPath: storageKeyPath].value
|
||||
|
|
|
@ -6,36 +6,55 @@
|
|||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
@propertyWrapper
|
||||
public struct Output<Value> {
|
||||
private var value: Value
|
||||
public class Output<Value> : DynamicProperty{
|
||||
|
||||
@Published private var value: Value
|
||||
|
||||
public init (wrappedValue: Value) {
|
||||
value = wrappedValue
|
||||
_value = Published(wrappedValue: wrappedValue)
|
||||
}
|
||||
public var wrappedValue: Value {
|
||||
get {
|
||||
fatalError()
|
||||
value
|
||||
}
|
||||
set {
|
||||
fatalError()
|
||||
value = newValue
|
||||
print("wrapped value set")
|
||||
|
||||
}
|
||||
}
|
||||
public var projectedValue: Binding<Value> {
|
||||
Binding(
|
||||
get: {
|
||||
self.value
|
||||
},
|
||||
set: {
|
||||
self.value = $0
|
||||
print("projected value set")
|
||||
}
|
||||
)
|
||||
}
|
||||
public static subscript<EnclosingSelf: ObservableObject>(
|
||||
_enclosingInstance object: EnclosingSelf,
|
||||
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
|
||||
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self>
|
||||
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Output>
|
||||
) -> Value {
|
||||
get {
|
||||
print("subscript get")
|
||||
return object[keyPath: storageKeyPath].value
|
||||
}
|
||||
set {
|
||||
print("output set ")
|
||||
object[keyPath: storageKeyPath].value = newValue
|
||||
let selfName = NSExpression(forKeyPath: wrappedKeyPath).keyPath
|
||||
guard let outputConnection = (object as? NodeModelBase)?.outputConnection[selfName] else {
|
||||
return
|
||||
}
|
||||
EasyNodeManager.shared.nodeModels[outputConnection.nodeID]!.setValue(newValue, forKey: outputConnection.inputName)
|
||||
EasyNodeManager.shared.objectWillChange.send()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue