tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/583-mediators-and-commandmapRobotlegs: Discussion 2011-11-02T15:38:45Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-06-10T06:12:54Z2011-06-10T06:12:54ZMediators and commandMap<div><p>HI! why commandMap is not Injected into Mediator?<br>
is a bad practice to map commands inside our mediators? I have some
commands that I only need if my mediator is alive, how can I solve
this?</p>
<p>Thanks !</p></div>Enriquetag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-06-10T08:21:46Z2011-06-10T08:21:46ZMediators and commandMap<div><p>Hi Enrique,</p>
<p>I see no problem about that. Just inject command map:</p>
<pre>
<code>[Inject]
public var commandMap:ICommandMap</code>
</pre>
<p>and map commands the same as in Context class.</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-06-10T10:13:19Z2011-06-10T10:13:19ZMediators and commandMap<div><p>Hi Enrique,</p>
<p>this is an interesting use case - it has never come up before as
far as I remember.</p>
<p>What Michal says will work - so you can go ahead and do
that.</p>
<p>But, what's your use case?</p>
<p>Commands are bound to events, and presumably the events are
dispatched from this mediator? So aren't the Commands only going to
be activated when this mediator is active anyway? Or do you have an
unusual use case where the events aren't coming from this mediator
but execution is dependent on this mediator existing?</p>
<p>One other option is to fire a custom event from the onRegister
of this mediator (and another from onRemove) which is bound to a
Command which maps and unmaps these commands on the commandMap for
you. Generally you shouldn't be acting on the commandMap in a
mediator... but it will work and you can always refactor to a
cleaner solution later.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-06-10T21:38:44Z2011-06-10T21:38:47ZMediators and commandMap<div><p>Hi @Stray, my code is unusual very often :) .... but that is not
a good thing :(</p>
<p>I'm dispatching an event from a model, this event executes a
command, this command is creating some VO and Arrays for
dataproviders (using many models, well only 2 right now), and the
data created by the command is dispatched in another event which is
listened by mediators.<br>
Now, if I don't have the mediator, I don't nee to prepare the data
for that mediator and I don't need the command.<br>
That's why I want to map the command inside my mediator.</p>
<p>@Michal said that is OK, and you say that is unusual, I say why
me.</p>
<p>Maybe I need to redesign everything, what do you think? :(</p></div>Enriquetag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-06-11T05:26:48Z2011-06-11T05:26:48ZMediators and commandMap<div><p>Mapping the command doesn't instantiate it. Commands are
short-lived anyway, they only exist for the duration of execution
of their code.<br>
This all means you can map your commands up-front even if the
mediators don't exist yet. In other words there's no need to map
your commands in your mediators.<br>
The reason why it's better to avoid that is because you create a
dependency on those commands in your mediator and the whole purpose
is to limit the number of dependencies and other-tier-awareness to
a minimum.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-06-11T14:55:49Z2011-06-11T14:55:52ZMediators and commandMap<div><p>yes, but my command IS deppendent of my mediator.<br>
and if I map the command in the context, then everytime I dispatch
an event from my model, will create and execute that command, even
if my mediator is not alive, and if my mediator is not alive I
don't need that command...<br>
The command is creating an array from multiple models that I can
use as DataProvider for my view.<br>
I don't need that if my view is not in the stage.</p>
<p>But maybe I'm using worng the command, I can [Inject] the modles
inside my mediator and build the dataProvider then, but I was
trying to avoid injecting models inside mediator after reading a
post written by @Stray.<br>
I don't know...</p></div>Enriquetag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-06-11T14:58:36Z2011-06-11T14:58:36ZMediators and commandMap<div><p>Hi Enrique,</p>
<p>what is the event that triggers this view to come and go from
the stage?</p>
<p>This is the event you should bind to Commands to map / unmap
this command.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-06-11T15:25:25Z2011-06-11T15:25:26ZMediators and commandMap<div><p>ah, that makes sense @Stray.<br>
I don't have any event at the moment, my app is not ready yet. But
I'm trying to put everything in its place.</p>
<p>but what happens for example if my view is in the stage, but I
block it from my mediator, or make it invisible, etc. or the view
is a window and is minimized, I mean, I have the mediator, but I
don't need to update the dataProvider.<br>
I don't need to execute a command to minimize a window.</p>
<p>Although maybe I should to have a model which saves the state of
the application.</p>
<p>How do you manage that? Do you have a model for saving the state
of the views?<br>
I was fighting with that the last days.<br>
Because, suppose I have a model with "Products", and a view that
permits select products.<br>
Where I should sabe the selected products?<br>
I finish putting that info in the "ProductModel" (the ProductVO has
a selected property) :(</p></div>Enriquetag:robotlegs.tenderapp.com,2009-10-18:Comment/78016912011-11-02T15:38:45Z2011-11-02T15:38:45ZMediators and commandMap<div><p>Hi Enrique,<br>
Feel free to reopen this discussion in case you have more questions
or you need further assistance with this issue. Please open new
threads for new issues.<br>
Thank you for posting.<br>
Ondina</p></div>Ondina D.F.