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