Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

* | |

  Show Posts
Pages: [1]
1  PureMVC Manifold / Bug Report / Re: [RESEARCHING] bug in notifyObservers when observers self-destruct on: July 18, 2008, 06:59:20
1. I am fairly certain the framework does not guarantee the order Notifications are received in. If I were younger I might remember where I read that!

2. You are correct. My fix does not handle "mediators removing other mediators listening to the same notification" and so is incomplete. Assuming yours works andres I would hope to see it in the next release. Well done!

Jay






2  PureMVC Manifold / Bug Report / [MERGED DUP] bug in notifyObservers when observers self-destruct on: July 17, 2008, 09:42:34
I have a number of ViewMediators which listen for a LOGOUT notification and remove themselves by using facade.removeMediator. Only half of them are removed. I traced the problem to notifyObservers in View.as. The for loop increments as the observers array decrements, which means you skip every other observer. My solution, after a bit of head scratching, is very simple: reverse the for loop. This fixed it for me:

public function notifyObservers( notification:INotification ) : void
{
   if( observerMap[ notification.getName() ] != null ) {
      var observers:Array = observerMap[ notification.getName() ] as Array;
      // BAD: because observers that remove themselves decrement the array while i increments
      // for (var i:Number = 0; i < observers.length; i++) {
      // GOOD:
      for (var i:Number = observers.length - 1; i >= 0; i--) {
         var observer:IObserver = observers[ i ] as IObserver;
         observer.notifyObserver( notification );
      }
   }
}

I hope others find this helpful. I would suggest adding this fix to the next release.

Jay

Pages: [1]