dispatching event from component
I am new to Robotlegs so may be approaching this from completely the wrong direction but...
I am building an application that represents a form on screen.
The form is made up of several (5-10) similar sections, each of
which is a mxml component with a local contextView. Each section
has several text fields, and sub-sections with text fields. I need
to pass a message saying which text field was clicked, within which
component instance, back up to the application.
I'd rather use event bubbling up to the level of the component, to
assemble a sensible message about what was clicked. Then I stop
event propagation attempt to dispatch a new single custom message,
SECTION_CLICKED from the component.
I can dispatchEvent and trace out the single message that is
sent... but that is the Flex event bus, and I need to send this
event via RobotLegs context.
I can't access the dispatch method from my component - (unless I am
missing the syntax)
The component has a mediator, and I have had limited success with
eventMap.mapListener, addContextListener and addViewListener (You
can tell I am getting desperate!) They do fire the method, but they
fire it once for each Section component, rather than once for the
single message (I'm fairly sure that it is only a single version of
the SECTION_CLICKED message that is fired). If I use
stopImmediatePropagation() instead of stopPropagation back at the
component's handleClick method, I still get to send the
SECTION_CLICKED message, but the Mediator doesn't respond at
all.
Ideally I'd bypass the mediator and dispatch my message straight from the component, but I suspect this would go against the design of Robotlegs?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by SteveB on 16 Jul, 2010 10:43 AM
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.
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.
2 Posted by steveb on 16 Jul, 2010 12:12 PM
Further update:
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.
! I removed the mapping in the MainContext and have it in the LocalContext so it now just gets fired once per component.
Sorry if you read through post 1 & 2 before seeing this. Amazing how strongly I believed it was something to do with event bubbling!
Support Staff 3 Posted by Shaun Smith on 16 Jul, 2010 02:02 PM
Reading your first post I am a little concerned with this part: "each of which is a mxml component with a local contextView".
How are you putting your app together? When building a normal (ie, non-modular) Robotlegs application there is only one
contextView
- a reference to the root view component that was passed to the context.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.
4 Posted by Brydges, Stephe... on 16 Jul, 2010 03:19 PM
Hi Shaun,
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!
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?
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.
Best wishes,
Steve
-----Original Message-----
From: Shaun Smith [mailto:[email blocked]]
Sent: 16 July 2010 15:04
To: Brydges, Stephen
Subject: Re: dispatching event from component [Problems]
Support Staff 5 Posted by Joel Hooks on 16 Jul, 2010 03:26 PM
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:
http://insideria.com/2010/06/an-introduction-to-robotlegs-a.html
http://wiki.github.com/robotlegs/robotlegs-framework/best-practices
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).
Support Staff 6 Posted by Shaun Smith on 17 Jul, 2010 10:47 AM
As Joel points out, that's not really a good model to follow.
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.
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:
http://github.com/robotlegs/robotlegs-demos-Bundle
I'd recommend starting with HelloFlex and FlickrImageGallery. Also, this document might clear up some stuff on the mechanical side:
http://wiki.github.com/robotlegs/robotlegs-framework/robotlegs-inte...
Stray closed this discussion on 16 Feb, 2011 09:05 PM.