tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/810-rovotlegs-v2-and-contextRobotlegs: Discussion 2013-02-10T08:42:44Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/246182642013-02-05T23:16:36Z2013-02-05T23:16:36ZRobotlegs v2 and context<div><p>Hello Andreas,</p>
<p>Have you had a look through the readme files on GitHub? They
should be enough to get started. For example:</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework">https://github.com/robotlegs/robotlegs-framework</a><br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src">https://github.com/robotlegs/robotlegs-framework/tree/master/src</a></p>
<p>Just navigate around the source tree on GitHub and you should
find readme files in pretty much every package.</p>
<p>Hope that helps.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/246182642013-02-05T23:45:44Z2013-02-06T14:20:21ZRobotlegs v2 and context<div><p>Yes, but these pages did raise my questions:<br>
The site about Bundles does not explain enough when I have to use
which Bundle and when I have to create my own.<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/bundles">
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a></p>
<p>What I miss is a guide or some sort of explanation how these
classes and packages should work together. That is why I am
confused about the role of the context in v 2.<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/bundles/mvcs">
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a>
tells something about the context, but does not answer the question
how I have to use the context.</p>
<p>Also I found some slides online that described some of the new
features in robotlegs 2, that showed it will be much simpler to set
up robotlegs, becauseyou do not need to write so much code for your
context.<br>
<a href=
"http://www.slideshare.net/justinjmoses/introduction-to-robotlegs-2">
http://www.slideshare.net/justinjmoses/introduction-to-robotlegs-2</a><br>
but there is not much explanation, either.</p></div>andreastag:robotlegs.tenderapp.com,2009-10-18:Comment/246182642013-02-07T09:58:08Z2013-02-07T09:58:08ZRobotlegs v2 and context<div><p>Hi Andreas,</p>
<blockquote>
<p>The site about Bundles does not explain enough when I have to
use which Bundle and when I have to create my own.</p>
</blockquote>
<p>So, let’s take a look at the MVCSBundle (<a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/bundles/mvcs/MVCSBundle.as">https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a>)</p>
<p>In the following example, a new Context is created, and several
extensions installed. I’ve listed all the extensions that are
part of the MVCSBundle. I could have used
context.install(MVCSBundle); instead of the long list.<br>
There is just a RootDisplayObject mapped to a RootMediator;</p>
<p><strong>Root display object, RootView</strong></p>
<pre>
<code>private var robotlegsConfig:RobotlegsConfig;
protected function preinitializeHandler(event:FlexEvent):void
{
robotlegsConfig = new RobotlegsConfig(this);
}</code>
</pre>
<p><strong>RootMediator</strong></p>
<pre>
<code>public class RootMediator extends Mediator
{
[Inject]
public var view:RootView;
override public function initialize():void
{
addViewListener(SomeEvent.SOME_TYPE, onSomeViewEvent, SomeEvent);
}
}</code>
</pre>
<p><strong>RobotlegsConfig</strong></p>
<pre>
<code>public function RobotlegsConfig(rootDisplayObject:DisplayObjectContainer)
{
_contextView = new ContextView(rootDisplayObject);
context = new Context();
((the extensions contained in the MVCSBundle::
context.install(
TraceLoggingExtension,
VigilanceExtension,
InjectableLoggerExtension,
ContextViewExtension,
EventDispatcherExtension,
ModularityExtension,
CommandCenterExtension,
EventCommandMapExtension,
LocalEventMapExtension,
ViewManagerExtension,
StageObserverExtension,
ManualStageObserverExtension,
MediatorMapExtension,
StageSyncExtension);
context.configure(_contextView);
context.afterInitializing(init);
injector = context.injector;
mediatorMap = injector.getInstance(IMediatorMap);
eventDispatcher = injector.getInstance(IEventDispatcher);
mediatorMap.map(RootDisplayObject).toMediator(RootMediator);
}
private function init():void
{
mediatorMap.mediate(_contextView.view);
}</code>
</pre>
<p>Now, let’s create our own bundle with a minimum of
extensions needed for mediating the root display object.</p>
<p>SomeSimpleBundle will look like this:</p>
<pre>
<code>public class SomeSimpleBundle implements IBundle
{
public class SomeSimpleBundle implements IBundle
{
public function extend(context:IContext):void
{
context.install(
ContextViewExtension,
EventDispatcherExtension,
LocalEventMapExtension,
ViewManagerExtension,
StageObserverExtension,
StageSyncExtension,
MediatorMapExtension
);
context.configure(ContextViewListenerConfig);
}
}</code>
</pre>
<p>Now, our RobotlegsConfig would look like this:</p>
<pre>
<code>public function RobotlegsConfig(rootDisplayObject:DisplayObjectContainer)
{
_contextView = new ContextView(rootDisplayObject);
context = new Context();
context.install(SomeSimpleBundle);
context.configure(_contextView);
context.afterInitializing(init);
injector = context.injector;
mediatorMap = injector.getInstance(IMediatorMap);
eventDispatcher = injector.getInstance(IEventDispatcher);
mediatorMap.map(RootDisplayObject).toMediator(RootMediator);
}
private function init():void
{
mediatorMap.mediate(_contextView.view);
}</code>
</pre>
<p>If I needed commands too, I’d have to add<br>
EventCommandMapExtension and CommandCenterExtension to the
SomeSimpleBundle</p>
<p>And in RobotlegsConfig:<br>
commandMap = injector.getInstance(IEventCommandMap);<br>
commandMap.map(SomeEvent.SOME_TYPE,
SomeEvent).toCommand(SomeCommand);</p>
<p>The simple bundle (from the docs on github <a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/bundles/mvcs">
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a>):</p>
<ul>
<li>
<p>ContextViewExtension -- consumes a display object container as
the contextView (<a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/extensions/contextView">https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a>)</p>
</li>
<li>
<p>EventDispatcherExtension - makes a shared event dispatcher
available (<a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/extensions/eventDispatcher">https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a>)</p>
</li>
<li>
<p>LocalEventMapExtension - automatically cleans up listeners for
its clients</p>
</li>
<li>
<p>ViewManagerExtension - allows you to add multiple containers as
"view roots"</p>
</li>
<li>
<p>StageObserverExtension - watches the stage for view components
using magic</p>
</li>
<li>
<p>StageSyncExtension - automatically initializes the context when
the contextView lands on stage</p>
</li>
<li>
<p>MediatorMapExtension - configures and creates mediators for view
components (<a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/extensions/mediatorMap">https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a>)</p>
</li>
</ul>
<p>Depending on your needs, you can add more extensions to your
custom bundle.<br>
In your robotlegs config, you could use the MVCSBundle or your own
custom bundle, or like in my first code snippet a list of
extensions:</p>
<p>context.install(MVCSBundle);</p>
<p>or<br>
context.install(SomeSimpleBundle);</p>
<p>or<br>
context.install(SomeSimpleBundle,EventCommandMapExtension,<br>
CommandCenterExtension);</p>
<p>or<br>
context.install(MVCSBundle, ScopedEventDispatcherExtension,
ViewProcessorMapExtension);</p>
<p>or<br>
context.install(<br>
ContextViewExtension, EventDispatcherExtension,<br>
LocalEventMapExtension, ViewManagerExtension, StageSyncExtension,
MediatorMapExtension );</p>
<p>About the role of the context: <a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/framework/readme-context.md">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p>
<p>There are readme files for almost all extensions or framework
classes on github. I don’t know if you’ve already seen
<strong>all</strong> of them.<br>
If not, go through all the folders… I know, I know,
it’s not the same as reading a tutorial, but for the time
being you’ll have to live with what is there.<br>
Don’t hesitate to ask more questions :)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/246182642013-02-07T17:45:19Z2013-02-07T17:45:19ZRobotlegs v2 and context<div><p>Thank you, that helped a lot, but I am still learning and not
done reading.<br>
Also I start creating my own little robotlegs2-project and play a
bit with the code.<br>
For now it is just a mediated button, but I want to implement
something like a stopwatch in robotlegs v2 (to have an example for
the whole MVCS-system: the clock as model, that started on a
command and gets updated by a service)</p>
<p>"Don’t hesitate to ask more questions :)" I will ;-) :<br>
1) What happened to the "Model"-class? I've seen some people have
implemented their own BaseActor, but what is best practice now?<br>
(this one is vital for my clock-example)</p>
<p>2) in your code you call<br></p>
<pre>
<code>context.afterInitializing(init);</code>
</pre>
that init function calls
<code>mediatorMap.mediate(_contextView.view);</code>... but why?
wont it be enough to map the mediator to the rood display using
<code>mediatorMap.map(...)</code> ?</div>andreastag:robotlegs.tenderapp.com,2009-10-18:Comment/246182642013-02-08T10:06:54Z2013-02-08T10:06:54ZRobotlegs v2 and context<div><p>Hey Andreas,</p>
<blockquote>
<p>What happened to the "Model"-class?</p>
</blockquote>
<p>Gone.</p>
<blockquote>
<p>I've seen some people have implemented their own BaseActor, but
what is best practice now?</p>
</blockquote>
<p>All you need is a shared event dispatcher.<br>
Either a BaseActor or any class that has a shared event dispatcher
injected into it can be used as a Model or a Service. The MVCS best
practices are still the same: Models and Services should only
dispatch events and not listen to any, but, as always, it’s
up to you, how you design your app :)</p>
<blockquote>
<p>in your code you call</p>
<pre>
<code>context.afterInitializing(init);</code>
</pre>
that init function calls
<code>mediatorMap.mediate(_contextView.view);</code>... but why?
wont it be enough to map the mediator to the rood display using
<code>mediatorMap.map(...)</code> ?</blockquote>
<p>That’s only necessary for the contextView, because it is
already on stage when the configuration process is starting,</p>
<p>It has to do with the lifecycle of the context (<a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/framework/readme-lifecycle.md">https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a>)</p>
<p>In debug mode, you can see the traces from rl’s
LogManager.</p>
<p>After initialization, all extensions have been installed, all
the configurations run, and all the dependencies supplied. If you
take a look at the extensions in the simple bundle from my previous
post, you can see what’s needed to create and initialize a
mediator and to provide the dependencies that it needs. It would
take me too long now to mention all the classes involved in the
process and to show the order of execution of their methods. Maybe
at another time..</p>
<p>But, keep in mind that context.afterInitializing means that the
context is ready, mappings are done, dependencies are supplied, and
everything in your app is ready to be used as desired.<br>
As an exercise, you can call
mediatorMap.mediate(_contextView.view); immediately after
mediatorMap.map() and look at the traces from the logger and
compare them to the ones produced when you call it after
initializing the context. Also, remove some extensions from the
bundle and see how the injector will complain about the missing
parts.</p>
<p>Note: You also need mediatorMap.mediate() for any other
situations where auto mediation is not possible or desired.</p>
<p>Does this help a little?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/246182642013-02-08T20:55:07Z2013-02-08T20:55:07ZRobotlegs v2 and context<div><p>@Ondina - > That’s only necessary for the contextView,
because it is already on stage when the configuration process is
starting,</p>
<p>That's not the case any more. The StageCrawler takes care of
traversing existing views when the context initializes.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/246182642013-02-09T00:40:05Z2013-02-09T00:40:05ZRobotlegs v2 and context<div><p>Thank you, Ondina, that helped a lot.<br>
So for a Model to work all I need is to use an eventdispatcher,
fine!</p>
<p>I just created a small example on my github-account which shows
the full MVCS-functionality (and explains it with the Class Diagram
at <a href=
"http://www.robotlegs.org/diagram/">http://www.robotlegs.org/diagram/</a>):<br>
<a href=
"https://github.com/brean/robotlegs2-clock-example">https://github.com/brean/robotlegs2-clock-example</a>
.</p></div>andreastag:robotlegs.tenderapp.com,2009-10-18:Comment/246182642013-02-09T13:09:09Z2013-02-09T13:09:09ZRobotlegs v2 and context<div><p>@Shaun Thanks! I pasted the code from an older app, that was
using an older rl version and I completely forgot about the
StageCrawler. Of course there is no need for a
mediatorMap.mediate() anymore for the root display object:)</p>
<p>@Andreas</p>
<p>You’re welcome :) I’ll take a look at your code.
I’ll add it to our rl2 list of examples.</p>
<p>Ondina</p></div>Ondina D.F.