tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/8695-directcommandmapRobotlegs: Discussion 2014-01-22T15:22:49Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/305631762013-12-15T10:40:41Z2013-12-15T11:02:11ZDirectCommandMap<div><p>Hello Mike,</p>
<p>I've never used the directCommandMap until today. So, I've
followed the instructions from the readme file:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/directCommandMap/readme.md">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p>
<p>As the name "direct" implies, commands are executed directly,
while the execution of commands mapped using the eventCommandMap is
triggered by events :)</p>
<p>I've created the context:</p>
<pre>
<code>_context = new Context()
.install(MVCSBundle)
.configure(ModelsConfig, ServicesConfig, ControllersConfig, MediatorsConfig)
.configure(new ContextView(view));</code>
</pre>
<p>The DirectCommandMapExtension is included in the MVCSBundle, so
it will be installed.</p>
<p>I've built 4 commands:</p>
<p>BootstrapCommand</p>
<p>LoadXMLConfigsCommand</p>
<p>ConfigureServicesCommand</p>
<p>CheckConnectivityCommand</p>
<p>Inside of BootstrapCommand:</p>
<pre>
<code>public class BootstrapCommand
{
[Inject]
public var directCommandMap:IDirectCommandMap;
public function execute():void
{
directCommandMap.map(LoadXMLConfigsCommand)
.map(ConfigureServicesCommand)
.map(CheckConnectivityCommand)
.execute();
}
}</code>
</pre>
<p>Inside of ControllersConfig (where I map all my commands) I've
experimented with 2 ways of mapping the BootstrapCommand:</p>
<ul>
<li>first to be triggered by an event that I would dispatch from a
mediator, for example:</li>
</ul>
<pre>
<code>commandMap.map(BootstrapEvent.START_SEQUENCING).toCommand(BootstrapCommand);</code>
</pre>
<ul>
<li>and also to be executed right away:</li>
</ul>
<pre>
<code>directCommandMap.map(BootstrapCommand).execute();</code>
</pre>
<p>You can choose between the 2 mappings or even have both.</p>
<p>The idea is, that LoadXMLConfigsCommand,
ConfigureServicesCommand and CheckConnectivityCommand should be
called one after the other, synchronously. They are regular
commands, with an execute() method.</p>
<blockquote>
<p>Is the mapping created in its own class or in a config file?</p>
</blockquote>
<p>You map the command(s) there, where you need them to be
executed. Obviously, you need to use (inject) IDirectCommandMap
everywhere you expect commands to be executed right away.</p>
<p>In my example, BootstrapCommand can be mapped as usual, using
the eventCommandMap, if you want it to be executed at a later point
in time, once or several times.</p>
<p>Creating task sequences (chained commands) and placing them into
another command, seems to me to be a better choice than injecting
IDirectCommandMap into other actors like Models, Services or
Mediators.</p>
<p>As you can see in the readme, you can pass a payload object to
the execute method, and also use hooks and guards.</p>
<p>creynders, who introduced the DirectCommandMapExtension, can
tell you more about it, or make corrections to what I've said
above, if need be;)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/305631762013-12-17T14:36:20Z2013-12-18T09:07:38ZDirectCommandMap<div><p>Ondina,<br>
Looks good and I greatly appreciate this I haven't had a chance to
work it yet with my project. My current job is sucking most of my
time from my other pursuits. I will look at this over the weekend
and let you know. Again it was awesome that you took the time to do
this for me. All of you do great work.<br>
Thank you kindly,<br>
Mike</p></div>Miketag:robotlegs.tenderapp.com,2009-10-18:Comment/305631762014-01-22T15:22:41Z2014-01-22T15:22:41ZDirectCommandMap<div><p>Mike, I guess, this is resolved by now. I'm going to close this
discussion, but you can re-open it, if need be, or create other
discussions for other issues.</p></div>Ondina D.F.