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
@@ -232,10 +232,9 @@ public class LocationDirector extends BasicDirector
public function mayMoveTo (placeId :int, rl :ResultListener) :Boolean
{
var vetoed :Boolean = false;
_observers.apply(function (obs :Object) :Boolean {
_observers.apply(function (obs :Object) :void {
var lobs :LocationObserver = (obs as LocationObserver);
vetoed = vetoed || !lobs.locationMayChange(placeId);
return true;
});
// if we're actually going somewhere, let the controller know that
@@ -536,9 +535,8 @@ public class LocationDirector extends BasicDirector
protected function notifyFailure (placeId :int, reason :String) :void
{
_observers.apply(function (obs :Object) :Boolean {
_observers.apply(function (obs :Object) :void {
(obs as LocationObserver).locationChangeFailed(placeId, reason);
return true;
});
}
@@ -582,10 +580,9 @@ public class LocationDirector extends BasicDirector
protected var _moveListener :ResultListener;
/** The operation used to inform observers that the location changed. */
protected var _didChangeOp :Function = function (obs :Object) :Boolean
protected var _didChangeOp :Function = function (obs :Object) :void
{
(obs as LocationObserver).locationDidChange(_plobj);
return true;
};
/** We require that a moveTo request be outstanding for one minute
@@ -400,8 +400,8 @@ public class Client extends EventDispatcher
protected var _comm :Communicator;
/** Our list of client observers. */
protected var _observers :ObserverList =
new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY);
// protected var _observers :ObserverList =
// new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY);
/** General startup information provided by the server. */
protected var _bstrap :BootstrapData;
+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]);
}