-
-
Save darscan/483069 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.visfleet.robotlegs { | |
import flash.display.DisplayObject; | |
import flash.display.DisplayObjectContainer; | |
import org.robotlegs.base.ContextEvent; | |
import org.robotlegs.core.IMediatorMap; | |
import org.robotlegs.mvcs.Actor; | |
public class Presenter extends Actor { | |
[Inject] | |
public var contextView:DisplayObjectContainer; | |
[Inject] | |
public var mediatorMap:IMediatorMap; | |
public var _parentView:DisplayObject; | |
[PostConstruct] | |
public function _ready():void { | |
addContextListener(ContextEvent.SHUTDOWN, handleShutdown, ContextEvent); | |
onReady(); | |
} | |
/** | |
* Called when the <code>Presenter</code> is constructed, has injections, and is configured. | |
* | |
* <p> Override this method for your startup code. Much as you would use <code>onRegister</code> | |
* in <code>Mediator</code></p> | |
*/ | |
public function onReady():void { | |
} | |
/** | |
* Starts the <code>beforeDispose</code>, remove event map, <code>afterDispose</code> sequence. | |
* | |
* <p>Call this when you are disposing the view component.</p> | |
* <p>You do not need to dispose of the <code>Presenter</code> if you are only taking the | |
* view off the display list.</p> | |
*/ | |
public function dispose():void { | |
beforeDispose(); | |
_removeListeners(); | |
afterDispose(); | |
} | |
private function handleShutdown(event:ContextEvent):void { | |
dispose(); | |
} | |
/** | |
* Called when the <code>Presenter</code> is about to be disposed. | |
* | |
* <p> Override this method to clean up the class, before the <code>eventMap</code> is disposed of.</p> | |
*/ | |
public function beforeDispose():void { | |
} | |
/** | |
* Called when the <code>Presenter</code> is about to be disposed. | |
* | |
* <p> Override this method to clean up the class, after the <code>eventMap</code> is disposed of.</p> | |
*/ | |
public function afterDispose():void { | |
} | |
public function _removeListeners():void { | |
if (_eventMap) | |
_eventMap.unmapListeners(); | |
eventDispatcher.removeEventListener(ContextEvent.SHUTDOWN, handleShutdown); | |
} | |
/** | |
* Syntactical sugar for mapping a listener to an <code>IEventDispatcher</code> | |
* | |
* @param type | |
* @param listener | |
* @param eventClass | |
* @param useCapture | |
* @param priority | |
* @param useWeakReference | |
* | |
*/ | |
//noinspection OverlyComplexFunctionJS | |
protected function addContextListener(type:String, listener:Function, eventClass:Class = null, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = true):void | |
{ | |
eventMap.mapListener(eventDispatcher, type, listener, | |
eventClass, useCapture, priority, useWeakReference); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment