Created
January 19, 2011 21:42
-
-
Save Stray/786925 to your computer and use it in GitHub Desktop.
The actual service - map as a singleton and use getInstance to make it come to life
This file contains hidden or 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
| public class InterestingEventTypesLookup { | |
| protected var _eventClassesByType:Dictionary; | |
| public function get eventClassesByType():Dictionary | |
| { | |
| return _eventClassesByType ||= new Dictionary(); | |
| } | |
| public function appendEventInterest(eventClass:Class, eventType:String):void | |
| { | |
| eventClassesByType[eventType] = eventClass; | |
| } | |
| } |
This file contains hidden or 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
| public class ConfigureLoggingCommand { | |
| [Inject] | |
| public var interestingEventTypes:InterestingEventTypesLookup; | |
| public function execute():void | |
| { | |
| // for each event you care about | |
| interestingEventTypes.appendEventInterest(SomeEvent, SomeEvent.SOMETHING_WENT_DOWN); | |
| // then bring the actual logger to life | |
| injector.getInstance(LogginService); | |
| } | |
| } |
This file contains hidden or 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
| public class LoggingService extends Actor { | |
| [Inject] | |
| public var interestingEventTypes:InterestingEventTypesLookup; | |
| protected var eventMap:EventMap; // copy the event map imp from Mediator | |
| public function LoggingService() | |
| { | |
| registerListeners(); | |
| } | |
| protected function registerListeners():void | |
| { | |
| var eventClassesByType:Dictionary = interestingEventTypes.eventClassesByType; | |
| for (var eventType:Object in eventClassesByType) | |
| { | |
| var eventTypeStr:String = eventType as String; | |
| var eventClass:String = eventClassesByType[eventType]; | |
| eventMap.mapListener(eventDispatcher, eventTypeStr, logEvent, eventClass); | |
| } | |
| } | |
| protected function logEvent(e:Event):void | |
| { | |
| // do your thang with the event | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment