tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/100-initialization-sequenceRobotlegs: Discussion 2012-10-17T12:30:19Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-01T07:45:44Z2012-10-01T07:45:44ZInitialization Sequence<div><p>Hi Mutasem,</p>
<p>Your way of setting up Context is perfectly fine:<br>
1. Add extensions and configurations<br>
2. Add listener to after initialization<br>
3. Configure contextView<br>
I also use the same steps and that works great.</p>
<p>The main thing that auto kicks off the initialization process
when contextView lands on stage (or is already added) is <a href=
"https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/extensions/stageSync/StageSyncExtension.as#L61">
StageSyncExtension</a>. It listens when instance of
DisplayObjectContainer is configured in context.</p>
<p>OK, so let's quickly go through points you mentioned here.</p>
<p>[1] When using <a href=
"https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/mxml/ContextBuilderTag.as#L77">
ContextBuilderTag</a> it iterates over all values declared in that
view and uses extend for Extensions and configure for other
objects. After that contextView (class where ContextBuilderTag is
used) is configured to the context instance. ContextBuilderTag is
used <a href=
"https://github.com/dartavion/Robotlegs-2-Simple-Project-with-Popup/blob/master/src/Robotlegs2Example.mxml">
here</a>. When contextView is configured then AppConfig extensions
is calls handleContextView (it listens when DisplayObject is
configured).</p>
<p>[2] I described when context.configure(contextView) is called in
the first point. And you're right about constructing
ScopedEventDispatcherExtension. There should be something like
that:</p>
<pre>
<code><rl2:ContextBuilderTag>
<scopedEventDispatcher:ScopedEventDispatcherExtension>
<scopedEventDispatcher:names>
<String>global</String>
<String>local</String>
</scopedEventDispatcher:names>
</scopedEventDispatcher:ScopedEventDispatcherExtension>
</rl2:ContextBuilderTag></code>
</pre>
<p>[3] Not sure about this one. I think you created Context, added
extensions, added listener for preinitialize that configures the
context, and then configure(contextView) that kicks off the
initialization process. Anyway if it launches correctly it's
fine.</p>
<p>Hope that helps a bit, making initialization process
clearer.</p>
<p>Cheers,<br>
Michał</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-01T14:20:16Z2012-10-01T14:20:16ZInitialization Sequence<div><p>Hi Michal,</p>
<p>Thank you for helping me understand the initializing
process.</p>
<ul>
<li>
<p>I just noticed the following statement:</p>
<pre>
<code> _contextView ||= document as DisplayObjectContainer;</code>
</pre>
<p>inside the <a href=
"https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/mxml/ContextBuilderTag.as#L77">
ContextBuilderTag</a>, which explains how the _contextView is being
set even though no <code>contextView="{this}"</code> is being set
on the ContextBuilder's mxml tag.</p>
</li>
</ul>
<p>Things are more clear now that I understand how the
<code>ContextBuilderTag</code> works.</p>
<p>The other question that comes to my mind, is that why sometimes
we need to manually <code>.mediate()</code> a view... I understand
the we do it manually because the view is already on stage before
the <code>_mediatorMap.map().toMediator()</code> is called.
However, this is exactly what I don't understand.</p>
<p>For example, if you take a look at the config file <a href=
"https://github.com/MBarjawi/robotlegs2-ModularCommunications/blob/master/src/modules/moduleView1/config/ModuleView1Config.as">
here</a>, I had to manually mediate the <code>_contextView</code>
or else things won't work. What doesn't make sense to me is that
the <code>configureMediators()</code> method is being called during
the <code>preinitialize</code> phase of the
<code>_contextViews</code>'s lifecycle... which (I think) means
that this is before the <code>_contextView</code> is added to
stage. And since the mediation (I also think) happens when views
are added to stage, there shouldn't be a problem in automatically
mediating the <code>_contextView</code>. So the question remains:
why do I have to manually mediate it?</p>
<p>Thanks for your help,</p></div>mbarjawitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-01T14:27:23Z2012-10-01T14:27:23ZInitialization Sequence<div><p>You need to manually <code>mediate()</code> only when view is
already on stage or auto-mediation is not used. When on
<code>preinitialize</code> contextView is already on stage because
<code>contextView ADDED_TO_STAGE</code> event caused initialization
process.</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-01T15:38:34Z2012-10-01T15:38:34ZInitialization Sequence<div><p>Thanks again for putting the time to answer my questions.</p>
<blockquote>
<p>or auto-mediation is not used.</p>
</blockquote>
<p>How can auto mediation be not used? is there a flag for it or
something?</p>
<ul>
<li>
<p>Is there a way to finish configuring the application BEFORE the
<code>contextView</code> is added to stage? (so that it gets
automatically mediated by the rules set during configuration)</p>
</li>
<li>
<p>Is there also a way to finish configuring the application BEOFRE
the contents of the <code>contextView</code> are added to stage? or
do we always have to manually use <code>addElement</code> to ensure
that <code>contextView</code>'s elements are added after all
mediation rules are set?</p>
</li>
</ul></div>mbarjawitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-01T18:58:27Z2012-10-01T21:15:46ZInitialization Sequence<div><p>auto-mediation is when using <a href=
"https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/extensions/viewManager/StageObserverExtension.as">
StageObserverExtension</a> - mediators are assigned when view is
added to contextView tree.<br>
manual-mediation is when using <a href=
"https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/extensions/viewManager/ManualStageObserverExtension.as">
ManualStageObserverExtension</a> - your view needs to dispatch
special event requesting mediation.<br>
MVCSBundle uses auto-mediation</p>
<p>And about your questions:</p>
<ul>
<li>
<p>Don't mediate your main swf class but a child that is added
there. Like in <a href=
"https://github.com/dartavion/Robotlegs-2-Simple-Project-with-Popup/blob/master/src/org/robotlegs/example/AppConfig.as">
the first example you provided</a> Only <code>MainView</code> is
mediated - not <code>Robotlegs2Example</code> class.</p>
</li>
<li>
<p>Don't create and add subviews in constructor of your MainView.
You can use some kind of a navigator (with state machine) that
start on <code>afterInitialization</code> when context is
configured.</p>
</li>
</ul></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-02T04:10:51Z2012-10-02T04:10:51ZInitialization Sequence<div><p>Ahh... finally I was able to understand those two classes. There
is no comments on those classes and I wasn't able to figure them
all by myself.. :) thanks!</p>
<blockquote>
<p>Don't mediate your main swf class but a child that is added
there.</p>
</blockquote>
<p>Thanks for the idea... it seems a better approach.. I will start
using it.</p>
<blockquote>
<p>Don't create and add subviews in constructor of your MainView.
You can use some kind of a navigator (with state machine) that
start on afterInitialization when context is configured.</p>
</blockquote>
<p>Not sure I understand your point. Do you mean that I create for
example a ViewStack object. and leave index=0 with empty Group for
example, and put the rest of my views in the index >= 1 ?</p>
<p>I guess I don't understand what you mean by "navigator". If you
can support with example it would help me better understand.</p>
<p>Thanks,</p></div>mbarjawitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-02T07:29:31Z2012-10-02T07:29:31ZInitialization Sequence<div><p>The simplest would be something like <a href=
"https://gist.github.com/26a0e2d08375956c1bf7">that</a>.
Implementation of that class has contextView injected and adds and
manages views added to contexView. Any command or else can call
methods to navigate to a certain view. You kick off with empty
contextView and on startup you call to add first view. For more
complex navigation you can use any state machine like one <a href=
"https://github.com/AS3StateMachine/TryHarderStateMachine">here</a>
(more functional that visual but serves well) or <a href=
"https://github.com/epologee/navigator-as3">here</a> visually
oriented. First one has extension for Robotlegs2.<br>
Empty ViewStack would also work of course.</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-02T14:56:48Z2012-10-02T14:56:48ZInitialization Sequence<div><p>Wow... this whole navigators and state machines are new to me.
It will take me a little while to read those links and examine with
them.</p>
<p>Thanks a lot for your help Michal.</p>
<p>I think I am good now in terms of how to initialize my
application (the simple way)... I'll be back if I have more
questions about the state machines.</p></div>mbarjawitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-04T04:32:15Z2012-10-04T04:32:15ZInitialization Sequence<div><p>I have read those links. I think it should be very useful to use
the state machines. However, one thing that I am having difficulty
with is: how to figure out the states in my application?</p>
<p>I attempted to layout states in my application (a project I am
working on right now)... but found that it is difficult to do so. I
don't have a clear understanding of what exactly a state is.</p>
<p>For example, here are some states that I came up with: (in no
certain order)</p>
<ul>
<li>LOADING (the application module)</li>
<li>INITIALIZING (inititalizing rl2 and any other
initializations)</li>
<li>EXPLORING STUDY PLAN (when the user is exploring their study
plan, adding, deleting, modifying..etc.)</li>
<li>EXPLORING AVAILABLE COURSES (self descriptive)</li>
<li>PRINTING (the study plan)</li>
</ul>
<p>Not sure if these are any close to be good ones... and not sure
how the transitions would be between them... maybe that is why I
feel that they are not good states.</p>
<p>Finally, About the <code>IMyViewNavigator</code> that you
posted, how is that supposed to be used. I mean for my application
I have lots of dialogs to popup and lots of things to add to
screen. The ones that are already done, they all get loaded/added
in commands or the views themselves after receiving signals from
the mediators. So is it in addition to those commands, I still need
to add this navigation system?</p>
<p>I guess, my question would be what is the value of having a
navigation class instead of just using commands to navigate
around?</p></div>mbarjawitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-04T07:37:46Z2012-10-04T07:37:46ZInitialization Sequence<div><p>Let's start from the end. <code>IMyViewNavigator</code> should
contain all loading, adding, fading logic. You shouldn't do it in
<code>Commands</code> as it may introduce duplication code, unless
it's just calling <code>PopUpManager</code> to open popup class.
<code>Commands</code> should be short in code just giving commands
to execute by other tiers (like to view navigator here). Not sure
what exactly code you have in your <code>Commands</code> but you
should get the point.</p>
<p>And now about the states. Your states should be good for your
app. You can define processes for those states like: NEXT, BACK,
EXPLORE_STUDY_PLAN, EXPLORE_AVAILABLE_COURSES, PRINT and using
those processes connect your states (define available routes).
Having NEXT and BACK processes is nice because your view doesn't
need to know anything about previous and next states, just about a
direction. Here is a nice description of using of neil's state
machine with more insight into the concept <a href=
"https://gist.github.com/1277913">https://gist.github.com/1277913</a>
and <a href=
"http://statemachine.org/?p=219">http://statemachine.org/?p=219</a>
. Another good point is that state machine doesn't need to be only
view oriented, so you can have nested functional state machine for
a complex loading process etc.</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-12T18:05:52Z2012-10-12T18:05:52ZInitialization Sequence<div><p>Thanks Michal for your answer.<br>
I looked more into these states and I actually liked the concept
and used the <a href=
"https://github.com/AS3StateMachine/TryHarderStateMachine">TryHarderStateMachine</a>
in a small project.</p>
<p>However, I still feel it is a little bit confusing. I think my
main confusion point is again understanding states. Its easy for me
to comprehend states like (Initialized, GameStarted, GamePaused,
GameEnded, Destroying...etc.)... but its really difficult to
understand in a normal application where you just have screens that
allows the user to interact with them. USER_DIALOG_SHOWN is not a
state, even though that is what the user is currently doing, i.e.,
looking/interacting the the user dialog. However, it gets more
complicated when you have two states that need to happen at the
same time USER_DIALOG_SHOWN and USERS_LIST_SHOWN or whatever other
thing to show at the same time as the user dialog.</p>
<p>In the first states examples, it is very clear that you can be
at a single state at a single time... but in the second its
not.</p>
<p>If I want to create states for a normal application I would name
them (Initialized, AppStarted, AppDestroyed)... thats it... but
maybe thats because of my lack of understanding. Do you know any
complete examples (not only code snippits) that shows states in
action for a normal application like the users example I have been
using?</p>
<p>Thanks,</p></div>mbarjawitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-12T20:39:49Z2012-10-12T20:39:49ZInitialization Sequence<div><p><a href=
"http://www.slideshare.net/epologee/robot-legs-workshop-extra-session-navigatoras3">
This presentation</a> helped me alot figuring out. It talks about
AS3-Navigator (doesn't have Robotlegs 2 extension) And it supports
multiple states. There you can have <em>/userDialog and</em>
/usersList states that stack on them into something like this:
/userView/userDialog/usersList. Not really sure if that's a good
approach putting that detail into states but just showing how it
would look like.</p>
<p>Mike</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/191823462012-10-17T12:30:18Z2012-10-17T12:30:18ZInitialization Sequence<div><p>@Mutasem I think, Michal has answered all your questions. So,
I’m going to close this thread, but as you know, you can
re-open it, if need be.</p></div>Ondina D.F.