Changing Views

nickt's Avatar

nickt

03 Apr, 2012 08:35 PM

Hello...

I've been searching for a similar question to mine and I found some helpful tips but not exactly what I need. Forgive the totally noob question but after working in a completely different way in Flex for 3 years, Robotlegs seems like a lot of fun but confusing in some parts as well.

I understand the role of all the classes in the framework and seeing the questions of other people as well, I've realized that having a model and a view that have similar concepts is not so bad and I can inject the model to my view.

So, suppose you have a StartView and a SecondView in the application. The start view handles some loading and when the loading is completed, it dispatches a custom event. Its mediator handles the event by dispatching a new application event which will probably be mapped in a command.
At exactly this point I'm lost on how the flow should continue. I want to change the visible view and navigate to the second so I was thinking of a mediator for the whole application. If that's the case then what should the command do?
If this approach is completely wrong then what would be the best practice for a use case like this.

Sorry if this has been asked a million times already. :)

  1. 1 Posted by Stray on 03 Apr, 2012 11:42 PM

    Stray's Avatar

    Hi Nick,

    I would mediate the whole app by mapping your contextView class to a mediator - the mediator will then be created immediately and will be ready to catch that event and can ask the contextView to switch the views over.

    Let me know if you need to do more...

    Stray

  2. 2 Posted by nickt on 04 Apr, 2012 11:23 AM

    nickt's Avatar

    I see.. This is what I thought as well but I was confused about including a command or not. For example, the solution you are suggesting does not include a command, as I can see it, the contextview mediator just listens for the event and does its job. Its fine and really easy but when should the commands be used then? Only in model-services scenarios?

  3. 3 Posted by Abel de Beer on 04 Apr, 2012 03:28 PM

    Abel de Beer's Avatar

    Hey Nick,

    Yes, Commands are most often used in Model / Service scenarios, as is displayed in the original flow diagram: http://www.robotlegs.org/diagram/

    Generally it's smart to remember this rule: if you want to manage Views, use Mediators.
    Also remember it's best practice to keep your Mediators as lean as possible: have them function only as Event receivers and dispatchers.

    Good luck!

  4. 4 Posted by nickt on 04 Apr, 2012 04:25 PM

    nickt's Avatar

    Thanks guys. Things are much more clarified now. :) For what its worth the framework really refreshed me when I was at weird point with my project. Refactoring has never been that much fun :)

  5. Ondina D.F. closed this discussion on 06 Apr, 2012 11:57 AM.

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