author | Claus Gittinger <cg@exept.de> |
Tue, 18 Mar 2014 16:14:17 +0100 | |
changeset 3314 | 552383bb5952 |
parent 3291 | 8690be2779fc |
child 3349 | ffebc3c4e212 |
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 |
||
260 |
"Created: / 17.8.1998 / 10:06:41 / cg" |
|
1326 | 261 |
"Modified: / 30.1.2000 / 23:24:18 / cg" |
1045 | 262 |
! |
263 |
||
382 | 264 |
forLogicalOrAll:argArray |
265 |
"return a new BlockValue computing the logical OR of all elements |
|
1326 | 266 |
in the passed argArray (which are usually other valueHolders)" |
382 | 267 |
|
1815 | 268 |
^ (self new) |
606 | 269 |
setBlock:[:arg | (arg findFirst:[:el | el value]) ~~ 0] |
911 | 270 |
argumentArray:argArray asArray |
382 | 271 |
|
911 | 272 |
"Created: / 22.1.1997 / 19:13:01 / cg" |
273 |
"Modified: / 28.4.1998 / 20:20:09 / ca" |
|
1326 | 274 |
"Modified: / 30.1.2000 / 23:24:34 / cg" |
382 | 275 |
! |
276 |
||
145 | 277 |
with:aBlock |
278 |
"return a new BlockValue computing aBlock" |
|
279 |
||
1815 | 280 |
^ (self new) setBlock:aBlock |
145 | 281 |
|
282 |
"Created: 16.12.1995 / 19:16:33 / cg" |
|
283 |
! |
|
284 |
||
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
285 |
with:aBlock argument:anArgument |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
286 |
"return a new BlockValue computing aBlock" |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
287 |
|
1815 | 288 |
^ (self new) |
1352 | 289 |
setBlock:aBlock |
290 |
arguments:(Array with:anArgument) |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
291 |
|
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
292 |
"Created: 16.12.1995 / 19:20:14 / cg" |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
293 |
! |
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
294 |
|
1255 | 295 |
with:aBlock argument:anArgument1 argument:anArgument2 |
296 |
"return a new BlockValue computing aBlock" |
|
297 |
||
1815 | 298 |
^ (self new) |
1352 | 299 |
setBlock:aBlock |
300 |
arguments:(Array with:anArgument1 with:anArgument2) |
|
1255 | 301 |
|
302 |
"Created: 16.12.1995 / 19:20:14 / cg" |
|
303 |
! |
|
304 |
||
1352 | 305 |
with:aBlock argument:anArgument1 argument:anArgument2 argument:anArgument3 |
306 |
"return a new BlockValue computing aBlock" |
|
307 |
||
1815 | 308 |
^ (self new) |
1352 | 309 |
setBlock:aBlock |
310 |
arguments:(Array with:anArgument1 with:anArgument2 with:anArgument3) |
|
1815 | 311 |
! |
1352 | 312 |
|
1815 | 313 |
with:aBlock argument:anArgument1 argument:anArgument2 argument:anArgument3 argument:anArgument4 |
314 |
"return a new BlockValue computing aBlock" |
|
315 |
||
316 |
^ (self new) |
|
317 |
setBlock:aBlock |
|
318 |
arguments:(Array with:anArgument1 with:anArgument2 with:anArgument3 with:anArgument4) |
|
1352 | 319 |
! |
320 |
||
145 | 321 |
with:aBlock arguments:aCollectionOfArguments |
322 |
"return a new BlockValue computing aBlock" |
|
323 |
||
1815 | 324 |
^ (self new) |
1352 | 325 |
setBlock:aBlock |
326 |
arguments:aCollectionOfArguments |
|
145 | 327 |
|
328 |
"Created: 16.12.1995 / 19:20:14 / cg" |
|
329 |
! ! |
|
330 |
||
331 |
!BlockValue methodsFor:'accessing'! |
|
332 |
||
333 |
setBlock:aBlock |
|
382 | 334 |
"set the receivers action block" |
335 |
||
145 | 336 |
block := aBlock. |
337 |
arguments notNil ifTrue:[ |
|
382 | 338 |
self release |
145 | 339 |
]. |
340 |
arguments := nil. |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
341 |
cachedValue := NeverComputed. |
145 | 342 |
|
343 |
"Created: 16.12.1995 / 19:16:59 / cg" |
|
382 | 344 |
"Modified: 22.1.1997 / 19:05:54 / cg" |
345 |
! |
|
346 |
||
347 |
setBlock:aBlock argumentArray:anArgumentCollection |
|
348 |
"set the receivers action block, and define an arguments collection |
|
349 |
to be passed to it. |
|
350 |
A change in any element of the collection will force reevaluation of the |
|
351 |
action block (passing the collection as a single argument) |
|
352 |
- possibly generating another change from myself" |
|
353 |
||
354 |
block := aBlock. |
|
355 |
arguments notNil ifTrue:[ |
|
356 |
self release |
|
357 |
]. |
|
358 |
arguments := Array with:anArgumentCollection. |
|
359 |
anArgumentCollection do:[:arg | |
|
2530 | 360 |
arg notNil ifTrue:[ |
361 |
arg addDependent:self |
|
362 |
]. |
|
382 | 363 |
]. |
364 |
cachedValue := NeverComputed. |
|
365 |
||
366 |
"Modified: 22.1.1997 / 19:08:51 / cg" |
|
367 |
"Created: 22.1.1997 / 19:22:13 / cg" |
|
145 | 368 |
! |
369 |
||
370 |
setBlock:aBlock arguments:aCollectionOfArguments |
|
382 | 371 |
"set the receivers action block, and define arguments to be passed to it. |
372 |
A change in any of the arguments will force reevaluation of the action |
|
373 |
block - possibly generating another change from myself" |
|
374 |
||
145 | 375 |
block := aBlock. |
376 |
arguments notNil ifTrue:[ |
|
382 | 377 |
self release |
145 | 378 |
]. |
379 |
arguments := aCollectionOfArguments. |
|
380 |
arguments do:[:arg | |
|
2530 | 381 |
"arg maybe some constant..." |
382 |
arg notNil ifTrue:[ |
|
383 |
arg addDependent:self |
|
384 |
]. |
|
145 | 385 |
]. |
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:21:41 / cg" |
|
382 | 389 |
"Modified: 22.1.1997 / 19:08:51 / cg" |
145 | 390 |
! |
391 |
||
155 | 392 |
setValue:newValue |
393 |
"physically set my value, without change notifications. |
|
394 |
This is a noop here, since my value is computed." |
|
395 |
||
396 |
^ self |
|
397 |
||
398 |
||
399 |
! |
|
400 |
||
145 | 401 |
value |
382 | 402 |
"retrieve my value - this does not always evaluate the action block, |
403 |
since the returned value is cached internally" |
|
404 |
||
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
405 |
cachedValue == NeverComputed ifTrue:[ |
491 | 406 |
cachedValue := self computeValue |
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
407 |
]. |
145 | 408 |
^ cachedValue |
409 |
||
410 |
"Created: 16.12.1995 / 19:23:26 / cg" |
|
382 | 411 |
"Modified: 22.1.1997 / 19:06:59 / cg" |
145 | 412 |
! ! |
413 |
||
347 | 414 |
!BlockValue methodsFor:'change & update'! |
145 | 415 |
|
1788 | 416 |
recomputeValue |
417 |
"reevaluate my actionBlock, and possibly send a change notification to my dependents" |
|
382 | 418 |
|
145 | 419 |
|oldValue| |
420 |
||
421 |
oldValue := cachedValue. |
|
491 | 422 |
cachedValue := self computeValue. |
145 | 423 |
oldValue ~~ cachedValue ifTrue:[ |
382 | 424 |
self changed:#value |
145 | 425 |
]. |
1788 | 426 |
! |
427 |
||
428 |
update:something with:aParameter from:someone |
|
429 |
"the one I depend on has changed - reevaluate my actionBlock, |
|
430 |
and possibly send a change notification to my dependents" |
|
431 |
||
432 |
self recomputeValue |
|
145 | 433 |
|
434 |
"Created: 16.12.1995 / 19:22:54 / cg" |
|
382 | 435 |
"Modified: 22.1.1997 / 19:07:39 / cg" |
145 | 436 |
! ! |
437 |
||
2985 | 438 |
!BlockValue methodsFor:'dependents access'! |
439 |
||
440 |
release |
|
441 |
"release any dependencies upon the arguments" |
|
442 |
||
443 |
arguments notNil ifTrue:[ |
|
444 |
arguments do:[:arg | arg removeDependent:self]. |
|
445 |
]. |
|
3291 | 446 |
super release |
2985 | 447 |
|
448 |
"Modified: 22.1.1997 / 19:08:06 / cg" |
|
449 |
! ! |
|
450 |
||
1788 | 451 |
!BlockValue methodsFor:'misc'! |
452 |
||
453 |
computeValue |
|
454 |
"evaluate the receivers action block" |
|
455 |
||
456 |
|sz arg1 arg2 argValues| |
|
457 |
||
458 |
arguments isNil ifTrue:[ |
|
459 |
^ block value |
|
460 |
]. |
|
461 |
sz := arguments size. |
|
462 |
sz == 0 ifTrue:[ |
|
463 |
^ block value |
|
464 |
]. |
|
465 |
arg1 := (arguments at:1) value. |
|
466 |
sz == 1 ifTrue:[ |
|
467 |
^ block value:arg1 |
|
468 |
]. |
|
469 |
arg2 := (arguments at:2) value. |
|
470 |
sz == 2 ifTrue:[ |
|
471 |
^ block value:arg1 value:arg2 |
|
472 |
]. |
|
473 |
"/ do not evaluate arg[1-2] twice |
|
474 |
argValues := Array new:arguments size. |
|
475 |
argValues at:1 put:arg1. "/ do not evaluate twice |
|
476 |
argValues at:2 put:arg2. "/ do not evaluate twice |
|
477 |
3 to:arguments size do:[:i | argValues at:i put:(arguments at:i) value]. |
|
478 |
||
479 |
^ block valueWithArguments:argValues |
|
480 |
||
481 |
"Created: 16.12.1995 / 19:27:40 / cg" |
|
482 |
"Modified: 22.1.1997 / 19:05:57 / cg" |
|
483 |
! |
|
484 |
||
485 |
dependOn:someObject |
|
486 |
"arrange for the blockValue to be reevaluated, whenever someObject |
|
487 |
changes (i.e. sends a change notification)" |
|
488 |
||
489 |
arguments isNil ifTrue:[ |
|
490 |
arguments := Array with:someObject |
|
491 |
] ifFalse:[ |
|
492 |
arguments := arguments copyWith:someObject |
|
493 |
]. |
|
494 |
someObject addDependent:self |
|
495 |
||
496 |
"Modified: 22.1.1997 / 19:05:26 / cg" |
|
497 |
! |
|
498 |
||
499 |
resetValue |
|
500 |
"evaluate the receivers action block" |
|
501 |
||
502 |
cachedValue := self computeValue |
|
503 |
! ! |
|
504 |
||
145 | 505 |
!BlockValue class methodsFor:'documentation'! |
506 |
||
507 |
version |
|
3291 | 508 |
^ '$Header: /cvs/stx/stx/libview2/BlockValue.st,v 1.26 2014-02-26 15:10:56 cg Exp $' |
2760 | 509 |
! |
510 |
||
511 |
version_CVS |
|
3291 | 512 |
^ '$Header: /cvs/stx/stx/libview2/BlockValue.st,v 1.26 2014-02-26 15:10:56 cg Exp $' |
145 | 513 |
! ! |
1665 | 514 |
|
3291 | 515 |
|
146
9603cec98ac2
oops change notification was wrong
Claus Gittinger <cg@exept.de>
parents:
145
diff
changeset
|
516 |
BlockValue initialize! |