tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/1006-wrapping-rl-application-as-componentRobotlegs: Discussion 2012-09-25T07:56:59Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T07:45:37Z2012-08-21T07:45:37ZWrapping RL application as component<div><p>Hi Vjekoslav,</p>
<blockquote>
<p>So I would create multiple components all created with RL
framework and export them as SWC.</p>
</blockquote>
<p>This sounds like a library project to me.<br>
You add the components to a library project, and then you add it to
your project’s library path.<br>
In case you don’t know how to do this, here are more
details:<br>
<a href=
"http://livedocs.adobe.com/flex/3/html/projects_7.html">http://livedocs.adobe.com/flex/3/html/projects_7.html</a></p>
<p>Then you can use/wire your components like any other components
in your Robotlegs application.</p>
<p>Or are you talking about modules?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T08:30:02Z2012-09-25T07:56:58ZWrapping RL application as component<div><p>Thanks for your reply.</p>
<p>I know how to work with libraries, that's not what I'm
interested.</p>
<p>Let me explain in detail with examples. Component could provide
either some functionality (i.e. supporting component for
communication with web service) or can be collection of visual
elements providing some functionality (i.e. custom notification
pop-up).<br>
What service component will do is relay request to web service,
validate response and dispatch event which will contain result. To
send message (to use component) you would call method
<em>send(message:XML)</em> from IService interface.<br>
What notification component will do is present notification window,
wait for user input to confirm that notification (like clicking ok
or close button) and in the end dispatch event which will mark that
notification was completed. To show notification you would call
method <em>notify(text:String)</em> from INotification
interface.</p>
<p>I know how would I wire things up with RL in my application to
include this service and notification, but what I'm not sure is how
would I actually <strong>create</strong> this components using RL.
My question is where do I implement this interfaces and provide the
usability of components like I described in example.</p>
<p>Regards,<br>
Vjeko</p></div>Vj3k0tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T08:47:54Z2012-08-21T08:47:54ZWrapping RL application as component<div><p>I hope this time I understand what you are looking for :)</p>
<p>In robotlegs v.1 :</p>
<p>-The Service class:</p>
<p>public class SomeService extends Actor implements
ISomeService</p>
<p>-Mapping:</p>
<p>injector.map(ISomeService).toSingleton(SomeService);</p>
<p>-In a class (for example in a Command) where you need the
service:</p>
<p>[Inject] public var someService: ISomeService;</p>
<p>someService.send(message)</p>
<p>But, if you know this too, then I really don’t know what
you mean.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T08:50:28Z2012-08-21T08:50:28ZWrapping RL application as component<div><p>Sorry, I used the robotlegs v2 mapping style in my previous
post.</p>
<p>Here for robotlegs v. 1:<br>
injector.mapSingletonOf(ISomeService, SomeService);</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T09:11:47Z2012-08-21T09:11:47ZWrapping RL application as component<div><p>Since SomeService extends Actor, it is able to dispatch custom
events on the shared EventDispatcher provided by the robotlegs
context.</p>
<p>Commands, Mediators, Models and Services (extending Actor), they
all have access to that shared event dispatcher.</p>
<p>But, as you can see here: <a href=
"http://knowledge.robotlegs.org/kb/reference-mvcs-implementation/do-models-and-services-have-to-extend-actor-why">
http://knowledge.robotlegs.org/kb/reference-mvcs-implementation/do-...</a></p>
<p>you don’t have to extend Actor.</p>
<p>Sorry, if you knew this too. Maybe I’m totally missing the
point :)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T09:17:47Z2012-09-25T07:56:59ZWrapping RL application as component<div><p>Hehe, you're getting there.</p>
<p><em>I'll be using RL1 convention since I'm more familiar with
it, but the problem should be the same for RL2.</em></p>
<p>Suppose you create your application like you did here. But when
you're done, you pack it in SWC and want to provide one interface
for it.<br>
So for your service you have structure like:<br>
- ServiceContext - ServiceComponent - commands - SendMessage -
ReformatMessage - ... - model - ServiceModel - vo</p>
<pre>
<code> - SomeValueObject
- ...</code>
</pre>
<ul>
<li>service
<ul>
<li>Service</li>
<li>dto
<ul>
<li>SomeDTO</li>
<li>...</li>
</ul>
</li>
</ul>
</li>
<li>views
<ul>
<li><em>(nothing here for this)</em></li>
</ul>
</li>
</ul>
<p>So to create a component, I would have as document class
ServiceComponent. In there I would create context, etc... Now I
have finished project all cool with asdocs, fancy formatting and
tested, and now I want to wrap as SWC so that I can use it
somewhere else (doesn't need to be RL project).</p>
<p>So when I have this SWC, I want to treat it as full thoroughbred
component - black box. There is only one input and that is through
IService interface. There may be multiple outputs which are relayed
through events.</p>
<p>So if I want to use this SWC created with RL in non-RL
application I would have to create and instance of this and use it
through this IService interface:<br>
var service:IService = new ServiceComponent();<br>
service.send(someMessage);</p>
<p>Now I have a problem because for this to work that would mean
that ServiceComponent should implement IService interface (to
remind you ServiceComponent is document class which holds component
context).</p>
<p>Don't know how much more could I describe it. :-)</p></div>Vj3k0tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T09:21:16Z2012-09-25T07:56:59ZWrapping RL application as component<div><p>Sorry about formatting issue, it represents project
structure:</p>
<ul>
<li>ServiceContext</li>
<li>ServiceComponent</li>
<li>commands
<ul>
<li>SendMessage</li>
<li>ReformatMessage</li>
<li>...</li>
</ul>
</li>
<li>model
<ul>
<li>ServiceModel</li>
<li>vo
<ul>
<li>SomeValueObject</li>
<li>...</li>
</ul>
</li>
</ul>
</li>
<li>service
<ul>
<li>Service</li>
<li>dto
<ul>
<li>SomeDTO</li>
<li>...</li>
</ul>
</li>
</ul>
</li>
<li>views
<ul>
<li>(nothing here for this)</li>
</ul>
</li>
</ul></div>Vj3k0tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T10:15:17Z2012-08-21T10:15:17ZWrapping RL application as component<div><p>Vjeko , I’ll have to think about this and answer later,
when I’ll have more time, but just now all I can come up with
is having an interface for your ServiceComponent which would be
mediated by a ServiceComponentMediator, which would handle the
request for a service call coming from the main application.</p>
<p>Till later.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T11:02:35Z2012-09-25T07:56:59ZWrapping RL application as component<div><p>That was my thinking also, glad you understood my problem.
:-)</p></div>Vj3k0tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T11:11:47Z2012-08-21T11:11:47ZWrapping RL application as component<div><blockquote>
<p>That was my thinking also, glad you understood my problem.
:-)</p>
</blockquote>
<p>Oh well, I might be a little slow today..</p>
<p>Another possibility would be to use a shared event dispatcher
between the main app and your swc.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-21T15:39:15Z2012-08-21T15:39:15ZWrapping RL application as component<div><p>To sum it up, here are the possibilities that I know of:</p>
<ul>
<li>Use the Modular Utility to communicate between 2 rl apps (not
your case)</li>
<li>Robotlegs swcs as a library project, mappings in the main
app’s context (not your case)</li>
<li>Loading Robotlegs swc into a non-robotlegs application:
<ul>
<li>Communicate between main and swc through an interface that the
document class (or root view) of your swc implements, and let its
mediator communicate with commands, services etc</li>
<li>Define a shared event dispatcher (either set the dispatcher of
the subapp to be main’s dispatcher or vice versa)</li>
<li>In your swc’s Context (or a Command responsible for
mappings) map IMainView to MainViewMediator. Bad names, I know. In
your main application, the component (SomeMainView) wanting to call
the service from your swc implements IMainView interface. When this
view dispatches an event, MainViewMediator(in your swc),
who’s listening fort hat event, dispatches an event to
trigger a command->service etc. The swc’s root/document
class creates its Context with the main application’s view
(SomeMainView) as the contextView.</li>
</ul>
</li>
</ul>
<p>My preference would be interfaces and shared event
dispatcher.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-22T06:24:03Z2012-09-25T07:56:59ZWrapping RL application as component<div><p>Thanks for your suggestions.</p>
<p>I'm gonna comment on your 3rd point of loading RL swc in non-RL
application.<br>
1. This was my suggestion also, so no point in commenting that.<br>
2. Interesting as a thought, but I don't see it working in non-RL
application since they are not oriented to work around single event
bus. This way, I would have to have exposed this event dispatcher
somewhere in the code, instead of having only component. It also
creates coupling.<br>
3. This will create really tight coupling, not to mention that if I
have component which has 50 methods and properties exposed through
interface, each application in which I would use this component
would have to implement all 50 of them. Also if view is mapped to
my main application that would mean that it needs to dispatch all
events for mediator to catch them.</p>
<p>I'm open to other suggestions also. :-)</p>
<p>P.S. Ondina, thanks for your prompt help.</p></div>Vj3k0tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-22T11:29:32Z2012-08-22T11:29:32ZWrapping RL application as component<div><p>Hi Vjeko,</p>
<p>You’re welcome! Interesting discussion.</p>
<p>As we all know, the components in the Flex SDK make use of data
fields, data functions, data descriptors, and object factories and
they dispatch events containing the return data.<br>
Accessing components through their API of events, properties,
methods, or defining interfaces are the most common ways of
building them loosely coupled and keeping them encapsulated.<br>
But, it sounds like you think that using APIs, Interfaces, or
shared event dispatchers would break the encapsulation of your
components in a way or another, or that you had to do extra work on
the component level, and therefore that you need another solution
:)</p>
<blockquote>
<p>I'm open to other suggestions also. :-)</p>
</blockquote>
<p>Me too!</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/181676422012-08-22T12:13:50Z2012-08-22T12:13:50ZWrapping RL application as component<div><p>JFYI:<br>
Not directly related to this discussion, and also not a solution to
your problem, but I thought you might be interested in the concept
of an “anti corruption layer“, that Shaun mentioned in
this post:<br>
<a href=
"http://knowledge.robotlegs.org/discussions/robotlegs-2/38-service-with-a-large-api#comment_17269563">
http://knowledge.robotlegs.org/discussions/robotlegs-2/38-service-w...</a></p>
<p><a href=
"http://moffdub.wordpress.com/2008/09/21/anatomy-of-an-anti-corruption-layer-part-1/">
http://moffdub.wordpress.com/2008/09/21/anatomy-of-an-anti-corrupti...</a><br>
<a href=
"http://moffdub.wordpress.com/2008/09/24/anatomy-of-an-anti-corruption-layer-part-2/">
http://moffdub.wordpress.com/2008/09/24/anatomy-of-an-anti-corrupti...</a></p></div>Ondina D.F.