Title: handleNotification and order Post by: scorche on March 31, 2009, 11:10:02 I've been attempting to tackle pureMVC for a while and would get discouraged rather easily, but Today I finally sat down and started making an application. I find it is much easier to do that with a goal in mind, rather than just learning how it works.
well here's something I came up against that has me quite confused. I have two mediators that handle notifications: mA and mB; the mediator mA is the main mediator that runs the big picture, but they both handle the same two notifications E1 and E2. I have mB sending a notification E2 upon receiving E1. for some reason I can see that the trace is showing that the notifications within the models are firing in this order mB - E1 mB - E2 mA - E2 mA - E1 Though I'm not ruling out the possibility of a mistake on my part... I'm wondering why the events don't fire in this sequence mA - E1 mB - E1 mA - E2 mB - E2 if I remove sending a notification E2 after mB processing E1 I get mB - E1 mA - E1 Is this at all normal? I don't have much experience with pureMVC so I'm asking if somebody either knows why this happens and/or can suggest some better practices to avoid this odd behaviour. Title: Re: handleNotification and order Post by: Ondina on April 01, 2009, 12:18:38 I don't think that's a puremvc issue.
It rather has something to do with the execution order of AS3 code in general. private function superMediator():void{ mediatorA(); mediatorB("b1"); //3 } private function mediatorA():void{ trace("mA "); //1 mediatorB("b2"); } private function mediatorB(s:String):void{ trace("mB "+s); //2 } The trace should give you this: mA mB b2 mB b1 which is perfectly normal. If Notification were AS3 Events you could set the priority parameter to change the order of execution. Essential ActionScript 3.0 But Notifications in puremvc aren't Events. Let's see what the puremvc experts will say about this. :) Ondina Title: Re: handleNotification and order Post by: willw on April 01, 2009, 02:26:42 for some reason I can see that the trace is showing that the notifications within the models are firing in this orderI think so, yes. Without reading the code I guess: When you send a notification, it isn't queued, but processed by PureMVC immediately. So when mB sends E2, everything that handles E2 is going to handle it before sendNotification(E2) returns in mB, and mB returns control to the framework. So only when mB finishes handling E1 can any other class get a chance to handle it. If you want everything to handle E1 followed by everything handling E2, you could make a new command that sends E1 followed by E2. It isn't clear to me what you want to happen, and therefore difficult to advise you. Will Title: Re: handleNotification and order Post by: scorche on April 01, 2009, 09:17:40 ok point take, thanks for the replies
I was thinking maybe I messed something up. |