How to move logic from Mediator to a Command?

Gert-Jan van der Wel's Avatar

Gert-Jan van der Wel

11 Oct, 2011 09:41 AM

Hey everyone!!

I'm kinda new to Robotlegs. I think I got the basics down, but I need a bit of help with the following situation.

I have two views. One view (GlassView) catches all mouse and gesture events and its mediator sends those to the shared eventDispatcher. The mediator of the other view (SceneView) listens for the events, does some math and updates its view.

I have a feeling that the mediator shouldn't do the math and I want to be able to undo the action. So I think I should use a Command, but how would it work then?

  1. 1 Posted by krasimir on 11 Oct, 2011 09:48 AM

    krasimir's Avatar

    Hello,

    I think that your feeling is correct. It is better to map the events which are coming from GlassView to a command. Do the calculations there and then dispatch another events which should be handled by the ScrenView's mediator and update the SceneView.

  2. 2 Posted by Gert-Jan van de... on 11 Oct, 2011 10:02 AM

    Gert-Jan van der Wel's Avatar

    Wow, that's fast! Yea, so that's the trick. Let a Command do the calculations have it throw a new Event? Thanks.

  3. 3 Posted by krasimir on 11 Oct, 2011 10:07 AM

    krasimir's Avatar

    Yep. Or at least that's what I think is the better choice. As far as I know the job of the mediator is to make the connection between the controllers and the views. It's not a place for "logic" ;)

  4. Support Staff 4 Posted by creynders on 11 Oct, 2011 07:43 PM

    creynders's Avatar

    Or just move the calculations to the SceneView. View logic is meant to be in the view, there's no rule against having complex calculations in views. As long as the outcome of those calculations isn't used anywhere else, not even in other views, then there's no problem. Obviously if you're creating a very view-centric app, a game for instance, then the view data is possibly application data and then it would be appropriate to extract it out of the view.

  5. 5 Posted by Gert-Jan van de... on 12 Oct, 2011 07:08 AM

    Gert-Jan van der Wel's Avatar

    Ah yes, that's another good idea. That won't give me the undo option, but it is much simpler. Thnx.

  6. Ondina D.F. closed this discussion on 09 Nov, 2011 02:06 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