author | mawalch |
Tue, 23 May 2017 16:16:26 +0200 | |
changeset 3957 | c7db19dbd128 |
parent 3946 | 3aa94b58d2b0 |
child 4242 | dee79356dad2 |
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 |
||
3945 | 378 |
setArguments:aCollectionOfArguments |
379 |
"set the receiver's arguments to be passed to it. |
|
380 |
A change in any of the arguments will force reevaluation of the action |
|
381 |
block - possibly generating another change from myself" |
|
382 |
||
383 |
arguments notNil ifTrue:[ |
|
3946 | 384 |
arguments do:[:arg | arg removeDependent:self]. |
3945 | 385 |
]. |
386 |
arguments := aCollectionOfArguments. |
|
387 |
arguments do:[:arg | |
|
388 |
"arg maybe some constant..." |
|
389 |
arg notNil ifTrue:[ |
|
390 |
arg addDependent:self |
|
391 |
]. |
|
392 |
]. |
|
393 |
self recomputeValue. |
|
394 |
||
395 |
"Created: / 30-03-2017 / 14:00:27 / stefan" |
|
3946 | 396 |
"Modified: / 31-03-2017 / 16:28:39 / stefan" |
3945 | 397 |
! |
398 |
||
145 | 399 |
setBlock:aBlock |
3613 | 400 |
"set the receiver's action block" |
382 | 401 |
|
145 | 402 |
block := aBlock. |
403 |
arguments notNil ifTrue:[ |
|
382 | 404 |
self release |
145 | 405 |
]. |
406 |
arguments := nil. |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
407 |
cachedValue := NeverComputed. |
145 | 408 |
|
409 |
"Created: 16.12.1995 / 19:16:59 / cg" |
|
382 | 410 |
"Modified: 22.1.1997 / 19:05:54 / cg" |
411 |
! |
|
412 |
||
413 |
setBlock:aBlock argumentArray:anArgumentCollection |
|
3613 | 414 |
"set the receiver's action block, and define an arguments collection |
382 | 415 |
to be passed to it. |
416 |
A change in any element of the collection will force reevaluation of the |
|
417 |
action block (passing the collection as a single argument) |
|
418 |
- possibly generating another change from myself" |
|
419 |
||
420 |
block := aBlock. |
|
421 |
arguments notNil ifTrue:[ |
|
422 |
self release |
|
423 |
]. |
|
424 |
arguments := Array with:anArgumentCollection. |
|
425 |
anArgumentCollection do:[:arg | |
|
2530 | 426 |
arg notNil ifTrue:[ |
427 |
arg addDependent:self |
|
428 |
]. |
|
382 | 429 |
]. |
430 |
cachedValue := NeverComputed. |
|
431 |
||
432 |
"Modified: 22.1.1997 / 19:08:51 / cg" |
|
433 |
"Created: 22.1.1997 / 19:22:13 / cg" |
|
145 | 434 |
! |
435 |
||
436 |
setBlock:aBlock arguments:aCollectionOfArguments |
|
3613 | 437 |
"set the receiver's action block, and define arguments to be passed to it. |
382 | 438 |
A change in any of the arguments will force reevaluation of the action |
439 |
block - possibly generating another change from myself" |
|
440 |
||
145 | 441 |
block := aBlock. |
442 |
arguments notNil ifTrue:[ |
|
382 | 443 |
self release |
145 | 444 |
]. |
445 |
arguments := aCollectionOfArguments. |
|
446 |
arguments do:[:arg | |
|
2530 | 447 |
"arg maybe some constant..." |
448 |
arg notNil ifTrue:[ |
|
449 |
arg addDependent:self |
|
450 |
]. |
|
145 | 451 |
]. |
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
452 |
cachedValue := NeverComputed. |
145 | 453 |
|
454 |
"Created: 16.12.1995 / 19:21:41 / cg" |
|
382 | 455 |
"Modified: 22.1.1997 / 19:08:51 / cg" |
145 | 456 |
! |
457 |
||
155 | 458 |
setValue:newValue |
459 |
"physically set my value, without change notifications. |
|
460 |
This is a noop here, since my value is computed." |
|
461 |
||
462 |
^ self |
|
463 |
||
464 |
||
465 |
! |
|
466 |
||
145 | 467 |
value |
382 | 468 |
"retrieve my value - this does not always evaluate the action block, |
469 |
since the returned value is cached internally" |
|
470 |
||
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
471 |
cachedValue == NeverComputed ifTrue:[ |
491 | 472 |
cachedValue := self computeValue |
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
473 |
]. |
145 | 474 |
^ cachedValue |
475 |
||
476 |
"Created: 16.12.1995 / 19:23:26 / cg" |
|
382 | 477 |
"Modified: 22.1.1997 / 19:06:59 / cg" |
145 | 478 |
! ! |
479 |
||
347 | 480 |
!BlockValue methodsFor:'change & update'! |
145 | 481 |
|
1788 | 482 |
recomputeValue |
483 |
"reevaluate my actionBlock, and possibly send a change notification to my dependents" |
|
382 | 484 |
|
145 | 485 |
|oldValue| |
486 |
||
487 |
oldValue := cachedValue. |
|
491 | 488 |
cachedValue := self computeValue. |
145 | 489 |
oldValue ~~ cachedValue ifTrue:[ |
382 | 490 |
self changed:#value |
145 | 491 |
]. |
1788 | 492 |
! |
493 |
||
494 |
update:something with:aParameter from:someone |
|
495 |
"the one I depend on has changed - reevaluate my actionBlock, |
|
496 |
and possibly send a change notification to my dependents" |
|
497 |
||
498 |
self recomputeValue |
|
145 | 499 |
|
500 |
"Created: 16.12.1995 / 19:22:54 / cg" |
|
382 | 501 |
"Modified: 22.1.1997 / 19:07:39 / cg" |
145 | 502 |
! ! |
503 |
||
2985 | 504 |
!BlockValue methodsFor:'dependents access'! |
505 |
||
506 |
release |
|
507 |
"release any dependencies upon the arguments" |
|
508 |
||
509 |
arguments notNil ifTrue:[ |
|
510 |
arguments do:[:arg | arg removeDependent:self]. |
|
511 |
]. |
|
3291 | 512 |
super release |
2985 | 513 |
|
514 |
"Modified: 22.1.1997 / 19:08:06 / cg" |
|
515 |
! ! |
|
516 |
||
1788 | 517 |
!BlockValue methodsFor:'misc'! |
518 |
||
519 |
computeValue |
|
3613 | 520 |
"evaluate the receiver's action block" |
1788 | 521 |
|
522 |
|sz arg1 arg2 argValues| |
|
523 |
||
524 |
arguments isNil ifTrue:[ |
|
525 |
^ block value |
|
526 |
]. |
|
527 |
sz := arguments size. |
|
528 |
sz == 0 ifTrue:[ |
|
529 |
^ block value |
|
530 |
]. |
|
531 |
arg1 := (arguments at:1) value. |
|
532 |
sz == 1 ifTrue:[ |
|
533 |
^ block value:arg1 |
|
534 |
]. |
|
535 |
arg2 := (arguments at:2) value. |
|
536 |
sz == 2 ifTrue:[ |
|
537 |
^ block value:arg1 value:arg2 |
|
538 |
]. |
|
539 |
"/ do not evaluate arg[1-2] twice |
|
540 |
argValues := Array new:arguments size. |
|
541 |
argValues at:1 put:arg1. "/ do not evaluate twice |
|
542 |
argValues at:2 put:arg2. "/ do not evaluate twice |
|
543 |
3 to:arguments size do:[:i | argValues at:i put:(arguments at:i) value]. |
|
544 |
||
545 |
^ block valueWithArguments:argValues |
|
546 |
||
547 |
"Created: 16.12.1995 / 19:27:40 / cg" |
|
548 |
"Modified: 22.1.1997 / 19:05:57 / cg" |
|
549 |
! |
|
550 |
||
551 |
dependOn:someObject |
|
552 |
"arrange for the blockValue to be reevaluated, whenever someObject |
|
553 |
changes (i.e. sends a change notification)" |
|
554 |
||
555 |
arguments isNil ifTrue:[ |
|
556 |
arguments := Array with:someObject |
|
557 |
] ifFalse:[ |
|
558 |
arguments := arguments copyWith:someObject |
|
559 |
]. |
|
560 |
someObject addDependent:self |
|
561 |
||
562 |
"Modified: 22.1.1997 / 19:05:26 / cg" |
|
563 |
! |
|
564 |
||
565 |
resetValue |
|
3613 | 566 |
"evaluate the receiver's action block" |
1788 | 567 |
|
568 |
cachedValue := self computeValue |
|
569 |
! ! |
|
570 |
||
145 | 571 |
!BlockValue class methodsFor:'documentation'! |
572 |
||
573 |
version |
|
3613 | 574 |
^ '$Header$' |
2760 | 575 |
! |
576 |
||
577 |
version_CVS |
|
3613 | 578 |
^ '$Header$' |
145 | 579 |
! ! |
1665 | 580 |
|
3291 | 581 |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
582 |
BlockValue initialize! |