Events from nested components (Confirmation/Suggestions)

samac1068's Avatar

samac1068

06 Apr, 2011 06:36 PM

I've searched and found many resolutions to mediator issues, but I didn't find one that fit my question. Although I have a feeling this is a stupid question and I hate asking those, I'm at my wits end and am trying to avoid a refactor of my app. So let me try it out.

Attached you'll find an image of a single view. This view has its own mediator (which is working properly), but from there I have a component which through multiple other component calls displays my information. At the lowest level are links within a datagrid which needs to be listened for by the framework. So my question is, I know we can add mediators that are generated when the view is created and in most cases this is referred to as a Popup. I've used this method (http://knowledge.robotlegs.org/kb/reference-mvcs-implementation/how...) previously with success, but not sure if it will work here. My component isn't a popup but I must mediate it so I can listen for events. I wondering how should I go about this?

Any help would be greatly appreciated.

  1. 1 Posted by samac1068 on 07 Apr, 2011 05:31 PM

    samac1068's Avatar

    I've decided to use custom events within the children of the mediated view. To me, that appears dirty, but I have no other suggestions or idea. I'm going to keep it open just incase someone comes up with an idea. Thanks.

  2. Support Staff 2 Posted by creynders on 08 Apr, 2011 07:55 AM

    creynders's Avatar

    Mediators that are generated when a view is created are not referred to as popups. Popups are for instance Alert instances and they too can be mediated, but slightly differently than a "normal" component, that's what the link you gave describes.
    Whenever a component is added to the stage that is mapped to be mediated it's mediator will be instantiated automatically, that's normal procedure and has little to do with it being a popup or not.
    Now, on to your question. Basically you can mediate any display object that gets added to the stage. In reality it's a bit harder sometimes because you don't always have full control/access to a component's children, so in those cases you'll mediate the entire component instead of the children.
    It all depends on what you want to do actually. If I understand it correctly from your diagram, the lowest level display objects ('grid') dispatch events that need to be relayed to the framework??
    Then you have two choices, either you mediate each grid separately, or you mediate their container. From your diagram I can't deduce what the container would be. For instance what are those squares with the numbers in them? But let's say nr 2 is a canvas that contains those four grids, then you could let nr 2 listen to the events of all the grid objects and pass them to its mediator.

    And using custom events in a view's children is never a bad idea, on the contrary I'd advise using custom events as much as possible.

  3. 3 Posted by Amy on 08 Apr, 2011 01:37 PM

    Amy's Avatar

    The beauty of how RobotLegs works is that you don't need access to the children. If you let the mediators be created automatically by the Context, then they will automatically be attached to the renderer (for example) when it hits the display list, no matter how deeply nested it is.

    If you need to know about the data in the renderer to do whatever you're trying to do with your mediator, you need to add a view listener on its dataChange event in the onRegister() handler so that you can update the Mediator's state in line with the data.

    If you don't care about the data, you probably don't need to mediate at the renderer level anyway, because the link event bubbles, and you can handle it at a higher level.

    HTH;

    Amy

  4. Stray closed this discussion on 02 May, 2011 03:33 PM.

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