| Package | potomac.core |
| Class | public class PotomacDispatcher |
| Inheritance | PotomacDispatcher flash.events.EventDispatcher |
[Handles] tag is the backbone
of the Potomac messaging system.
PotomacDispatcher manages two types of messaging. The first is the standard event dispatching available in Flash/Flex (and comes through via the EventDispatcher base class). The second is a leaner messaging system that doesn't require event classes. This system is available via the #addListener and #dispatch methods. The PotomacDispatcher calls the listeners with the arguments passed to the #dispatch. Therefore it is expected that the signature of the listener method match the arguments passed to #dispatch. It is important to note that this requirement means that adding a new field to the message requires an update to the function signature of the listener method (where as with the event-based pattern new fields can be added to the event without impacting the listener methods). Thus this technique creates a slightly more brittle API.
Clients may inject the PotomacDispatcher and call methods on it directly. Alternatively, if a
class is only required to listen for an event it may use the [Handles] tag with the
attribute global="true" and Potomac will wire the event listener automatically.
The PotomacDispatcher only uses weak references.
| Method | Defined By | ||
|---|---|---|---|
PotomacDispatcher should not be instantiated by clients. | PotomacDispatcher | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void [override]
| PotomacDispatcher | ||
addListener(type:String, listenerObject:Object, listenerName:String, priority:int = 0):void
Adds a message listener listening to messages of the given type. | PotomacDispatcher | ||
dispatch(type:String, ... args):void
Dispatches a message of the given type to all listeners, passing the given arguments. | PotomacDispatcher | ||
dispatchEvent(event:Event):Boolean [override] | PotomacDispatcher | ||
[static]
Returns the global PotomacDispatcher instance. | PotomacDispatcher | ||
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void [override] | PotomacDispatcher | ||
removeListener(type:String, listenerObject:Object, listenerName:String):void
Removes the given message listener. | PotomacDispatcher | ||
| PotomacDispatcher | () | Constructor |
public function PotomacDispatcher()PotomacDispatcher should not be instantiated by clients. It is available for injection instead.
| addEventListener | () | method |
override public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Parameters
type:String | |
listener:Function | |
useCapture:Boolean (default = false) | |
priority:int (default = 0) | |
useWeakReference:Boolean (default = false) |
| addListener | () | method |
public function addListener(type:String, listenerObject:Object, listenerName:String, priority:int = 0):voidAdds a message listener listening to messages of the given type.
Due to a bug in the Flash Player (https://bugs.adobe.com/jira/browse/FP-840), Potomac is unable to provide a method signature similar to #addEventListener. PotomacDispatcher uses weak references only by design. This particular bug prevents any Actionscript code from maintaining a weak reference to any Function. In order to provide the same functionality and maintain only a weak reference (an absolute requirement), Potomac requires a reference to the listening method's parent object and the name of the listening method. (Basically we're saying this weird API isn't our fault ;)
Parameters
type:String — message type to listen for.
| |
listenerObject:Object — Object containing the message listening function.
| |
listenerName:String — Name of the message listening function.
| |
priority:int (default = 0) |
| dispatch | () | method |
public function dispatch(type:String, ... args):voidDispatches a message of the given type to all listeners, passing the given arguments.
Parameters
type:String — message type.
| |
... args — arguments to pass to the listener methods.
|
| dispatchEvent | () | method |
override public function dispatchEvent(event:Event):BooleanParameters
event:Event |
Boolean |
| getInstance | () | method |
public static function getInstance():PotomacDispatcherReturns the global PotomacDispatcher instance.
This method goes against the design of dependency injection itself but is made available for pragmatic reasons. Internally, this method calls the global Injector to get the global PotomacDispatcher instance and so this method is not considered harmful.
ReturnsPotomacDispatcher |
| removeEventListener | () | method |
override public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):voidParameters
type:String | |
listener:Function | |
useCapture:Boolean (default = false) |
| removeListener | () | method |
public function removeListener(type:String, listenerObject:Object, listenerName:String):voidRemoves the given message listener.
Parameters
type:String — message type.
| |
listenerObject:Object — Object containing the message listening function.
| |
listenerName:String — Name of the message listening function.
|