tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/13224-some-pure-as3-modularity-extension-example-for-rl2Robotlegs: Discussion 2015-10-12T12:13:35Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/323236562014-03-30T17:43:47Z2014-03-30T17:43:47ZSome pure-as3 modularity extension example for RL2<div><p>Hello,</p>
<p>I've attached a very simple example of a pure as3 modular
app.<br>
I've put it together very quickly, so it's not perfect ;)<br>
It is an AIR app. I've used FlashBuilder 4.6 to specify the action
script module used in this example (ModuleAView).<br>
The ModuleLoaderView loads ModuleAView.<br>
It's getting late here, where I live, so I'm going to tell you more
about how it works tomorrow, if need be.</p>
<p>The attached as3 app is similar to this one for Flex:<br>
<a href=
"https://github.com/Ondina/robotlegs-bender-modular-air">https://github.com/Ondina/robotlegs-bender-modular-air</a></p>
<p>And here is another example (Flex) using signals:<br>
<a href=
"https://github.com/dotdotcommadot/ModularRL">https://github.com/dotdotcommadot/ModularRL</a></p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/323236562014-04-01T15:58:49Z2014-04-01T15:58:49ZSome pure-as3 modularity extension example for RL2<div><p>Hello Ondina. Thanks a lot for your example. I made my code
work, can't believe it was so simple :) Reading your code raises
two questions on me:</p>
<p>Is there any special reason to wait for Event.ADDED_TO_STAGE
before loading the module in ModulesLoaderView and before adding
context and clindren in ModuleAView? Is it some kind of good
practice?</p>
<p>You are mediating your module context view. Isn't it a
discouraged practice? Where is the limit when mediating root views
without getting in troubles?</p></div>greenLEDtag:robotlegs.tenderapp.com,2009-10-18:Comment/323236562014-04-02T11:26:20Z2014-04-18T08:57:05ZSome pure-as3 modularity extension example for RL2<div><p>Hi,</p>
<p>You're welcome. :)<br>
I'm glad my example was helpful.<br>
In the meantime I've changed it a bit. Even though it is still WIP,
I've uploaded it on github:<br>
<a href=
"https://github.com/Ondina/robotlegs-bender-as3-modular-example">https://github.com/Ondina/robotlegs-bender-as3-modular-example</a></p>
<p>The readme is a work in progress as well. It's easier to write
code than a good readme, and also less time consuming ;)</p>
<p>The example uses a shared library for some components, models
and events, and it is also capable of loading another robotlegs app
as a swf. There are 2 other repositories there for the library and
external app. I'll explain the work flow in the readme as soon as I
get a chance.</p>
<blockquote>
<p>Is there any special reason to wait for Event.ADDED_TO_STAGE
before loading the module in ModulesLoaderView and before adding
context and clindren in ModuleAView? Is it some kind of good
practice?</p>
</blockquote>
<p>I guess the only reason for using addedtostage was that the
stage was null in the constructor of the module and I wanted to
scale the stage or something, but forgot to do so, in the
hurry..<br>
I'll make sure to change this in the github example. If you find
any other issues, please let me know.</p>
<p>In fact, it is better to create the context of a pure
actionscript project in the constructor of a child view of the
document view. The reason for that is StageSyncExtension's way of
handling the contextView of a non-Flex application. For more
details see this discussion:<br>
<a href=
"http://knowledge.robotlegs.org/discussions/robotlegs-2/3724-ieventdispatcher-null-in-model/page/1?to=%2Fdiscussions%2Frobotlegs-2%2F3724-ieventdispatcher-null-in-model%2F#comment_27722911">
http://knowledge.robotlegs.org/discussions/robotlegs-2/3724-ieventd...</a></p>
<blockquote>
<p>You are mediating your module context view. Isn't it a
discouraged practice? Where is the limit when mediating root views
without getting in troubles?</p>
</blockquote>
<p>There are many situations where a Mediator for the contextView
is needed, and there are lots of questions on this forum asking how
to do it. So I'd made it a habit to create a mediator for a
contextView whenever I write an example, just to show how it's
done.</p>
<blockquote>
<p>Isn't it a discouraged practice?</p>
</blockquote>
<p>Can you point me out to the article(s) or discussion(s) that
made that statement? Maybe they were referring to robotlegs version
1?<br>
And, what kind of troubles are you expecting to get into?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/323236562014-04-02T23:42:33Z2014-04-02T23:42:33ZSome pure-as3 modularity extension example for RL2<div><blockquote>
<p>Can you point me out to the article(s) or discussion(s) that
made that statement? Maybe they were referring to robotlegs version
1? And, what kind of troubles are you expecting to get into?</p>
</blockquote>
<p>You are right. Some days ago I read an article from the
Knowledge Base<br>
named "Can I Mediate my Root Application?" and in fact, as I can
see in<br>
the sintax it shows, it refers to RL1. As the article says, I could
end up<br>
with an uninitialized context, but again, it is for RL1. Does it
means<br>
there is no null context risk in RL2 whem mediating the root
application?</p>
<p>I saw your updated example at GitHub. The readme.md explains a
lot the<br>
inter modular comunication process. Thanks again :)</p></div>greenLEDtag:robotlegs.tenderapp.com,2009-10-18:Comment/323236562014-04-03T10:39:17Z2014-04-03T10:39:17ZSome pure-as3 modularity extension example for RL2<div><blockquote>
<p>As the article says, I could end up with an uninitialized
context, but again, it is for RL1.</p>
</blockquote>
<p>You misunderstood the article. The context would be initialized
just fine. Having a mediator for the root display object that is
used as a contextView doesn't affect context's initialization. It
is rather the other way around. Classes, like Mediators, Models,
Commands, Services, will be fully functional only after a context
has been created and the wiring process has finished (mappings..).
If such a framework class is created before the robotlegs start up
process has finished, it won't be supplied with the needed
dependencies.</p>
<p>Robotlegs v2 handles the initialization process much better than
rl1. The context's lifecycle handlers come in pretty handy. For
example, afterInitializing() means that the context has been fully
initialized and your classes have been configured. The application
is ready - up and running.<br>
You can follow the flow of a context initialization process by
looking at the log messages in debug mode.</p>
<blockquote>
<p>Does it means there is no null context risk in RL2 whem
mediating the root application?</p>
</blockquote>
<p>The null context problem has also nothing to do with mediating
the root display object.<br>
See this:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems#problem-things-work-for-a-while-and-then-mysteriously-stop">
https://github.com/robotlegs/robotlegs-framework/wiki/Common-Proble...</a></p>
<p>The only problem with a mediated root view could be what is
called "a race condition". For example, if the mediator added a
listener for an event dispatched by the view, and the event has
been dispatched before mediator's initialize(), the mediator won't
be able to react to the event. But, such a situation can be easily
circumvented.<br>
With dependency injection, race conditions can arise in other parts
of your application as well. But, you can avoid them, if you
carefully design your classes. Keep in mind that the order of
execution / the timing of events or processes are important and
that dependencies must be satisfied before using them.<br>
There are also some utilities, that can be of help when dealing
with the order of the execution of events or commands, but that's
another story:)</p>
<p>Do you need more assistance with the modular extension or can we
mark this discussion as resolved?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/323236562014-04-03T13:09:20Z2014-04-03T13:09:20ZSome pure-as3 modularity extension example for RL2<div><p>Yes, you can mark this discussion as solved. I am fine with
modules for<br>
now. Thanks Ondina, and sorry for the offtopics.</p></div>greenLEDtag:robotlegs.tenderapp.com,2009-10-18:Comment/323236562014-04-03T14:15:43Z2014-04-03T14:15:43ZSome pure-as3 modularity extension example for RL2<div><p>My pleasure! Don't worry about the offtopics. It's better to
clear up doubts right away than to live with them :)</p>
<p>See you around,<br>
Ondina</p></div>Ondina D.F.