-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextObject.sc
128 lines (105 loc) · 2.54 KB
/
extObject.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
+Object {
onSignalDependantAdded {
// override to be notified of new signal dependant connection
}
onSignalDependantRemoved {
// override to be notified of new signal dependant disconnection
}
valueSlot {
|setter=\value|
^ValueSlot(this, setter.asSymbol.asSetter)
}
inputSlot {
^this.valueSlot(\input)
}
methodSlot {
|method|
^MethodSlot(this, method)
}
methodSlots {
|...methods|
^methods.collect(this.methodSlot(_))
}
delegateSlot {
^MethodSlot(this, "changed(changed, *args)")
}
forwardSlot {
^MethodSlot(this, "forwardUpdate(object, changed, *args)")
}
forwardUpdate {
|...args|
dependantsDictionary.at(this).copy.do({ arg item;
item.update(*args);
});
}
connectTo {
|...dependants|
var autoConnect = if (dependants.last.isKindOf(Boolean)) { dependants.pop() } { true };
if (dependants.size == 1) {
^Connection(this, dependants[0], autoConnect);
} {
^ConnectionList.newFrom(dependants.collect {
|dependant|
Connection(this, dependant, autoConnect)
})
}
}
uniqueConnectionAt {
|name|
^UniqueConnections.at(this, name)
}
uniqueConnectionPut {
|name, value|
UniqueConnections.put(this, name, value)
}
connectToUnique {
|name ...dependants|
var connection;
if (name.isKindOf(String)) {
name = name.asSymbol
};
if (name.isKindOf(Symbol).not) {
dependants = [name] ++ dependants;
name = \defaultUniqueConnection;
};
this.uniqueConnectionAt(name).free;
connection = this.connectTo(*dependants);
this.uniqueConnectionPut(name, connection);
^connection
}
mapToSlots {
|...associations|
^ConnectionList.newFrom(
associations.collect {
|assoc|
assoc.key.connectTo(this.methodSlot(assoc.value));
}
)
}
signal {
|keyOrFunc|
if (keyOrFunc.isNil) {
^this
} {
if (keyOrFunc.isKindOf(Symbol)) {
^UpdateDispatcher(this).at(keyOrFunc);
} {
^this.connectTo(UpdateFilter(keyOrFunc));
}
}
}
signals {
|...keyOrFuncs|
^keyOrFuncs.collect(this.signal(_));
}
inputToValue { |obj| ^this.signal(\input).connectTo(obj.valueSlot()) }
valueToValue { |obj| ^this.signal(\value).connectTo(obj.valueSlot()) }
inputToInput { |obj| ^this.signal(\input).connectTo(obj.inputSlot()) }
valueToInput { |obj| ^this.signal(\value).connectTo(obj.inputSlot()) }
inputToArg { |obj, argName| ^this.signal(\input).connectTo(obj.argSlot(argName)) }
valueToArg { |obj, argName| ^this.signal(\value).connectTo(obj.argSlot(argName)) }
connectionTraceString {
^"%(%)".format(this.class, this.identityHash)
}
connectionFreed {}
}