Mapper

The mapper is the class that holds all the UI elements that have to be notified about an Instruction, so this is your event bus. It can be used at an application level or at a component level, you have to extends this singleton class following this sample and then put inside it an empty variable for each instruction in order to avoid that the compiler doesn't import the instructions class in the build.

package com.gnstudio.snippetrepobrowser.air.core	{

	       
	        import com.gnstudio.nabiro.mvp.instructions.InstructionEvent;
	        import com.gnstudio.nabiro.mvp.mapper.Mapper;
	    
	       
	        import flash.events.IEventDispatcher;
	
	
	        public class SnippetMapper extends Mapper{
	                               
	                private static var _instance:SnippetMapper  = new SnippetMapper ();
	               	               
	                /**
	                 * Compsition bugs fix.
	                 */
	                private var launchRegistration:LaunchRegistration;
	                
	                               
	                public function SnippetMapper (){
	                       
	                        if (_instance != null) throw new Error("SnippetMapper is obviously Singleton.");
	                       
	                       
	                }
	               
	                public static function getInstance(target:IEventDispatcher = null):SnippetMapper  {
	                                               
	                        if(target){
	                               
	               
	                                _instance.registerTarget(target);
	                               
	                        }
	               
	                        return _instance;
	                       
	                }
	               
	                override protected function onInstruction(e:InstructionEvent):void{
	                       
	                        try{
	                       
	                                super.onInstruction(e);
	                               
	                        }catch(error:Error){
	                               
	                                trace("\t", "Keep", e.toPerform, "on the system manager")       
	               
	                               
	                        }
	                       
	                        if(e.isPreventable){
	                               
	                                e.stopImmediatePropagation();
	                               
	                        }
	                       
	                       
	                }
	               
	               
	        }
	} 

Obviously you have to change the class name and the pacging in order to fit your needs. The Mapper the class derived from it have a bunch of methods:

  • register(element:IMapperCandidate):IMapperCandidate Register an element to the mapper and perform a check in order to avoid duplicates in the elements array
  • unregister(element:IMapperCandidate):IMapperCandidate Remove an element from the elements array and return the removed element
  • getInstance(target:IEventDispatcher = null):Mapper Method used to be sure that only an instance of the class will be created and to register the main target for instruction bubbling
  • getCurrentWatcher(view:IView):PresenterChangeDetector Get the current presenter interested in the update strategy

1.1.2-pro © 2008-2009 agile42 all rights reserved (this page was served in: 0.31000 sec.)