author | Claus Gittinger <cg@exept.de> |
Mon, 25 May 2009 20:53:28 +0200 | |
changeset 2149 | 329461c02e84 |
parent 1759 | 78e481899a63 |
child 2150 | bdd3b90b3dae |
permissions | -rw-r--r-- |
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 |
||
2149
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
131 |
|na selector| |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
132 |
|
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
133 |
na := aBlock numArgs. |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
134 |
na == 0 ifTrue:[ |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
135 |
selector := #value |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
136 |
] ifFalse:[ |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
137 |
selector := #( #'value:' #'value:value:') at:na |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
138 |
]. |
329461c02e84
allow for 0,1,2 arguments (update params) to be passed to interest blocks.
Claus Gittinger <cg@exept.de>
parents:
1759
diff
changeset
|
139 |
^ self onChangeSend:selector to:aBlock |
1759 | 140 |
|
141 |
" |
|
142 |
|p b| |
|
143 |
||
144 |
b := [Transcript showCR:' -> the point changed']. |
|
145 |
||
146 |
p := Point new. |
|
147 |
Transcript showCR:'interest in #foo:'. |
|
148 |
p onChangeEvaluate:b. |
|
149 |
p x:1. |
|
150 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
151 |
p changed:#bar. |
|
152 |
||
153 |
p retractInterests. |
|
154 |
p changed:#bar. |
|
155 |
" |
|
156 |
! ! |
|
157 |
||
158 |
!Object methodsFor:'dependents-interests'! |
|
159 |
||
160 |
onChangeSend:aSelector to:anObject |
|
161 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
162 |
changes." |
|
163 |
||
164 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
165 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
166 |
||
167 |
((self interests ? #()) |
|
168 |
contains:[:anInterest | |
|
169 |
(anInterest isInterestConverter) |
|
170 |
and:[ anInterest destination == anObject |
|
171 |
and:[ anInterest selector == aSelector]] |
|
172 |
]) |
|
173 |
ifTrue:[^ self]. |
|
174 |
||
175 |
self addInterest:(InterestConverter |
|
176 |
destination:anObject |
|
177 |
selector:aSelector) |
|
1668 | 178 |
|
179 |
" |
|
1759 | 180 |
|p b| |
181 |
||
182 |
b := [Transcript showCR:'the point changed']. |
|
183 |
||
184 |
p := Point new. |
|
185 |
p onChangeSend:#value to:b. |
|
186 |
p x:1. |
|
187 |
Transcript showCR:'now changing'. |
|
188 |
p changed. |
|
189 |
Transcript cr. |
|
190 |
||
191 |
Delay waitForSeconds:1. |
|
192 |
Transcript showCR:'now changing'. |
|
193 |
p changed. |
|
194 |
Transcript cr. |
|
195 |
||
196 |
Delay waitForSeconds:1. |
|
197 |
Transcript showCR:'no more interest'. |
|
198 |
p retractInterestsFor:b. |
|
199 |
Transcript showCR:'now changing again'. |
|
200 |
p changed. |
|
201 |
Transcript cr. |
|
202 |
||
203 |
Delay waitForSeconds:1. |
|
204 |
Transcript showCR:'interest again'. |
|
205 |
p onChangeSend:#value to:b. |
|
206 |
Transcript showCR:'now changing again'. |
|
207 |
p changed. |
|
208 |
Transcript cr. |
|
209 |
" |
|
210 |
||
211 |
"Created: 19.4.1996 / 10:26:38 / cg" |
|
212 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
|
213 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
|
214 |
! ! |
|
215 |
||
216 |
!Object methodsFor:'dependents-interests'! |
|
217 |
||
218 |
removeInterest:anInterest |
|
219 |
"remove an interest forwarder. |
|
220 |
Here, we use the nonWeakDependencies." |
|
221 |
||
222 |
self removeNonWeakDependent:anInterest |
|
223 |
||
224 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
225 |
! ! |
|
226 |
||
227 |
!Object methodsFor:'dependents-interests'! |
|
228 |
||
229 |
retractInterestIn:aspect for:someOne |
|
230 |
"remove the interest of someOne in the receiver changing aspect |
|
231 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
232 |
||
233 |
"/ for now, remove the interestConverter. |
|
234 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
235 |
||
236 |
self retractInterestsForWhich:[:i | (i aspect == aspect) and:[i destination == someOne]] |
|
237 |
||
1668 | 238 |
" |
1759 | 239 |
|p b| |
240 |
||
241 |
b := [Transcript showCR:'the point changed']. |
|
242 |
||
243 |
p := Point new. |
|
244 |
Transcript showCR:'interest in #foo'. |
|
245 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
246 |
p x:1. |
|
247 |
Transcript showCR:'now changing #bar'. |
|
248 |
p changed:#bar. |
|
249 |
Transcript cr. |
|
250 |
||
251 |
Delay waitForSeconds:1. |
|
252 |
Transcript showCR:'now changing #foo'. |
|
253 |
p changed:#foo. |
|
254 |
Transcript cr. |
|
255 |
||
256 |
Delay waitForSeconds:1. |
|
257 |
Transcript showCR:'no more interest in #foo'. |
|
258 |
p retractInterestIn:#foo for:b. |
|
259 |
Transcript showCR:'now changing #foo'. |
|
260 |
p changed:#foo. |
|
261 |
Transcript cr. |
|
262 |
||
263 |
Delay waitForSeconds:1. |
|
264 |
Transcript showCR:'interest in #bar now'. |
|
265 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
266 |
Transcript showCR:'now changing #foo'. |
|
267 |
p changed:#foo. |
|
268 |
Transcript showCR:'now changing #bar'. |
|
269 |
p changed:#bar. |
|
270 |
Transcript cr. |
|
271 |
||
272 |
Delay waitForSeconds:1. |
|
273 |
Transcript showCR:'interest in #foo now'. |
|
274 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
275 |
Transcript showCR:'now changing #foo'. |
|
276 |
p changed:#foo. |
|
277 |
Transcript showCR:'now changing #bar'. |
|
278 |
p changed:#bar. |
|
279 |
Transcript cr. |
|
280 |
||
281 |
Delay waitForSeconds:1. |
|
282 |
Transcript showCR:'no more interests'. |
|
283 |
p retractInterestsFor:b. |
|
284 |
Transcript showCR:'now changing #foo'. |
|
285 |
p changed:#foo. |
|
286 |
Transcript showCR:'now changing #bar'. |
|
287 |
p changed:#bar. |
|
288 |
Transcript cr. |
|
289 |
" |
|
290 |
||
291 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
292 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
293 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
294 |
! ! |
|
295 |
||
296 |
!Object methodsFor:'dependents-interests'! |
|
297 |
||
298 |
retractInterests |
|
299 |
"remove all interests in the receiver changing aspect |
|
300 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
301 |
||
302 |
"/ for now, remove the interestConverter. |
|
303 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
304 |
||
305 |
self retractInterestsForWhich:[:i | true ] |
|
306 |
! ! |
|
307 |
||
308 |
!Object methodsFor:'dependents-interests'! |
|
309 |
||
310 |
retractInterestsFor:someOne |
|
311 |
"remove the interest of someOne in the receiver |
|
312 |
(as installed with #onChangeSend:to:)." |
|
313 |
||
314 |
"/ for now, remove the interestConverter. |
|
315 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
316 |
||
317 |
self retractInterestsForWhich:[:i | i destination == someOne ] |
|
318 |
||
319 |
" |
|
320 |
|p b| |
|
321 |
||
322 |
b := [Transcript showCR:'the point changed']. |
|
323 |
||
324 |
p := Point new. |
|
325 |
p onChangeSend:#value to:b. |
|
326 |
p x:1. |
|
327 |
Transcript showCR:'now changing'. |
|
328 |
p changed. |
|
329 |
Transcript cr. |
|
330 |
||
331 |
Delay waitForSeconds:1. |
|
332 |
Transcript showCR:'now changing'. |
|
333 |
p changed. |
|
334 |
Transcript cr. |
|
335 |
||
336 |
Delay waitForSeconds:1. |
|
337 |
Transcript showCR:'no more interest'. |
|
338 |
p retractInterestsFor:b. |
|
339 |
Transcript showCR:'now changing again'. |
|
340 |
p changed. |
|
341 |
Transcript cr. |
|
342 |
||
343 |
Delay waitForSeconds:1. |
|
344 |
Transcript showCR:'interest again'. |
|
345 |
p onChangeSend:#value to:b. |
|
346 |
Transcript showCR:'now changing again'. |
|
347 |
p changed. |
|
348 |
Transcript cr. |
|
349 |
" |
|
350 |
||
351 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
352 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
353 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
354 |
! ! |
|
355 |
||
356 |
!Object methodsFor:'dependents-interests'! |
|
357 |
||
358 |
retractInterestsForWhich:aBlock |
|
359 |
"remove all interests in the receiver changing aspect |
|
360 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
361 |
||
362 |
"/ for now, remove the interestConverter. |
|
363 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
364 |
||
365 |
|deps coll| |
|
366 |
||
367 |
deps := self interests. |
|
368 |
deps size ~~ 0 ifTrue:[ |
|
369 |
"/ cannot removeDependent within the loop - the interests collection rehashes |
|
370 |
coll := OrderedCollection new. |
|
371 |
deps do:[:dep | |
|
372 |
dep isInterestConverter ifTrue:[ |
|
373 |
(aBlock value:dep) ifTrue:[coll add:dep]. |
|
374 |
] |
|
375 |
]. |
|
376 |
coll do:[:dep | |
|
377 |
self removeInterest:dep. |
|
378 |
]. |
|
379 |
]. |
|
380 |
! ! |
|
381 |
||
382 |
!Object methodsFor:'dependents-interests'! |
|
383 |
||
384 |
retractInterestsIn:aspect |
|
385 |
"remove all interests in the receiver changing aspect |
|
386 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
387 |
||
388 |
"/ for now, remove the interestConverter. |
|
389 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
390 |
||
391 |
self retractInterestsForWhich:[:i | i aspect == aspect ] |
|
1668 | 392 |
! ! |
393 |
||
394 |
!Object methodsFor:'dependents-st/v event simulation'! |
|
395 |
||
396 |
when:eventSymbol send:selector to:anObject |
|
397 |
"install an ST/V-style interest forwarder. |
|
398 |
Here, we use the nonWeakDependencies." |
|
399 |
||
400 |
self addInterest:(InterestConverterWithParameters |
|
401 |
destination:anObject |
|
402 |
selector:selector |
|
403 |
aspect:eventSymbol). |
|
404 |
||
405 |
" |
|
406 |
|p b| |
|
407 |
||
408 |
b := [Transcript showCR:'the point changed']. |
|
409 |
||
410 |
p := Point new. |
|
411 |
p whem:#foo:bar: send:#value:value: to:[:a :b | Transcript show:'foo: '; show:a; show:' bar: '; showCR:b]. |
|
412 |
Transcript showCR:'now changing'. |
|
413 |
p triggerEvent:#foo:bar: withArguments:#('fooArg' 'barArg'). |
|
414 |
p retracrtInterests. |
|
415 |
" |
|
416 |
! ! |
|
417 |