Where to get a reference to model when a mediator dispatches an event ?

combes.benjamin's Avatar

combes.benjamin

26 Jan, 2010 10:56 AM

Hi all !

I'm working on a Flash project displaying stacks on screen. So for example, on screen I have 3 stacks, all of them containing 10 elements. When a stack is clicked, I want the camera to zoom on stacks, and display details about each stack item. Then, I want to be able to click on a stack item to show more details about it.

All data (for stacks and stack-items) is parsed from an XML (Stacks & elements number, visual symbols used or details to display for instance), is stored into a Model (including Vector of VO for Stacks, each Stack containing a Vector of VO with data for stack items).

Then, when XML data has been parsed and stored into the model, a command parses this model to create the stacks on screen based on model-provided information.

I now want to capture when a stack is clicked to zoom on it. So I added an event listener to my StackMediator, which dispatches an Event, executing a StackClickedCommand. My problem is I don't get how I can get a reference to the corresponding stack in my model in this StackClickedCommand to know what I have to display for instance.

All solutions I found seem bad practice to me : do I have to keep a reference to the visual element in my model's Stack VO ? Do I have to keep a reference to my model in my StackMediator? Is there a more elegant solution?

This problem will be redunduant, because once zoomed on a stack, I have to be able to click on a stack-item to make another level of zoom and display a more detailed level of information.

Thanks a lot for you help !

  1. Support Staff 1 Posted by Shaun Smith on 26 Jan, 2010 01:56 PM

    Shaun Smith's Avatar

    You could make use of IDs - each stack VO would have an ID, and that ID would be passed to the stack view when you create it. Events dispatched by the stack's mediator would pass the ID as an event payload. The StackClickedCommand would use this ID to find the corresponding VO in the model.

    Does that help?

  2. 2 Posted by combes.benjamin on 26 Jan, 2010 02:05 PM

    combes.benjamin's Avatar

    Hi Shaun ! Thanks a lot for you really fast answer once again, thanks !!! I thought of this solution a while agoo too, but I just was wondering if something I didn't think of allready was doing this king of things in robotlegs. So that's perfect !
    I had another question on this project, but I'll post it in another thread to make it clearer for the comunity, thanks a lot once again for your really precious help !

  3. Support Staff 3 Posted by Shaun Smith on 26 Jan, 2010 02:08 PM

    Shaun Smith's Avatar

    My pleasure! The downside to this approach is that the view component itself ends up knowing about the application (more specifically it has to know about it's ID) - this is a side-effect of automatic mediator registration. Another option is to create and register the mediators manually - that way you can set the ID directly on the mediator rather than on the view component.

  4. 4 Posted by combes.benjamin on 26 Jan, 2010 02:12 PM

    combes.benjamin's Avatar

    Yes, in fact was thinking of storing this ID directly in the mediator itself, instead of using the view, as my views have to be fully decouplated from the system, it seems the best way to me to keep all independant, thanks again !

  5. Till Schneidereit closed this discussion on 02 Mar, 2010 12:46 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