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

Pages: [1]
Print
Author Topic: handleNotification and order  (Read 8525 times)
scorche
Newbie
*
Posts: 2


View Profile Email
« 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.
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #1 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
Colin Moock

By default, when multiple event listeners are registered for a single event type with a
given object, those listeners are triggered in the order in which they registered
...
To alter the default order in which event listeners are triggered, we can use the
addEventListener( ) method’s priority parameter, shown in the following generic
code:
addEventListener(type, listener, useCapture, priority, useWeakReference)
The priority parameter is an integer indicating the order in which the event listener
being registered should be triggered, relative to other listeners registered for the same
event with the same object. Listeners registered with a higher priority are triggered
before listeners registered with a lower priority.
For example, a listener registered
with priority 3 will be triggered before a listener registered with priority 2. When
two listeners are registered with the same priority, they are executed in the order in
which they were registered. When priority is not specified, it defaults to 0.

But Notifications in puremvc aren't Events.

Let's see what the puremvc experts will say about this. :)

Ondina
Logged

~ Ondina ~
willw
Full Member
***
Posts: 30


View Profile Email
« Reply #2 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 order

mB - E1
mB - E2
mA - E2
mA - E1

[...]

Is this at all normal?
I 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
Logged
scorche
Newbie
*
Posts: 2


View Profile Email
« Reply #3 on: April 01, 2009, 09:17:40 »

ok point take, thanks for the replies
I was thinking maybe I messed something up.
Logged
Pages: [1]
Print