├── .gitignore ├── LICENSE ├── README ├── libs └── robotlegs-framework-v1.0.0.swc └── src └── org └── robotlegs └── utilities └── modular ├── base ├── ModuleCommandMap.as └── ModuleEventDispatcher.as ├── core ├── IModuleCommandMap.as ├── IModuleContext.as ├── IModuleContextView.as └── IModuleEventDispatcher.as └── mvcs ├── ModuleContext.as ├── ModuleContextView.as └── ModuleMediator.as /.gitignore: -------------------------------------------------------------------------------- 1 | .settings/* 2 | bin-debug/* 3 | bin-release/* 4 | html-template/* 5 | bin/* 6 | doc/* 7 | obj/* 8 | 9 | */.svn/* 10 | .actionScriptProperties 11 | .flexProperties 12 | .flexLibProperties 13 | .FlexUnitSettings 14 | .project 15 | 16 | Thumbs.db 17 | .DS_Store 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 the original author or authors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Some helper classes for building modular apps with Robotlegs. 2 | 3 | Note, if you are using Flex, or AS3 with Robotlegs 1.1 or later then please see the Joel Hooks fork instead: 4 | 5 | http://github.com/joelhooks/robotlegs-utilities-Modular 6 | 7 | This fork is frozen at this point PURELY for the convenience of the small number of early-adopters who are bound to using Robotlegs v 1.0.x 8 | 9 | 10 | 11 | -------------------------------- 12 | 13 | 14 | Modules should extend ModuleContextView. 15 | 16 | Each module requires a context, which should extend ModuleContext. 17 | 18 | The IModuleCommandMap and IModuleEventDispatcher work together to provide the modules with a shared event/command bus for inter-module events to take place. 19 | 20 | You need to provide each module with the shared ModuleEventDispatcher, and then run startup() on each module to kick things off. 21 | 22 | Please see the Robotlegs framework for more info. 23 | 24 | These classes were compiled to work with Robotlegs v1.0. -------------------------------------------------------------------------------- /libs/robotlegs-framework-v1.0.0.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stray/robotlegs-utilities-Modular/406cf2b346f4ac8bc7551041ec1ad2b0426d7d22/libs/robotlegs-framework-v1.0.0.swc -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/base/ModuleCommandMap.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.base 9 | { 10 | import org.robotlegs.base.CommandMap; 11 | import org.robotlegs.core.IInjector; 12 | import org.robotlegs.core.IReflector; 13 | import org.robotlegs.utilities.modular.core.IModuleCommandMap; 14 | import org.robotlegs.utilities.modular.core.IModuleEventDispatcher; 15 | 16 | public class ModuleCommandMap extends CommandMap implements IModuleCommandMap 17 | { 18 | public function ModuleCommandMap(eventDispatcher:IModuleEventDispatcher, injector:IInjector, reflector:IReflector) 19 | { 20 | super(eventDispatcher, injector, reflector); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/base/ModuleEventDispatcher.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.base 9 | { 10 | import flash.events.EventDispatcher; 11 | import flash.events.IEventDispatcher; 12 | 13 | import org.robotlegs.utilities.modular.core.IModuleEventDispatcher; 14 | 15 | public class ModuleEventDispatcher extends EventDispatcher implements IModuleEventDispatcher 16 | { 17 | public function ModuleEventDispatcher(target:IEventDispatcher = null) 18 | { 19 | super(target); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/core/IModuleCommandMap.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.core 9 | { 10 | import org.robotlegs.core.ICommandMap; 11 | 12 | public interface IModuleCommandMap extends ICommandMap 13 | { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/core/IModuleContext.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.core 9 | { 10 | 11 | public interface IModuleContext 12 | { 13 | function setModuleDispatcher(dispatcher:IModuleEventDispatcher):void; 14 | } 15 | } -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/core/IModuleContextView.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.core 9 | { 10 | 11 | public interface IModuleContextView 12 | { 13 | function setModuleDispatcher(dispatcher:IModuleEventDispatcher):void; 14 | 15 | function startup():void; 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/core/IModuleEventDispatcher.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.core 9 | { 10 | import flash.events.IEventDispatcher; 11 | 12 | public interface IModuleEventDispatcher extends IEventDispatcher 13 | { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/mvcs/ModuleContext.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.mvcs 9 | { 10 | import flash.display.DisplayObjectContainer; 11 | 12 | import org.robotlegs.mvcs.Context; 13 | import org.robotlegs.utilities.modular.base.ModuleCommandMap; 14 | import org.robotlegs.utilities.modular.core.IModuleCommandMap; 15 | import org.robotlegs.utilities.modular.core.IModuleContext; 16 | import org.robotlegs.utilities.modular.core.IModuleEventDispatcher; 17 | 18 | public class ModuleContext extends Context implements IModuleContext 19 | { 20 | protected var _isModuleDispatcherSet:Boolean; 21 | 22 | public function ModuleContext(contextView:DisplayObjectContainer = null) 23 | { 24 | // autostartup doesn't make sense in this set up because you need to run setModuleDispatcher before startup(); 25 | super(contextView, false); 26 | } 27 | 28 | override public function startup():void 29 | { 30 | if (!_isModuleDispatcherSet) 31 | { 32 | trace("DIAGNOSTIC HELPER: You need to set up the module dispatcher before you can run startup. If your app bails now... you'll know why.") 33 | } 34 | super.startup(); 35 | } 36 | 37 | public function setModuleDispatcher(dispatcher:IModuleEventDispatcher):void 38 | { 39 | injector.mapValue(IModuleEventDispatcher, dispatcher); 40 | injector.mapValue(IModuleCommandMap, new ModuleCommandMap(dispatcher, injector, reflector)); 41 | 42 | _isModuleDispatcherSet = true; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/mvcs/ModuleContextView.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.mvcs 9 | { 10 | import flash.display.Sprite; 11 | 12 | import org.robotlegs.utilities.modular.core.IModuleContextView; 13 | import org.robotlegs.utilities.modular.core.IModuleEventDispatcher; 14 | 15 | public class ModuleContextView extends Sprite implements IModuleContextView 16 | { 17 | protected var context:ModuleContext; 18 | 19 | public function ModuleContextView() 20 | { 21 | } 22 | 23 | public function setModuleDispatcher(dispatcher:IModuleEventDispatcher):void 24 | { 25 | context.setModuleDispatcher(dispatcher); 26 | } 27 | 28 | public function startup():void 29 | { 30 | context.startup(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/org/robotlegs/utilities/modular/mvcs/ModuleMediator.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009 the original author or authors 3 | * 4 | * Permission is hereby granted to use, modify, and distribute this file 5 | * in accordance with the terms of the license agreement accompanying it. 6 | */ 7 | 8 | package org.robotlegs.utilities.modular.mvcs 9 | { 10 | import org.robotlegs.mvcs.Mediator; 11 | import org.robotlegs.utilities.modular.core.IModuleEventDispatcher; 12 | import org.robotlegs.utilities.modular.core.IModuleCommandMap; 13 | 14 | import flash.events.Event; 15 | 16 | public class ModuleMediator extends Mediator 17 | { 18 | [Inject] 19 | public var moduleDispatcher:IModuleEventDispatcher; 20 | 21 | [Inject] 22 | public var moduleCommandMap:IModuleCommandMap; 23 | 24 | 25 | // Helper functions for passing events between / around modules 26 | protected function redispatchToModules(e:Event):void{ 27 | moduleDispatcher.dispatchEvent(e); 28 | } 29 | 30 | protected function redispatchInternally(e:Event):void{ 31 | // you could equally use the dispatch(e) helper, but sometimes longhand offers clarity 32 | eventDispatcher.dispatchEvent(e); 33 | } 34 | 35 | // extra sugar to reduce boilerplate on the transfer of events 36 | protected function mapRedispatchInternally(eventType:String):void{ 37 | eventMap.mapListener(moduleDispatcher, eventType, redispatchInternally); 38 | } 39 | 40 | protected function mapRedispatchToModules(eventType:String):void{ 41 | eventMap.mapListener(eventDispatcher, eventType, redispatchToModules); 42 | } 43 | 44 | 45 | } 46 | 47 | } --------------------------------------------------------------------------------