Remove/Add View?

Fabian's Avatar

Fabian

25 Nov, 2009 10:33 AM

Hi there,
what is the best way to remove a view/mediator and change to the next view/mediator (i am not using flex)?

// does robotlegs offers any utils?

  1. Support Staff 1 Posted by Till Schneidere... on 25 Nov, 2009 10:36 AM

    Till Schneidereit's Avatar

    Hi Fabian,

    could you explain a bit more what it is you're trying to accomplish?
    Views and their mediators can be added/ removed in many ways so it
    would be helpful to know a bit more.

    thanks,
    till

  2. 2 Posted by Fabian on 25 Nov, 2009 10:48 AM

    Fabian's Avatar

    Ok, it's a realysimple "twitter-reader" (Reading Tweets by Username).

    In my first view, the user can enter the username.
    In my second view, i show a list of tweets and a back-button (to first view).

    I'am not sure how to change between these to views. They must be added/removed somehow by someone.

    g.

  3. Support Staff 3 Posted by Till Schneidere... on 25 Nov, 2009 10:54 AM

    Till Schneidereit's Avatar

    For such a small app, I'd recommend keeping both views around and just
    hiding the inactive one. Use a model to store view state, i.e. which
    view should be active. Let the model dispatch some sort of id for the
    view that should be visible and hide the other one in the mediators
    listener for that event.
    Another option would be to register the mediators with the model and
    let the model keep track of which view is active. That way, you could
    grow the number of views without having lots of duplicated activity in
    the mediators on each view change.

  4. 4 Posted by Fabian on 25 Nov, 2009 01:47 PM

    Fabian's Avatar

    Ok.

    My ListView fires:
    dispatchEvent(new Event(TweetListView.BACK, true));

    The ListViewMediator listens:
    eventMap.mapListener(tweetListView, TweetListView.BACK, handleBackButton);
    and relays the event to the framework
    function handleBackButton(event : Event) : void { dispatch(event); }

    My SeachViewMedator listens.
    eventMap.mapListener(eventDispatcher, TweetListView.BACK, handleBackButton);
    BUT: I dont get any events here ;-(

    Whats wrong?

  5. Support Staff 5 Posted by Till Schneidere... on 25 Nov, 2009 01:57 PM

    Till Schneidereit's Avatar

    Looks like it should be working. Have you verified that the
    dispatch(event) happens, i.e. that handleBackButton gets called?

  6. 6 Posted by Fabian on 25 Nov, 2009 02:42 PM

    Fabian's Avatar

    The Events gets fired.
    But only one of the two mediators recieves it.

    Same with a Framework event of my TwitterService. MediatorA gets the events, MediatorB (the bad one) not.

  7. Support Staff 7 Posted by Till Schneidere... on 25 Nov, 2009 02:48 PM

    Till Schneidereit's Avatar

    That's really weird.

    Can you maybe attach the mediator class that's not working (and,
    ideally, also the working one). You can strip out the proprietary
    pieces, of course.

  8. 8 Posted by Fabian on 25 Nov, 2009 02:51 PM

    Fabian's Avatar

    damn, i missed a removeMediator() – sry.
    Now everythings works fine.

  9. Support Staff 9 Posted by Till Schneidere... on 25 Nov, 2009 02:54 PM

    Till Schneidereit's Avatar

    Cool, glad it worked out!

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