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