tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/226-conceptually-why-shouldnt-i-access-a-mediator-from-a-commandRobotlegs: Discussion 2013-04-28T10:27:31Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/23354032010-07-22T10:33:08Z2010-07-22T10:33:09ZConceptually, why shouldn't I access a Mediator from a command?<div><p>Eeek! Sorry about the double post! Not sure what happened there,
could one of the mods please clean it up for me? :)</p></div>Peter Cardwell-Gardnertag:robotlegs.tenderapp.com,2009-10-18:Comment/23354032010-07-22T10:50:28Z2010-07-22T10:50:28ZConceptually, why shouldn't I access a Mediator from a command?<div><p>Cleaned up!</p>
<p>Short answer: you can do anything you like with robotlegs!</p>
<p>Longer answer: the purpose of the mediator is to translate
app-specific events back and forth for the view.</p>
<p>So - if you were going to act on the view in your command then
I'd just act directly on the view.</p>
<p>You have access to contextView in your Command (it's injected
into the base class) and you can map any view you want to act upon
directly as a named value if you need access to it, using
mapValue.</p>
<p>Your mediator isn't the right way to access the view in this
respect because on the whole it shouldn't have api (beyond the
onRegister etc required for the framework), it should only have
handlers.</p>
<p>These are all 'shoulds' of course. You're free to organise your
code any way you like.</p>
<p>On the whole I favour events for updating my views but you're
right - sometimes breaking out that logic chain into multiple
events and commands is not useful.</p>
<p>Most refactorings (a la Fowler) have a reverse case refactoring
which can also be an improvement.</p>
<p>I still agree with the 'don't inject mediators!' recommendation,
but only because you'd be better off injecting the view itself. I
occasionally use signals injected between mediators and other parts
of the framework where I need to know <em>which</em> mediator
triggered something and do a synchronous exchange.</p>
<p>Hope that's helpful - others will no doubt have more to add!</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/23354032010-07-22T12:34:40Z2010-07-22T12:34:40ZConceptually, why shouldn't I access a Mediator from a command?<div><p>Hi Peter,</p>
<p>Initially it was because of an implementation detail (or
side-effect) of the MediatorMap itself:</p>
<p><a href=
"http://knowledge.robotlegs.org/faqs/framework-core/why-cant-i-inject-mediators-into-other-actors">
http://knowledge.robotlegs.org/faqs/framework-core/why-cant-i-injec...</a></p>
<p>This has been addressed (somewhat), so it should now be much
easier to map specific view components or mediators for injection
into other parts of the system.</p></div>Shaun Smith