author | Stefan Vogel <sv@exept.de> |
Mon, 13 Mar 2017 09:54:33 +0100 | |
changeset 3941 | dd9237d3a727 |
parent 3613 | a134b3e2f23f |
child 3945 | 6219257414cf |
permissions | -rw-r--r-- |
145 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
158 | 3 |
All Rights Reserved |
145 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1665 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
3474 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
145 | 16 |
ValueModel subclass:#BlockValue |
17 |
instanceVariableNames:'cachedValue arguments block' |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
18 |
classVariableNames:'NeverComputed' |
145 | 19 |
poolDictionaries:'' |
20 |
category:'Interface-Support-Models' |
|
21 |
! |
|
22 |
||
23 |
!BlockValue class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
158 | 28 |
All Rights Reserved |
145 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
BlockValues depend on multiple other objects (typically valueHolders) |
|
43 |
and recompute a value whenever one of them changes. |
|
44 |
If the new value is different, it triggers itself a change to its dependents. |
|
45 |
||
46 |
Example use is to base an enableChannels value on multiple other boolean values. |
|
47 |
(See example for how this is done) |
|
223 | 48 |
|
231 | 49 |
Notice: |
50 |
this class was implemented using protocol information |
|
51 |
from alpha testers - it may not be complete or compatible to |
|
52 |
the corresponding ST-80 class. |
|
53 |
If you encounter any incompatibilities, please forward a note |
|
54 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
55 |
||
2760 | 56 |
Warning: |
57 |
BlockValues only work ine one direction; changing the blockValue's value |
|
58 |
does not affect the original model's value. |
|
59 |
||
223 | 60 |
[author:] |
61 |
Claus Gittinger |
|
145 | 62 |
" |
63 |
! |
|
64 |
||
65 |
examples |
|
66 |
" |
|
155 | 67 |
checkToggle 3 shows the value of toggle1 AND toggle2 |
231 | 68 |
[exBegin] |
69 |
|val1 val2 both box| |
|
155 | 70 |
|
231 | 71 |
val1 := false asValue. |
72 |
val2 := false asValue. |
|
73 |
both := BlockValue |
|
74 |
with:[:v1 :v2 | |
|
268 | 75 |
Transcript showCR:'evaluating ...'. |
231 | 76 |
v1 value and:[v2 value] |
77 |
] |
|
78 |
arguments:(Array with:val1 with:val2). |
|
155 | 79 |
|
231 | 80 |
box := Dialog new. |
81 |
box addCheckBox:'one' on:val1. |
|
82 |
box addCheckBox:'two' on:val2. |
|
83 |
box addHorizontalLine. |
|
84 |
box addCheckBox:'both' on:both. |
|
911 | 85 |
box addOkButton. |
231 | 86 |
box open |
87 |
[exEnd] |
|
155 | 88 |
|
89 |
the same, using a convenient instance creation message: |
|
231 | 90 |
[exBegin] |
91 |
|val1 val2 both box| |
|
155 | 92 |
|
231 | 93 |
val1 := false asValue. |
94 |
val2 := false asValue. |
|
95 |
both := BlockValue forLogical:val1 and:val2. |
|
145 | 96 |
|
231 | 97 |
box := Dialog new. |
98 |
box addCheckBox:'one' on:val1. |
|
99 |
box addCheckBox:'two' on:val2. |
|
100 |
box addHorizontalLine. |
|
911 | 101 |
(box addCheckBox:'both' on:both) disable. |
102 |
box addOkButton. |
|
231 | 103 |
box open |
104 |
[exEnd] |
|
155 | 105 |
|
106 |
logical or: |
|
231 | 107 |
[exBegin] |
108 |
|val1 val2 both box| |
|
155 | 109 |
|
231 | 110 |
val1 := false asValue. |
111 |
val2 := false asValue. |
|
112 |
both := BlockValue forLogical:val1 or:val2. |
|
145 | 113 |
|
231 | 114 |
box := Dialog new. |
115 |
box addCheckBox:'one' on:val1. |
|
116 |
box addCheckBox:'two' on:val2. |
|
117 |
box addHorizontalLine. |
|
118 |
box addCheckBox:'both' on:both. |
|
911 | 119 |
box addOkButton. |
231 | 120 |
box open |
121 |
[exEnd] |
|
155 | 122 |
|
123 |
example use: enabling an element depending on two others: |
|
231 | 124 |
[exBegin] |
125 |
|val1 val2 enabler val3 box| |
|
155 | 126 |
|
231 | 127 |
val1 := false asValue. |
128 |
val2 := false asValue. |
|
129 |
val3 := false asValue. |
|
130 |
enabler := BlockValue forLogical:val1 and:val2. |
|
155 | 131 |
|
231 | 132 |
box := Dialog new. |
133 |
box addCheckBox:'one' on:val1. |
|
134 |
box addCheckBox:'two' on:val2. |
|
135 |
box addHorizontalLine. |
|
911 | 136 |
(box addCheckBox:'three (both of the above)' on:val3) enableChannel:enabler. |
137 |
box addOkButton. |
|
231 | 138 |
box open |
139 |
[exEnd] |
|
382 | 140 |
|
141 |
||
142 |
like above, using a logical-or block: |
|
143 |
[exBegin] |
|
144 |
|val1 val2 enabler val3 box| |
|
145 |
||
146 |
val1 := false asValue. |
|
147 |
val2 := false asValue. |
|
148 |
val3 := false asValue. |
|
149 |
enabler := BlockValue forLogical:val1 or:val2. |
|
150 |
||
151 |
box := Dialog new. |
|
152 |
box addCheckBox:'one' on:val1. |
|
153 |
box addCheckBox:'two' on:val2. |
|
154 |
box addHorizontalLine. |
|
911 | 155 |
(box addCheckBox:'three (any of the above)' on:val3) enableChannel:enabler. |
156 |
box addOkButton. |
|
382 | 157 |
box open |
158 |
[exEnd] |
|
159 |
||
160 |
||
161 |
like above, using a bunch of toggles: |
|
162 |
[exBegin] |
|
163 |
|values anyValue box| |
|
164 |
||
165 |
values := (1 to:10) collect:[:i | false asValue]. |
|
166 |
anyValue := BlockValue forLogicalOrAll:values. |
|
167 |
anyValue onChangeSend:#value to:[Transcript showCR:'any is true']. |
|
168 |
||
169 |
box := Dialog new. |
|
170 |
values keysAndValuesDo:[:index :aValueHolder | |
|
171 |
box addCheckBox:index printString on:aValueHolder. |
|
172 |
]. |
|
173 |
box addHorizontalLine. |
|
911 | 174 |
(box addOkButton) enableChannel:anyValue. |
382 | 175 |
box open |
176 |
[exEnd] |
|
145 | 177 |
" |
178 |
! ! |
|
179 |
||
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
180 |
!BlockValue class methodsFor:'initialization'! |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
181 |
|
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
182 |
initialize |
158 | 183 |
NeverComputed isNil ifTrue:[ |
184 |
NeverComputed := Object new. |
|
185 |
] |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
186 |
! ! |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
187 |
|
145 | 188 |
!BlockValue class methodsFor:'instance creation'! |
189 |
||
979
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
190 |
block:aBlock arguments:aCollectionOfArguments |
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
191 |
"return a new BlockValue computing aBlock. |
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
192 |
Same as #with:arguments: for ST80 compatibility" |
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
193 |
|
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
194 |
^ self with:aBlock arguments:aCollectionOfArguments |
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
195 |
|
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
196 |
"Created: / 20.6.1998 / 14:00:16 / cg" |
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
197 |
! |
cd28a5d673c9
added #block:arguments: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
911
diff
changeset
|
198 |
|
155 | 199 |
forLogical:arg1 and:arg2 |
1326 | 200 |
"return a new BlockValue computing the logical AND of its args |
201 |
(which are usually other valueHolders)" |
|
155 | 202 |
|
1815 | 203 |
^ (self new) |
1326 | 204 |
setBlock:[:a :b | a value and:[b value]] |
205 |
arguments:(Array with:arg1 with:arg2) |
|
155 | 206 |
|
1326 | 207 |
"Created: / 16.12.1995 / 19:20:14 / cg" |
208 |
"Modified: / 30.1.2000 / 23:24:50 / cg" |
|
155 | 209 |
! |
210 |
||
2800 | 211 |
forLogical:arg1 and:arg2 and:arg3 |
212 |
"return a new BlockValue computing the logical AND of its args |
|
213 |
(which are usually other valueHolders)" |
|
214 |
||
215 |
^ (self new) |
|
216 |
setBlock:[:a :b :c | a value and:[b value and:[c value]]] |
|
217 |
arguments:(Array with:arg1 with:arg2 with:arg3) |
|
218 |
! |
|
219 |
||
155 | 220 |
forLogical:arg1 or:arg2 |
1326 | 221 |
"return a new BlockValue computing the logical OR of its args |
222 |
(which are usually other valueHolders)" |
|
155 | 223 |
|
1815 | 224 |
^ (self new) |
1326 | 225 |
setBlock:[:a :b | a value or:[b value]] |
226 |
arguments:(Array with:arg1 with:arg2) |
|
155 | 227 |
|
1326 | 228 |
"Created: / 16.12.1995 / 19:20:14 / cg" |
229 |
"Modified: / 30.1.2000 / 23:24:46 / cg" |
|
155 | 230 |
! |
231 |
||
2800 | 232 |
forLogical:arg1 or:arg2 or:arg3 |
233 |
"return a new BlockValue computing the logical OR of its args |
|
234 |
(which are usually other valueHolders)" |
|
235 |
||
236 |
^ (self new) |
|
237 |
setBlock:[:a :b :c | a value or:[b value or:[c value]]] |
|
238 |
arguments:(Array with:arg1 with:arg2 with:arg3) |
|
239 |
! |
|
240 |
||
382 | 241 |
forLogicalAndAll:argArray |
3474 | 242 |
"return a new BlockValue computing the logical AND of all elements |
1326 | 243 |
in the passed argArray (which are usually other valueHolders)" |
382 | 244 |
|
1815 | 245 |
^ (self new) |
382 | 246 |
setBlock:[:a | (argArray findFirst:[:a | a value not]) == 0] |
911 | 247 |
argumentArray:argArray asArray |
382 | 248 |
|
911 | 249 |
"Created: / 22.1.1997 / 19:12:44 / cg" |
250 |
"Modified: / 28.4.1998 / 20:16:38 / ca" |
|
1326 | 251 |
"Modified: / 30.1.2000 / 23:24:40 / cg" |
382 | 252 |
! |
253 |
||
1045 | 254 |
forLogicalNot:arg |
1326 | 255 |
"return a new BlockValue computing the logical NOT of its arg |
256 |
(which is usually another valueHolder)" |
|
1045 | 257 |
|
1815 | 258 |
^ (self new) |
1045 | 259 |
setBlock:[:a | a value not] |
260 |
arguments:(Array with:arg) |
|
261 |
||
3349 | 262 |
" |
263 |
|v1 v2| |
|
264 |
||
265 |
v1 := ValueHolder new. |
|
266 |
v1 value:true. |
|
267 |
||
268 |
v2 := BlockValue forLogicalNot:v1. |
|
269 |
v2 onChangeEvaluate:[ Transcript showCR:v2 value]. |
|
270 |
Transcript showCR:v2 value. 'shows a false already'. |
|
271 |
||
272 |
v1 value:true. 'no change signalled here'. |
|
273 |
v1 value:false. |
|
274 |
v1 value:true. |
|
275 |
" |
|
276 |
||
1045 | 277 |
"Created: / 17.8.1998 / 10:06:41 / cg" |
1326 | 278 |
"Modified: / 30.1.2000 / 23:24:18 / cg" |
1045 | 279 |
! |
280 |
||
382 | 281 |
forLogicalOrAll:argArray |
282 |
"return a new BlockValue computing the logical OR of all elements |
|
1326 | 283 |
in the passed argArray (which are usually other valueHolders)" |
382 | 284 |
|
1815 | 285 |
^ (self new) |
606 | 286 |
setBlock:[:arg | (arg findFirst:[:el | el value]) ~~ 0] |
911 | 287 |
argumentArray:argArray asArray |
382 | 288 |
|
911 | 289 |
"Created: / 22.1.1997 / 19:13:01 / cg" |
290 |
"Modified: / 28.4.1998 / 20:20:09 / ca" |
|
1326 | 291 |
"Modified: / 30.1.2000 / 23:24:34 / cg" |
382 | 292 |
! |
293 |
||
3349 | 294 |
forValue:someValue equalTo:someConstant |
295 |
"return a new BlockValue generating a true, |
|
296 |
if someValue (usually another holder) contains a value equal to someConstant. |
|
297 |
Useful, if the other valueHolder is a radioButton group model, |
|
298 |
and you want to automatically enable/disable other items based on the value |
|
299 |
(i.e. via the enableChannel)" |
|
300 |
||
301 |
^ (self new) |
|
302 |
setBlock:[:a | a = someConstant] |
|
303 |
arguments:(Array with:someValue) |
|
304 |
||
305 |
" |
|
306 |
|v1 v2| |
|
307 |
||
308 |
v1 := ValueHolder new. |
|
309 |
v1 value:'blah'. |
|
310 |
||
311 |
v2 := BlockValue forValue:v1 equalTo:'hello'. |
|
312 |
v2 onChangeEvaluate:[ Transcript showCR:v2 value]. |
|
313 |
Transcript showCR:v2 value. 'shows a false already'. |
|
314 |
||
315 |
v1 value:'blah'. 'no change signalled here'. |
|
316 |
v1 value:'oops'. 'remains false'. |
|
317 |
v1 value:'hello'. 'changes to true'. |
|
318 |
v2 value |
|
319 |
" |
|
320 |
! |
|
321 |
||
145 | 322 |
with:aBlock |
323 |
"return a new BlockValue computing aBlock" |
|
324 |
||
1815 | 325 |
^ (self new) setBlock:aBlock |
145 | 326 |
|
327 |
"Created: 16.12.1995 / 19:16:33 / cg" |
|
328 |
! |
|
329 |
||
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
330 |
with:aBlock argument:anArgument |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
331 |
"return a new BlockValue computing aBlock" |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
332 |
|
1815 | 333 |
^ (self new) |
1352 | 334 |
setBlock:aBlock |
335 |
arguments:(Array with:anArgument) |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
336 |
|
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
337 |
"Created: 16.12.1995 / 19:20:14 / cg" |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
338 |
! |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
339 |
|
1255 | 340 |
with:aBlock argument:anArgument1 argument:anArgument2 |
341 |
"return a new BlockValue computing aBlock" |
|
342 |
||
1815 | 343 |
^ (self new) |
1352 | 344 |
setBlock:aBlock |
345 |
arguments:(Array with:anArgument1 with:anArgument2) |
|
1255 | 346 |
|
347 |
"Created: 16.12.1995 / 19:20:14 / cg" |
|
348 |
! |
|
349 |
||
1352 | 350 |
with:aBlock argument:anArgument1 argument:anArgument2 argument:anArgument3 |
351 |
"return a new BlockValue computing aBlock" |
|
352 |
||
1815 | 353 |
^ (self new) |
1352 | 354 |
setBlock:aBlock |
355 |
arguments:(Array with:anArgument1 with:anArgument2 with:anArgument3) |
|
1815 | 356 |
! |
1352 | 357 |
|
1815 | 358 |
with:aBlock argument:anArgument1 argument:anArgument2 argument:anArgument3 argument:anArgument4 |
359 |
"return a new BlockValue computing aBlock" |
|
360 |
||
361 |
^ (self new) |
|
362 |
setBlock:aBlock |
|
363 |
arguments:(Array with:anArgument1 with:anArgument2 with:anArgument3 with:anArgument4) |
|
1352 | 364 |
! |
365 |
||
145 | 366 |
with:aBlock arguments:aCollectionOfArguments |
367 |
"return a new BlockValue computing aBlock" |
|
368 |
||
1815 | 369 |
^ (self new) |
1352 | 370 |
setBlock:aBlock |
371 |
arguments:aCollectionOfArguments |
|
145 | 372 |
|
373 |
"Created: 16.12.1995 / 19:20:14 / cg" |
|
374 |
! ! |
|
375 |
||
376 |
!BlockValue methodsFor:'accessing'! |
|
377 |
||
378 |
setBlock:aBlock |
|
3613 | 379 |
"set the receiver's action block" |
382 | 380 |
|
145 | 381 |
block := aBlock. |
382 |
arguments notNil ifTrue:[ |
|
382 | 383 |
self release |
145 | 384 |
]. |
385 |
arguments := nil. |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
386 |
cachedValue := NeverComputed. |
145 | 387 |
|
388 |
"Created: 16.12.1995 / 19:16:59 / cg" |
|
382 | 389 |
"Modified: 22.1.1997 / 19:05:54 / cg" |
390 |
! |
|
391 |
||
392 |
setBlock:aBlock argumentArray:anArgumentCollection |
|
3613 | 393 |
"set the receiver's action block, and define an arguments collection |
382 | 394 |
to be passed to it. |
395 |
A change in any element of the collection will force reevaluation of the |
|
396 |
action block (passing the collection as a single argument) |
|
397 |
- possibly generating another change from myself" |
|
398 |
||
399 |
block := aBlock. |
|
400 |
arguments notNil ifTrue:[ |
|
401 |
self release |
|
402 |
]. |
|
403 |
arguments := Array with:anArgumentCollection. |
|
404 |
anArgumentCollection do:[:arg | |
|
2530 | 405 |
arg notNil ifTrue:[ |
406 |
arg addDependent:self |
|
407 |
]. |
|
382 | 408 |
]. |
409 |
cachedValue := NeverComputed. |
|
410 |
||
411 |
"Modified: 22.1.1997 / 19:08:51 / cg" |
|
412 |
"Created: 22.1.1997 / 19:22:13 / cg" |
|
145 | 413 |
! |
414 |
||
415 |
setBlock:aBlock arguments:aCollectionOfArguments |
|
3613 | 416 |
"set the receiver's action block, and define arguments to be passed to it. |
382 | 417 |
A change in any of the arguments will force reevaluation of the action |
418 |
block - possibly generating another change from myself" |
|
419 |
||
145 | 420 |
block := aBlock. |
421 |
arguments notNil ifTrue:[ |
|
382 | 422 |
self release |
145 | 423 |
]. |
424 |
arguments := aCollectionOfArguments. |
|
425 |
arguments do:[:arg | |
|
2530 | 426 |
"arg maybe some constant..." |
427 |
arg notNil ifTrue:[ |
|
428 |
arg addDependent:self |
|
429 |
]. |
|
145 | 430 |
]. |
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
431 |
cachedValue := NeverComputed. |
145 | 432 |
|
433 |
"Created: 16.12.1995 / 19:21:41 / cg" |
|
382 | 434 |
"Modified: 22.1.1997 / 19:08:51 / cg" |
145 | 435 |
! |
436 |
||
155 | 437 |
setValue:newValue |
438 |
"physically set my value, without change notifications. |
|
439 |
This is a noop here, since my value is computed." |
|
440 |
||
441 |
^ self |
|
442 |
||
443 |
||
444 |
! |
|
445 |
||
145 | 446 |
value |
382 | 447 |
"retrieve my value - this does not always evaluate the action block, |
448 |
since the returned value is cached internally" |
|
449 |
||
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
450 |
cachedValue == NeverComputed ifTrue:[ |
491 | 451 |
cachedValue := self computeValue |
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
452 |
]. |
145 | 453 |
^ cachedValue |
454 |
||
455 |
"Created: 16.12.1995 / 19:23:26 / cg" |
|
382 | 456 |
"Modified: 22.1.1997 / 19:06:59 / cg" |
145 | 457 |
! ! |
458 |
||
347 | 459 |
!BlockValue methodsFor:'change & update'! |
145 | 460 |
|
1788 | 461 |
recomputeValue |
462 |
"reevaluate my actionBlock, and possibly send a change notification to my dependents" |
|
382 | 463 |
|
145 | 464 |
|oldValue| |
465 |
||
466 |
oldValue := cachedValue. |
|
491 | 467 |
cachedValue := self computeValue. |
145 | 468 |
oldValue ~~ cachedValue ifTrue:[ |
382 | 469 |
self changed:#value |
145 | 470 |
]. |
1788 | 471 |
! |
472 |
||
473 |
update:something with:aParameter from:someone |
|
474 |
"the one I depend on has changed - reevaluate my actionBlock, |
|
475 |
and possibly send a change notification to my dependents" |
|
476 |
||
477 |
self recomputeValue |
|
145 | 478 |
|
479 |
"Created: 16.12.1995 / 19:22:54 / cg" |
|
382 | 480 |
"Modified: 22.1.1997 / 19:07:39 / cg" |
145 | 481 |
! ! |
482 |
||
2985 | 483 |
!BlockValue methodsFor:'dependents access'! |
484 |
||
485 |
release |
|
486 |
"release any dependencies upon the arguments" |
|
487 |
||
488 |
arguments notNil ifTrue:[ |
|
489 |
arguments do:[:arg | arg removeDependent:self]. |
|
490 |
]. |
|
3291 | 491 |
super release |
2985 | 492 |
|
493 |
"Modified: 22.1.1997 / 19:08:06 / cg" |
|
494 |
! ! |
|
495 |
||
1788 | 496 |
!BlockValue methodsFor:'misc'! |
497 |
||
498 |
computeValue |
|
3613 | 499 |
"evaluate the receiver's action block" |
1788 | 500 |
|
501 |
|sz arg1 arg2 argValues| |
|
502 |
||
503 |
arguments isNil ifTrue:[ |
|
504 |
^ block value |
|
505 |
]. |
|
506 |
sz := arguments size. |
|
507 |
sz == 0 ifTrue:[ |
|
508 |
^ block value |
|
509 |
]. |
|
510 |
arg1 := (arguments at:1) value. |
|
511 |
sz == 1 ifTrue:[ |
|
512 |
^ block value:arg1 |
|
513 |
]. |
|
514 |
arg2 := (arguments at:2) value. |
|
515 |
sz == 2 ifTrue:[ |
|
516 |
^ block value:arg1 value:arg2 |
|
517 |
]. |
|
518 |
"/ do not evaluate arg[1-2] twice |
|
519 |
argValues := Array new:arguments size. |
|
520 |
argValues at:1 put:arg1. "/ do not evaluate twice |
|
521 |
argValues at:2 put:arg2. "/ do not evaluate twice |
|
522 |
3 to:arguments size do:[:i | argValues at:i put:(arguments at:i) value]. |
|
523 |
||
524 |
^ block valueWithArguments:argValues |
|
525 |
||
526 |
"Created: 16.12.1995 / 19:27:40 / cg" |
|
527 |
"Modified: 22.1.1997 / 19:05:57 / cg" |
|
528 |
! |
|
529 |
||
530 |
dependOn:someObject |
|
531 |
"arrange for the blockValue to be reevaluated, whenever someObject |
|
532 |
changes (i.e. sends a change notification)" |
|
533 |
||
534 |
arguments isNil ifTrue:[ |
|
535 |
arguments := Array with:someObject |
|
536 |
] ifFalse:[ |
|
537 |
arguments := arguments copyWith:someObject |
|
538 |
]. |
|
539 |
someObject addDependent:self |
|
540 |
||
541 |
"Modified: 22.1.1997 / 19:05:26 / cg" |
|
542 |
! |
|
543 |
||
544 |
resetValue |
|
3613 | 545 |
"evaluate the receiver's action block" |
1788 | 546 |
|
547 |
cachedValue := self computeValue |
|
548 |
! ! |
|
549 |
||
145 | 550 |
!BlockValue class methodsFor:'documentation'! |
551 |
||
552 |
version |
|
3613 | 553 |
^ '$Header$' |
2760 | 554 |
! |
555 |
||
556 |
version_CVS |
|
3613 | 557 |
^ '$Header$' |
145 | 558 |
! ! |
1665 | 559 |
|
3291 | 560 |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
561 |
BlockValue initialize! |