Some bits: made the actionscript Observer list cope and furthermore

keep all observers in the list if the 'apply' function you specify
returns void.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4374 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-09-14 01:48:09 +00:00
parent 54d3bb6496
commit 036271438a
3 changed files with 11 additions and 16 deletions
+6 -8
View File
@@ -28,7 +28,7 @@ public class ObserverList
*/
public function add (observer :Object) :void
{
if (_list.indexOf(observer) == -1) {
if (!ArrayUtil.contains(_list, observer)) {
_list.push(observer);
}
}
@@ -43,11 +43,9 @@ public class ObserverList
/**
* Apply some operation to all observers.
* The function to be passed in should expect one argument and return a
* Boolean.
* function (observer :Object) :Boolean.
* The function should return false if the observer should be removed
* from the list.
* The function to be passed in should expect one argument and either
* return void or a Boolean. If returning a Boolean, returning false
* indicates that the observer should be removed from the list.
*/
public function apply (func :Function) :void
{
@@ -58,8 +56,8 @@ public class ObserverList
}
for (var ii :int = list.length-1; ii >= 0; ii--) {
try {
var result :Boolean = func(list[ii]);
if (!result) {
var result :* = func(list[ii]);
if (result !== undefined && !Boolean(result)) {
// remove it if directed to do so
remove(list[ii]);
}