mediatorMap.removeMediator in Commands?
Hey,
So I thought id spend a lazy saturday looking in to RobotLegs, hit a bump in the road with the example I'm building which is removing a Mediator and its View from within a Command eg below:
' package com.flashlounge.robotlegs.controller {
import com.flashlounge.robotlegs.view.mediators.PreloaderMediator;
import com.flashlounge.robotlegs.view.Intro;
import org.osflash.thunderbolt.Logger;
import org.robotlegs.mvcs.SignalCommand;
/**
* @author karlfreeman
*/
public class ApplicationLoadedCommand extends SignalCommand {
override public function execute():void {
Logger.info("ApplicationLoadedCommand.execute()");
var intro : Intro = new Intro();
contextView.addChild(intro);
mediatorMap.removeMediator(PreloaderMediator);
}
}
} '
The application is a simple one but all I want to do is remove a Mediator during addition of the next View ( Something which in PureMVC is pretty simple ) Is this possible in RobotLegs? Or would the solution be to create an event to remove a mediator and dispatch it from within the command?
Thanks for the hard work!
Karl.
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
Support Staff 1 Posted by Shaun Smith on 04 Sep, 2010 06:53 PM
Howdy!
removeMediator(mediator:IMediator) expects an IMediator instance not a class reference - how will it know which instance to remove if you pass it a class? While it's not advisable to directly manipulate mediators from the model, service or controller tiers, you certainly can if you want to.
All you need is a reference to the mediator that you want to remove (or a reference to its view component). To inject such an instance into your command you might map it into the injector (with injector.mapValue) after you create it (or in the mediator's onRegister hook if you are using automatic mediation).
On the other hand, you could simply get the mediator to listen for the same event that triggers the command, and have it remove itself in response. If you are using automatic mediation you could just pop the view component off the display list and the mediator will be automatically removed. Or, just call mediatorMap.removeMediator(this); which will leave the view component on-screen.
2 Posted by Karl Freeman on 04 Sep, 2010 07:15 PM
Thanks for the support! Got a good example working now that I can compare and contrast with my normal way of PureMVC'ing. Much appreciated!
Stray closed this discussion on 10 Feb, 2011 05:44 PM.