1668
|
1 |
"{ Package: 'stx:libbasic2' }"
|
|
2 |
!
|
|
3 |
|
1759
|
4 |
!Object methodsFor:'dependents-interests'!
|
|
5 |
|
|
6 |
addInterest:anInterest
|
|
7 |
"install an interest forwarder.
|
|
8 |
Here, we use the nonWeakDependencies."
|
|
9 |
|
|
10 |
self addNonWeakDependent:anInterest
|
|
11 |
|
|
12 |
"Created: 14.10.1996 / 22:27:34 / stefan"
|
|
13 |
! !
|
|
14 |
|
|
15 |
!Object methodsFor:'dependents-interests'!
|
|
16 |
|
|
17 |
expressInterestIn:aspect for:anObject sendBack:aSelector
|
|
18 |
"arrange for aSelector to be sent to anObject whenever the receiver
|
|
19 |
changes aspect."
|
|
20 |
|
|
21 |
"/ for now, use an interestConverter, which is somewhat less efficient.
|
|
22 |
"/ In the future, a more intelligent DependencyCollection class is planned for
|
|
23 |
|
|
24 |
self addInterest:(InterestConverter
|
|
25 |
destination:anObject
|
|
26 |
selector:aSelector
|
|
27 |
aspect:aspect)
|
|
28 |
|
|
29 |
"
|
|
30 |
|p b|
|
|
31 |
|
|
32 |
b := [Transcript showCR:' -> the point changed'].
|
|
33 |
|
|
34 |
p := Point new.
|
|
35 |
Transcript showCR:'interest in #foo:'.
|
|
36 |
p expressInterestIn:#foo for:b sendBack:#value.
|
|
37 |
p x:1.
|
|
38 |
Transcript showCR:'now changing #bar ... (expect no notification)'.
|
|
39 |
p changed:#bar.
|
|
40 |
Transcript cr.
|
|
41 |
|
|
42 |
Delay waitForSeconds:1.
|
|
43 |
Transcript showCR:'now changing #foo ... (expect notification)'.
|
|
44 |
p changed:#foo.
|
|
45 |
Transcript cr.
|
|
46 |
|
|
47 |
Delay waitForSeconds:1.
|
|
48 |
Transcript showCR:'no more interest in #foo:'.
|
|
49 |
p retractInterestIn:#foo for:b.
|
|
50 |
Transcript showCR:'now changing #foo ... (expect no notification)'.
|
|
51 |
p changed:#foo.
|
|
52 |
Transcript cr.
|
|
53 |
|
|
54 |
Delay waitForSeconds:1.
|
|
55 |
Transcript showCR:'interest in #bar now:'.
|
|
56 |
p expressInterestIn:#bar for:b sendBack:#value.
|
|
57 |
Transcript showCR:'now changing #foo ... (expect no notification)'.
|
|
58 |
p changed:#foo.
|
|
59 |
Transcript showCR:'now changing #bar ... (expect notification)'.
|
|
60 |
p changed:#bar.
|
|
61 |
Transcript cr.
|
|
62 |
|
|
63 |
Delay waitForSeconds:1.
|
|
64 |
Transcript showCR:'interest in #foo now:'.
|
|
65 |
p expressInterestIn:#foo for:b sendBack:#value.
|
|
66 |
Transcript showCR:'now changing #foo ... (expect notification)'.
|
|
67 |
p changed:#foo.
|
|
68 |
Transcript showCR:'now changing #bar ... (expect notification)'.
|
|
69 |
p changed:#bar.
|
|
70 |
Transcript cr.
|
|
71 |
|
|
72 |
Delay waitForSeconds:1.
|
|
73 |
Transcript showCR:'no more interests:'.
|
|
74 |
p retractInterestsFor:b.
|
|
75 |
Transcript showCR:'now changing #foo ... (expect no notification)'.
|
|
76 |
p changed:#foo.
|
|
77 |
Transcript showCR:'now changing #bar... (expect no notification)'.
|
|
78 |
p changed:#bar.
|
|
79 |
Transcript cr.
|
|
80 |
|
|
81 |
p release.
|
|
82 |
"
|
1668
|
83 |
|
1759
|
84 |
"Created: 19.4.1996 / 10:26:22 / cg"
|
|
85 |
"Modified: 19.4.1996 / 12:34:08 / cg"
|
|
86 |
"Modified: 14.10.1996 / 22:28:20 / stefan"
|
|
87 |
! !
|
|
88 |
|
|
89 |
!Object methodsFor:'dependents-interests'!
|
|
90 |
|
|
91 |
interests
|
|
92 |
"return a Collection of interests - empty if there is none.
|
|
93 |
Here, we use the nonWeakDependents for interests."
|
|
94 |
|
|
95 |
^ self nonWeakDependents
|
|
96 |
|
|
97 |
"Created: / 14.10.1996 / 22:20:51 / stefan"
|
|
98 |
"Modified: / 30.1.1998 / 14:07:35 / cg"
|
|
99 |
! !
|
|
100 |
|
|
101 |
!Object methodsFor:'dependents-interests'!
|
|
102 |
|
|
103 |
interestsFor:someOne
|
|
104 |
"return a collection of interests of someOne - empty if there is none."
|
|
105 |
|
|
106 |
|coll deps|
|
|
107 |
|
|
108 |
deps := self interests.
|
|
109 |
deps size == 0 ifTrue:[^ #()].
|
|
110 |
|
|
111 |
coll := IdentitySet new.
|
|
112 |
|
|
113 |
deps do:[:dep |
|
|
114 |
(dep isInterestConverter) ifTrue:[
|
|
115 |
dep destination == someOne ifTrue:[
|
|
116 |
coll add:dep.
|
|
117 |
]
|
|
118 |
]
|
|
119 |
].
|
|
120 |
^ coll
|
|
121 |
|
|
122 |
"Created: / 30.1.1998 / 14:02:26 / cg"
|
|
123 |
"Modified: / 30.1.1998 / 14:08:24 / cg"
|
|
124 |
! !
|
1668
|
125 |
|
1759
|
126 |
!Object methodsFor:'dependents-interests'!
|
|
127 |
|
|
128 |
onChangeEvaluate:aBlock
|
|
129 |
"arrange for aBlock to be evaluated whenever the receiver changes."
|
|
130 |
|
|
131 |
^ self onChangeSend:#value to:aBlock
|
|
132 |
|
|
133 |
"
|
|
134 |
|p b|
|
|
135 |
|
|
136 |
b := [Transcript showCR:' -> the point changed'].
|
|
137 |
|
|
138 |
p := Point new.
|
|
139 |
Transcript showCR:'interest in #foo:'.
|
|
140 |
p onChangeEvaluate:b.
|
|
141 |
p x:1.
|
|
142 |
Transcript showCR:'now changing #bar ... (expect no notification)'.
|
|
143 |
p changed:#bar.
|
|
144 |
|
|
145 |
p retractInterests.
|
|
146 |
p changed:#bar.
|
|
147 |
"
|
|
148 |
! !
|
|
149 |
|
|
150 |
!Object methodsFor:'dependents-interests'!
|
|
151 |
|
|
152 |
onChangeSend:aSelector to:anObject
|
|
153 |
"arrange for aSelector to be sent to anObject whenever the receiver
|
|
154 |
changes."
|
|
155 |
|
|
156 |
"/ for now, use an interestConverter, which is somewhat less efficient.
|
|
157 |
"/ In the future, a more intelligent DependencyCollection class is planned for
|
|
158 |
|
|
159 |
((self interests ? #())
|
|
160 |
contains:[:anInterest |
|
|
161 |
(anInterest isInterestConverter)
|
|
162 |
and:[ anInterest destination == anObject
|
|
163 |
and:[ anInterest selector == aSelector]]
|
|
164 |
])
|
|
165 |
ifTrue:[^ self].
|
|
166 |
|
|
167 |
self addInterest:(InterestConverter
|
|
168 |
destination:anObject
|
|
169 |
selector:aSelector)
|
1668
|
170 |
|
|
171 |
"
|
1759
|
172 |
|p b|
|
|
173 |
|
|
174 |
b := [Transcript showCR:'the point changed'].
|
|
175 |
|
|
176 |
p := Point new.
|
|
177 |
p onChangeSend:#value to:b.
|
|
178 |
p x:1.
|
|
179 |
Transcript showCR:'now changing'.
|
|
180 |
p changed.
|
|
181 |
Transcript cr.
|
|
182 |
|
|
183 |
Delay waitForSeconds:1.
|
|
184 |
Transcript showCR:'now changing'.
|
|
185 |
p changed.
|
|
186 |
Transcript cr.
|
|
187 |
|
|
188 |
Delay waitForSeconds:1.
|
|
189 |
Transcript showCR:'no more interest'.
|
|
190 |
p retractInterestsFor:b.
|
|
191 |
Transcript showCR:'now changing again'.
|
|
192 |
p changed.
|
|
193 |
Transcript cr.
|
|
194 |
|
|
195 |
Delay waitForSeconds:1.
|
|
196 |
Transcript showCR:'interest again'.
|
|
197 |
p onChangeSend:#value to:b.
|
|
198 |
Transcript showCR:'now changing again'.
|
|
199 |
p changed.
|
|
200 |
Transcript cr.
|
|
201 |
"
|
|
202 |
|
|
203 |
"Created: 19.4.1996 / 10:26:38 / cg"
|
|
204 |
"Modified: 19.4.1996 / 12:34:26 / cg"
|
|
205 |
"Modified: 14.10.1996 / 22:28:27 / stefan"
|
|
206 |
! !
|
|
207 |
|
|
208 |
!Object methodsFor:'dependents-interests'!
|
|
209 |
|
|
210 |
removeInterest:anInterest
|
|
211 |
"remove an interest forwarder.
|
|
212 |
Here, we use the nonWeakDependencies."
|
|
213 |
|
|
214 |
self removeNonWeakDependent:anInterest
|
|
215 |
|
|
216 |
"Created: 14.10.1996 / 22:21:59 / stefan"
|
|
217 |
! !
|
|
218 |
|
|
219 |
!Object methodsFor:'dependents-interests'!
|
|
220 |
|
|
221 |
retractInterestIn:aspect for:someOne
|
|
222 |
"remove the interest of someOne in the receiver changing aspect
|
|
223 |
(as installed with #expressInterestIn:for:sendBack:)."
|
|
224 |
|
|
225 |
"/ for now, remove the interestConverter.
|
|
226 |
"/ In the future, a more intelligent DependencyCollection class is planned for
|
|
227 |
|
|
228 |
self retractInterestsForWhich:[:i | (i aspect == aspect) and:[i destination == someOne]]
|
|
229 |
|
1668
|
230 |
"
|
1759
|
231 |
|p b|
|
|
232 |
|
|
233 |
b := [Transcript showCR:'the point changed'].
|
|
234 |
|
|
235 |
p := Point new.
|
|
236 |
Transcript showCR:'interest in #foo'.
|
|
237 |
p expressInterestIn:#foo for:b sendBack:#value.
|
|
238 |
p x:1.
|
|
239 |
Transcript showCR:'now changing #bar'.
|
|
240 |
p changed:#bar.
|
|
241 |
Transcript cr.
|
|
242 |
|
|
243 |
Delay waitForSeconds:1.
|
|
244 |
Transcript showCR:'now changing #foo'.
|
|
245 |
p changed:#foo.
|
|
246 |
Transcript cr.
|
|
247 |
|
|
248 |
Delay waitForSeconds:1.
|
|
249 |
Transcript showCR:'no more interest in #foo'.
|
|
250 |
p retractInterestIn:#foo for:b.
|
|
251 |
Transcript showCR:'now changing #foo'.
|
|
252 |
p changed:#foo.
|
|
253 |
Transcript cr.
|
|
254 |
|
|
255 |
Delay waitForSeconds:1.
|
|
256 |
Transcript showCR:'interest in #bar now'.
|
|
257 |
p expressInterestIn:#bar for:b sendBack:#value.
|
|
258 |
Transcript showCR:'now changing #foo'.
|
|
259 |
p changed:#foo.
|
|
260 |
Transcript showCR:'now changing #bar'.
|
|
261 |
p changed:#bar.
|
|
262 |
Transcript cr.
|
|
263 |
|
|
264 |
Delay waitForSeconds:1.
|
|
265 |
Transcript showCR:'interest in #foo now'.
|
|
266 |
p expressInterestIn:#foo for:b sendBack:#value.
|
|
267 |
Transcript showCR:'now changing #foo'.
|
|
268 |
p changed:#foo.
|
|
269 |
Transcript showCR:'now changing #bar'.
|
|
270 |
p changed:#bar.
|
|
271 |
Transcript cr.
|
|
272 |
|
|
273 |
Delay waitForSeconds:1.
|
|
274 |
Transcript showCR:'no more interests'.
|
|
275 |
p retractInterestsFor:b.
|
|
276 |
Transcript showCR:'now changing #foo'.
|
|
277 |
p changed:#foo.
|
|
278 |
Transcript showCR:'now changing #bar'.
|
|
279 |
p changed:#bar.
|
|
280 |
Transcript cr.
|
|
281 |
"
|
|
282 |
|
|
283 |
"Created: / 19.4.1996 / 10:27:11 / cg"
|
|
284 |
"Modified: / 14.10.1996 / 22:21:19 / stefan"
|
|
285 |
"Modified: / 30.1.1998 / 14:05:34 / cg"
|
|
286 |
! !
|
|
287 |
|
|
288 |
!Object methodsFor:'dependents-interests'!
|
|
289 |
|
|
290 |
retractInterests
|
|
291 |
"remove all interests in the receiver changing aspect
|
|
292 |
(as installed with #expressInterestIn:for:sendBack:)."
|
|
293 |
|
|
294 |
"/ for now, remove the interestConverter.
|
|
295 |
"/ In the future, a more intelligent DependencyCollection class is planned for
|
|
296 |
|
|
297 |
self retractInterestsForWhich:[:i | true ]
|
|
298 |
! !
|
|
299 |
|
|
300 |
!Object methodsFor:'dependents-interests'!
|
|
301 |
|
|
302 |
retractInterestsFor:someOne
|
|
303 |
"remove the interest of someOne in the receiver
|
|
304 |
(as installed with #onChangeSend:to:)."
|
|
305 |
|
|
306 |
"/ for now, remove the interestConverter.
|
|
307 |
"/ In the future, a more intelligent DependencyCollection class is planned for
|
|
308 |
|
|
309 |
self retractInterestsForWhich:[:i | i destination == someOne ]
|
|
310 |
|
|
311 |
"
|
|
312 |
|p b|
|
|
313 |
|
|
314 |
b := [Transcript showCR:'the point changed'].
|
|
315 |
|
|
316 |
p := Point new.
|
|
317 |
p onChangeSend:#value to:b.
|
|
318 |
p x:1.
|
|
319 |
Transcript showCR:'now changing'.
|
|
320 |
p changed.
|
|
321 |
Transcript cr.
|
|
322 |
|
|
323 |
Delay waitForSeconds:1.
|
|
324 |
Transcript showCR:'now changing'.
|
|
325 |
p changed.
|
|
326 |
Transcript cr.
|
|
327 |
|
|
328 |
Delay waitForSeconds:1.
|
|
329 |
Transcript showCR:'no more interest'.
|
|
330 |
p retractInterestsFor:b.
|
|
331 |
Transcript showCR:'now changing again'.
|
|
332 |
p changed.
|
|
333 |
Transcript cr.
|
|
334 |
|
|
335 |
Delay waitForSeconds:1.
|
|
336 |
Transcript showCR:'interest again'.
|
|
337 |
p onChangeSend:#value to:b.
|
|
338 |
Transcript showCR:'now changing again'.
|
|
339 |
p changed.
|
|
340 |
Transcript cr.
|
|
341 |
"
|
|
342 |
|
|
343 |
"Created: / 19.4.1996 / 10:23:46 / cg"
|
|
344 |
"Modified: / 14.10.1996 / 22:21:25 / stefan"
|
|
345 |
"Modified: / 30.1.1998 / 14:04:52 / cg"
|
|
346 |
! !
|
|
347 |
|
|
348 |
!Object methodsFor:'dependents-interests'!
|
|
349 |
|
|
350 |
retractInterestsForWhich:aBlock
|
|
351 |
"remove all interests in the receiver changing aspect
|
|
352 |
(as installed with #expressInterestIn:for:sendBack:)."
|
|
353 |
|
|
354 |
"/ for now, remove the interestConverter.
|
|
355 |
"/ In the future, a more intelligent DependencyCollection class is planned for
|
|
356 |
|
|
357 |
|deps coll|
|
|
358 |
|
|
359 |
deps := self interests.
|
|
360 |
deps size ~~ 0 ifTrue:[
|
|
361 |
"/ cannot removeDependent within the loop - the interests collection rehashes
|
|
362 |
coll := OrderedCollection new.
|
|
363 |
deps do:[:dep |
|
|
364 |
dep isInterestConverter ifTrue:[
|
|
365 |
(aBlock value:dep) ifTrue:[coll add:dep].
|
|
366 |
]
|
|
367 |
].
|
|
368 |
coll do:[:dep |
|
|
369 |
self removeInterest:dep.
|
|
370 |
].
|
|
371 |
].
|
|
372 |
! !
|
|
373 |
|
|
374 |
!Object methodsFor:'dependents-interests'!
|
|
375 |
|
|
376 |
retractInterestsIn:aspect
|
|
377 |
"remove all interests in the receiver changing aspect
|
|
378 |
(as installed with #expressInterestIn:for:sendBack:)."
|
|
379 |
|
|
380 |
"/ for now, remove the interestConverter.
|
|
381 |
"/ In the future, a more intelligent DependencyCollection class is planned for
|
|
382 |
|
|
383 |
self retractInterestsForWhich:[:i | i aspect == aspect ]
|
1668
|
384 |
! !
|
|
385 |
|
|
386 |
!Object methodsFor:'dependents-st/v event simulation'!
|
|
387 |
|
|
388 |
when:eventSymbol send:selector to:anObject
|
|
389 |
"install an ST/V-style interest forwarder.
|
|
390 |
Here, we use the nonWeakDependencies."
|
|
391 |
|
|
392 |
self addInterest:(InterestConverterWithParameters
|
|
393 |
destination:anObject
|
|
394 |
selector:selector
|
|
395 |
aspect:eventSymbol).
|
|
396 |
|
|
397 |
"
|
|
398 |
|p b|
|
|
399 |
|
|
400 |
b := [Transcript showCR:'the point changed'].
|
|
401 |
|
|
402 |
p := Point new.
|
|
403 |
p whem:#foo:bar: send:#value:value: to:[:a :b | Transcript show:'foo: '; show:a; show:' bar: '; showCR:b].
|
|
404 |
Transcript showCR:'now changing'.
|
|
405 |
p triggerEvent:#foo:bar: withArguments:#('fooArg' 'barArg').
|
|
406 |
p retracrtInterests.
|
|
407 |
"
|
|
408 |
! !
|
|
409 |
|