PureMVC Architects Lounge

Announcements and General Discussion => Fabrication => Topic started by: broadysmile on December 21, 2010, 12:51:06



Title: [BUG?] Constructor of a mediator executed twice at first run
Post by: broadysmile on December 21, 2010, 12:51:06
As I'm not a native english speaker and don't expect you to understand the title, I'll just show an example:

Add
:
trace (NAME + ": ", viewComponent);in a mediator constructor.

Instantiate ShellMediator once and then WindowMediator twice:
ShellMediator:  [object Shell]
ShellMediator:  null
WindowMediator:  [object Window]
WindowMediator:  null
WindowMediator:  [object Window]

So it's like when You execute a mediator's constructor first time for the specific class, You get the constructor executed once more without viewComponent argument...

I'm using Fabrication for Flash, everything up-to-date.

I don't know if this is a bug, it just got me alarmed.


Title: Re: [BUG?] Constructor of a mediator executed twice at first run
Post by: broadysmile on December 31, 2010, 02:20:18
Not only extra instance of mediator, but also of it's viewComponent is created (I put trace in vc constructor)!

I can't sleep because of it! Will check the issue on new project in 2011.


Title: Re: [BUG?] Constructor of a mediator executed twice at first run
Post by: rafal.szemraj on January 03, 2011, 03:42:02
Hi,

Second constructor call for mediator is caused by reflection mechanism. As you've probably noticed in mediator constructor there is ( and should be ) as less code as possible - main mediator initialization should be done in onRegister() method. You should not be worry of second constructor run - reflection mechanism creates only local variable so it is deleted as soon as all reflection info about mediator instance is gathered. This explanation is only for mediator - I don't know how you managed to have second viewComponent instance created. Can you send me some code? Or maybe put some example in fabrication google code issues section?

Thanks.
Rafał


Title: Re: [BUG?] Constructor of a mediator executed twice at first run
Post by: broadysmile on January 03, 2011, 05:00:55
You just interrupted me making a simple program reproducing the problem and there is no extra component created there, so probably it's my fault ::).

As for reflection mechanism, thanks, I was expecting something like this going in the background, but as I'm new to the all MVC stuff and I'm making a complex project i was so afraid of memory leaks that I had to ask.

I'll try to either fix, or reproduce my problem with one extra component and report the result here : )

Thanks for Your time, Fabrication is great! (BTW, is it easy to get Fabrication going on HAXE?)


Title: Re: [BUG?] Constructor of a mediator executed twice at first run
Post by: broadysmile on January 03, 2011, 05:44:06
I prepared the essence of this bug (component constructor ran once more). I really can't find a mistake in this short code, but maybe I just didn't code it properly for reflection or some other mechanism...

Here is the flashDevelop project:
http://gospoda.oz.pl/vidmo.rar

It traces:
1
2
0

but I only instantiate
new Vidmo(1)
new Vidmo(2)

And trace is only in Vidmo constructor, tracing the number argument.

Thank You in advance.

EDIT: oh, the "0" disappears when I comment out these lines in main command:
registerMediator(new VidmoMediator(shell.vidmo1));
registerMediator(new VidmoMediator(shell.vidmo2));

so it's like the problem is somewhere around, or inside, reflection mechanism.


Title: Re: [BUG?] Constructor of a mediator executed twice at first run
Post by: broadysmile on January 04, 2011, 06:30:25
I enhanced it with:
:
var error:Error = new Error();
trace(number, error.getStackTrace().split('\n')[3]);

and got:
1 undefined
2 undefined
0    at org.as3commons.reflect::Type$/getTypeDescription()[/Users/sema/Work/projects/personal/development/PureMVCFabricationIoC/as3-commons-reflect/org/as3commons/reflect/Type.as:218]