Switching between Views(e.g remove one and replace)

dhagenbln's Avatar

dhagenbln

12 Feb, 2014 01:59 PM

Hi, I got another Question.
Suppose you have one view with a Button and when that Button is clicked you want to remove that view from the Context View, get rid of all Mediators for that view and now add Another completely different view.

What I saw from those FlowCharts for RL2 I receive the Event in the Mediator, dispatch it again, have a mapped Command react to that and change the values in the Model, dispatching another event, have the Mediator receive it and change the view appropriatly. So now I wonder where would you get manipulate the View to add new Components?

I would guess I could dispatch an Event in the Mediator listen in another Mediator/Simple Class that has the contextView Injected and have it remove the old Components and add the new ones. Would that be recommended?

The scenario could be screen Switching in games etc.

Thanks again.

  1. Support Staff 1 Posted by Ondina D.F. on 12 Feb, 2014 03:00 PM

    Ondina D.F.'s Avatar

    I would guess I could dispatch an Event in the Mediator listen in another Mediator/Simple Class that has the contextView Injected and have it remove the old Components and add the new ones. Would that be recommended?

    Yes.
    If, say, ParentView is the one containing FirstChildView, FirstChildMediator would redispatch an event on behalf of its view, when the FirstChildView's button is clicked. ParentMediator would listen for that event and would let its view (ParentView) remove the FirstChildView and add a SecondChildView.
    FirstChildMediator will be removed automatically when FirstChildView leaves the stage (under normal conditions), and SecondChildMediator will be created automatically when SecondChildView is added to the stage.

    If you meant clicking a button inside of ParentView in order to switch between child-views, then PaentView removes FirstChildView and adds SecondChildView, and it dispatches an event for ParentMediator to re-dispatch it, in case there is a need for updating a Model

    As a general rule, mediated views should communicate with each other via their Mediators.
    Adding and removing child views/components should happen in the view.

  2. 2 Posted by dhagenbln on 12 Feb, 2014 07:53 PM

    dhagenbln's Avatar

    I appreciate your quick Answers. I have another unrelated Question but I guess I will open a new Discussion so it is easier to search for.

    Thanks.

  3. Support Staff 3 Posted by Ondina D.F. on 13 Feb, 2014 09:44 AM

    Ondina D.F.'s Avatar

    No problem!
    Yes, please start a new discussion for other questions. I'm going to close this for now.

  4. Ondina D.F. closed this discussion on 13 Feb, 2014 09:44 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