tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/133-dispatching-event-from-componentRobotlegs: Discussion 2013-04-28T10:00:34Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/22774352010-07-16T10:43:06Z2010-07-16T10:43:08Zdispatching event from component<div><p>Update: I've managed to get this- nearly- working within the
mediator. I still get the mediator's function being called twice
though, for what I am sure is a single custom event.<br>
I have used stopImmediatePropagation() on the mouseClick before
calling my custom event. The custom event has a random number as
payload, and that's the same, so I'm still a bit confused, but at
least it is only a single instance of the component firing
this.</p></div>SteveBtag:robotlegs.tenderapp.com,2009-10-18:Comment/22774352010-07-16T12:12:34Z2010-07-16T12:12:38Zdispatching event from component<div><p>Further update:<br>
I've got it sorted. I was incorrectly calling the MainContext when
I was instantiating a new component, and so the mediator mapping
was called twice - in MainContext and again...in the component
instance which was referring back to MainContext.</p>
<p>! I removed the mapping in the MainContext and have it in the
LocalContext so it now just gets fired once per component.</p>
<p>Sorry if you read through post 1 & 2 before seeing this.
Amazing how strongly I believed it was something to do with event
bubbling!</p></div>stevebtag:robotlegs.tenderapp.com,2009-10-18:Comment/22774352010-07-16T14:02:15Z2010-07-16T14:02:15Zdispatching event from component<div><p>Reading your first post I am a little concerned with this part:
"each of which is a mxml component with a local contextView".</p>
<p>How are you putting your app together? When building a normal
(ie, non-modular) Robotlegs application there is only one
<code>contextView</code> - a reference to the root view component
that was passed to the context.</p>
<p>If you are new to Robotlegs I would suggest building your app
with a single context. Building modular RL apps is not too complex,
but it does require a good understanding of how everything fits
together.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/22774352010-07-16T15:19:34Z2010-07-16T15:19:34Zdispatching event from component<div><p>Hi Shaun,<br></p>
<pre>
<code>Thanks for getting back to me. I am starting RobotLegs and I'm finding it fairly confusing (I'm at an age when new stuff gets hard to learn!), so I take your warning about the complexity, but I think this has to be a modular app because of the sheer quantity of the data. The app is a virtual in-patient medication chart, which is to represent a 6 * a4 page chart for Doctors to test their prescribing skills. It will contain errors, that they must identify and resolve.
My first version contained a map of all the labels potential co-ordinates, but there are potentially hundreds of them. I can simplify the code by grouping them into individual prescriptions (about 5 to a page). Each prescription has perhaps ten major data items, but also a 5x14 grid for signatures when a drug has been administered. Having a component per prescription and a component per administration row greatly simplifies things. All I need to do is inject the right data to each component, to get it to render. Also to know which item on which component was clicked, so I can correct if necessary.
Since my prescriptions are based on multiple instances of the same component, doesn't it make sense for them to have their own context? Or am I heading for trouble? I was inspired to the modular approach by your video http://vimeo.com/7524637 where you make it look so easy!</code>
</pre>
<p>A follow-up question, If I can. My original app set up
databinding on each on-screen label, so that if I changed the model
(eg.
prescription[4].drugname.displaytext=prescription[4].drugname.correction
) the view would automatically update. Am I right in thinking that
that sort of thing is frowned upon, because the model is directly
manipulating the view?</p>
<p>Although RobotLegs is hard to start, I think it looks really
promising, whereas I had the feeling beforehand that I was just
heading for trouble as the app got more complex.<br>
Best wishes,<br>
Steve</p>
<p>-----Original Message----- From: Shaun Smith [mailto:<a href=
"mailto:tender+daaa9121296f41ba74d1887ca2da66fb576118f33@tenderapp.com">tender+daaa9121296f41ba74d1887ca2da66fb576118f33@tenderapp.com</a>]<br>
Sent: 16 July 2010 15:04<br>
To: Brydges, Stephen<br>
Subject: Re: dispatching event from component [Problems]</p></div>Brydges, Stephentag:robotlegs.tenderapp.com,2009-10-18:Comment/22774352010-07-16T15:26:33Z2010-07-16T15:26:33Zdispatching event from component<div><p>hmm, I don't think that video is a good place to model a
Robotlegs app off of, especially if you are finding it complex. The
MVCS approach is well documented:</p>
<p><a href=
"http://insideria.com/2010/06/an-introduction-to-robotlegs-a.html">http://insideria.com/2010/06/an-introduction-to-robotlegs-a.html</a><br>
<a href=
"http://wiki.github.com/robotlegs/robotlegs-framework/best-practices">
http://wiki.github.com/robotlegs/robotlegs-framework/best-practices</a></p>
<p>Obviously you are free to architect your app however you please,
but that is swimming against the current a bit (as the title of the
video implies it is a Swizzy approach).</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/22774352010-07-17T10:47:57Z2010-07-17T10:47:57Zdispatching event from component<div><p>As Joel points out, that's not really a good model to
follow.</p>
<p>I don't think the "quantity" of data, in this particular case,
is a good reason to go multi-context. It sounds to me like a single
context (read: application) with some good data modeling would do
the trick.</p>
<p>I'd recommend reading as much Robotlegs material as possible and
looking at some demos to get a good idea of some common work-flows.
Have a look through some of these:</p>
<p><a href=
"http://github.com/robotlegs/robotlegs-demos-Bundle">http://github.com/robotlegs/robotlegs-demos-Bundle</a></p>
<p>I'd recommend starting with HelloFlex and FlickrImageGallery.
Also, this document might clear up some stuff on the mechanical
side:</p>
<p><a href=
"http://wiki.github.com/robotlegs/robotlegs-framework/robotlegs-internals">
http://wiki.github.com/robotlegs/robotlegs-framework/robotlegs-inte...</a></p></div>Shaun Smith