├── .gitignore ├── .munit ├── CHANGES.md ├── LICENSE ├── README.md ├── build └── Build.hx ├── example ├── README.md ├── build.hxml ├── build │ ├── Main.exe │ ├── css │ │ └── index.css │ ├── data │ │ └── data.json │ ├── img │ │ ├── done.png │ │ └── none.png │ └── index.html └── src │ ├── Main.hx │ ├── example │ ├── app │ │ ├── ApplicationContext.hx │ │ ├── ApplicationView.hx │ │ └── ApplicationViewMediator.hx │ ├── core │ │ ├── DataView.hx │ │ └── View.hx │ └── todo │ │ ├── command │ │ └── LoadTodoListCommand.hx │ │ ├── model │ │ ├── Todo.hx │ │ └── TodoList.hx │ │ ├── signal │ │ └── LoadTodoList.hx │ │ └── view │ │ ├── TodoListView.hx │ │ ├── TodoListViewMediator.hx │ │ ├── TodoStatsView.hx │ │ └── TodoView.hx │ └── mcore │ ├── README │ ├── data │ ├── ArrayList.hx │ ├── Collection.hx │ └── CollectionBase.hx │ ├── loader │ ├── HTTPLoader.hx │ ├── JSONLoader.hx │ ├── Loader.hx │ └── LoaderBase.hx │ └── util │ ├── Arrays.hx │ ├── Iterables.hx │ ├── Strings.hx │ └── Types.hx ├── lib.json ├── mdk ├── info.config └── lib.config ├── project.json ├── src ├── haxelib.json ├── haxelib.xml └── mmvc │ ├── api │ ├── ICommand.hx │ ├── ICommandMap.hx │ ├── IContext.hx │ ├── IGuard.hx │ ├── IGuardedCommandMap.hx │ ├── IMediator.hx │ ├── IMediatorMap.hx │ ├── ITriggerMap.hx │ ├── IViewContainer.hx │ └── IViewMap.hx │ ├── base │ ├── CommandMap.hx │ ├── ContextError.hx │ ├── GuardedCommandMap.hx │ ├── MediatorBase.hx │ ├── MediatorMap.hx │ ├── TriggerMap.hx │ ├── ViewMap.hx │ └── ViewMapBase.hx │ └── impl │ ├── Actor.hx │ ├── Command.hx │ ├── Context.hx │ ├── Mediator.hx │ ├── TriggerCommand.hx │ └── TriggerMediator.hx ├── target └── haxelib │ └── haxedoc.xml.hxml └── test ├── TestMain.hx ├── mmvc ├── base │ ├── CommandMapTest.hx │ ├── MediatorMapTest.hx │ ├── TriggerMapTest.hx │ ├── ViewMapTest.hx │ └── support │ │ ├── ITestView.hx │ │ ├── MockClass.hx │ │ ├── MockEnum.hx │ │ ├── MockResult.hx │ │ ├── TestCommand.hx │ │ ├── TestCommand1.hx │ │ ├── TestCommand2.hx │ │ ├── TestContextView.hx │ │ ├── TestSignal.hx │ │ ├── TestSignal2.hx │ │ ├── TestView.hx │ │ ├── TriggerCommand_EnumValue.hx │ │ ├── TriggerCommand_Instance.hx │ │ ├── TriggerCommand_Int.hx │ │ ├── TriggerCommand_MockClass.hx │ │ └── TriggerCommand_String.hx └── impl │ ├── ActorTest.hx │ ├── CommandTest.hx │ ├── ContextTest.hx │ └── support │ ├── ICommandTester.hx │ ├── TestActor.hx │ ├── TestCommand.hx │ ├── TestContext.hx │ ├── TestContextView.hx │ ├── TestContextViewMediator.hx │ ├── ViewComponent.hx │ ├── ViewComponentAdvanced.hx │ ├── ViewMediator.hx │ └── ViewMediatorAdvanced.hx └── targets.hxml /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /.temp 3 | /lib 4 | /mmvc.iml 5 | 6 | Icon 7 | Thumbs.db 8 | .DS_Store 9 | TestSuite.hx 10 | 11 | example.js 12 | example.n 13 | example.swf 14 | 15 | /example/build/Main 16 | /example/build/example_cpp/ 17 | .mcover 18 | /MassiveMVC.iml 19 | /.idea/ 20 | *.hxproj 21 | example/build/** 22 | 23 | .haxelib 24 | /haxelib.json 25 | -------------------------------------------------------------------------------- /.munit: -------------------------------------------------------------------------------- 1 | version=0.9.4.2 2 | src=test 3 | bin=bin/test 4 | report=bin/test-report 5 | hxml=test/targets.hxml 6 | classPaths=src 7 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | ## 1.6.3 2 | 3 | - Updated README.md and relase information 4 | 5 | ## 1.6.2 6 | 7 | - Fixes TriggerMap for Haxe 3.2.1+ 8 | - Fixed enum bug where an enum trigger would not fire the command, added support for Int triggers 9 | - Added unit test for unsupported type and added missing unmap call 10 | 11 | ## 1.6.1 12 | 13 | - Type fix for Haxe 3.0.0 14 | 15 | ## 1.6.0 16 | 17 | - Fixes #17: adds TriggerMap to allow mapping of TriggeredCommands to various types 18 | 19 | ## 1.5.0 20 | 21 | - Added hamcrest dependency 22 | - - Use 'remove' instead of 'delete' on maps (as delete is reserved on some platforms and messes with optimization in closure) - Code style. 23 | - Add dce support using @:keep metadata where appropriate - Remove support for haxe < 2.x - General code cleanup - Upgrade minject dependency 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Massive Interactive 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | 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 THE 19 | SOFTWARE. 20 | 21 | RobotLegs License: 22 | 23 | The MIT License 24 | 25 | Copyright (c) 2009, 2010 the original author or authors 26 | 27 | Permission is hereby granted, free of charge, to any person obtaining a copy 28 | of this software and associated documentation files (the "Software"), to deal 29 | in the Software without restriction, including without limitation the rights 30 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 31 | copies of the Software, and to permit persons to whom the Software is 32 | furnished to do so, subject to the following conditions: 33 | 34 | The above copyright notice and this permission notice shall be included in 35 | all copies or substantial portions of the Software. 36 | 37 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 38 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 39 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 40 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 41 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 42 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 43 | THE SOFTWARE. 44 | -------------------------------------------------------------------------------- /build/Build.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | import mtask.target.HaxeLib; 24 | import mtask.target.Directory; 25 | 26 | class Build extends mtask.core.BuildBase 27 | { 28 | public function new() 29 | { 30 | super(); 31 | } 32 | 33 | @target function haxelib(target:HaxeLib) 34 | { 35 | target.url = "http://github.com/massiveinteractive/mmvc"; 36 | target.description = "A Haxe port of the ActionScript 3 RobotLegs MVC framework with signals and Haxe refinements. Supports AVM1, AVM2, JavaScript, Neko and C++."; 37 | target.versionDescription = "Add TriggerMap"; 38 | target.username = "massive"; 39 | 40 | // some of our dependencies haven't been released, add the ones that have manually 41 | untyped target.dependencies = []; 42 | target.addDependency("msignal"); 43 | target.addDependency("minject"); 44 | 45 | target.addTag("cross"); 46 | target.addTag("massive"); 47 | target.addTag("mvc"); 48 | 49 | target.beforeCompile = function(path) 50 | { 51 | cp("src/*", path); 52 | } 53 | } 54 | 55 | @target function example(target:Directory) 56 | { 57 | target.beforeCompile = function(path) 58 | { 59 | mkdir(path); 60 | cp("example/*", path); 61 | } 62 | } 63 | 64 | @task function test() 65 | { 66 | cmd("haxelib", ["run", "munit", "test", "-coverage"]); 67 | } 68 | 69 | @task function teamcity() 70 | { 71 | invoke("test"); 72 | cmd("haxelib", ["run", "munit", "report", "teamcity"]); 73 | 74 | invoke("build haxelib"); 75 | invoke("build example"); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | Todo App 2 | ============ 3 | 4 | This is a simple application demonstrating the main components of MMVC, running 5 | across JS, Flash and Neko targets. 6 | 7 | > This application requires Haxe 3.0 or greater. 8 | 9 | Overview 10 | ----------- 11 | 12 | This is a partially implemented Todo application, demonstrating the core 13 | elements of MMVC 14 | 15 | * configuring application via a Context (`ApplicationContext`) 16 | * loads a list of Todos from a file via a Command (`LoadTodoListCommand`) 17 | * updating contents of a managed Model (`TodoList`) 18 | * triggering commands via a Signal and listens to responses (`LoadTodoList`) 19 | * instanciating Mediators for registered Views (`ApplicationViewMediator`, 20 | `TodoListViewMediator`) 21 | 22 | 23 | Building the app 24 | ---------------- 25 | 26 | Compile the js, flash and neko targets via the hxml file: 27 | 28 | haxe build.hxml 29 | 30 | 31 | Application Structure 32 | --------------------- 33 | 34 | The application source contains the following classes: 35 | 36 | Main.hx // main entry point, instanciates application view and context 37 | 38 | /example 39 | 40 | /app // main application module 41 | 42 | ApplicationContext.hx // application Context 43 | ApplicationView.hx // application View 44 | ApplicationViewMediator.hx // application Mediator 45 | 46 | /core // bare-bones cross platform View classes 47 | 48 | View.hx // simple cross platform View class with concrete implementations for JS and Flash 49 | DataView // View with typed data property (useful for Views bound to a specific data object) 50 | 51 | /todo 52 | 53 | /command 54 | LoadTodoListCommand.hx // MMVC Command for loading external TodoList 55 | /model 56 | Todo.hx // todo data object 57 | TodoList.hx // collection of todos 58 | /signal 59 | LoadTodoList.hx // signal for loading TodoList and handling responses 60 | /view 61 | TodoListView.hx // View for TodoList 62 | TodoListViewMediator.hx // Mediator for TodoList. Triggers call to LoadTodoList 63 | TodoView.hx // View for inidividual Todo items 64 | TodoStatsView.hx // Summary of current todo list + button to create new Todo 65 | 66 | -------------------------------------------------------------------------------- /example/build.hxml: -------------------------------------------------------------------------------- 1 | -main Main 2 | -cp src 3 | -lib mmvc 4 | -js build/example.js 5 | 6 | --next 7 | 8 | -main Main 9 | -cp src 10 | -lib mmvc 11 | -swf build/example.swf 12 | 13 | --next 14 | 15 | -main Main 16 | -cp src 17 | -lib mmvc 18 | -neko build/example.n 19 | 20 | 21 | --next 22 | 23 | -main Main 24 | -cp src 25 | -lib mmvc 26 | -cpp build/example_cpp 27 | 28 | -cmd cp -rf build/example_cpp/Main build/Main 29 | -cmd build/Main 30 | -------------------------------------------------------------------------------- /example/build/Main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/massive-oss/mmvc/9382fbeff7f72bfcb0377a593ae344ca221afcf7/example/build/Main.exe -------------------------------------------------------------------------------- /example/build/css/index.css: -------------------------------------------------------------------------------- 1 | * 2 | { 3 | padding:0; 4 | margin:0; 5 | } 6 | 7 | 8 | .TodoView 9 | { 10 | margin:10px; 11 | padding-left:20px; 12 | background: url('../img/none.png') no-repeat 0 0; 13 | } 14 | 15 | .done 16 | { 17 | background: url('../img/done.png') no-repeat 0 0; 18 | } 19 | 20 | .TodoStatsView 21 | { 22 | background-color: #CCC; 23 | padding: 10px; 24 | margin: 0px; 25 | } 26 | 27 | .TodoStatsView a 28 | { 29 | padding: 4px;border: solid #AAA 2px; 30 | margin-left: 10px; 31 | } -------------------------------------------------------------------------------- /example/build/data/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "items": 3 | [ 4 | {"name":"Item 1", "done":true}, 5 | {"name":"Item 2", "done":true}, 6 | {"name":"Item 3", "done":false}, 7 | {"name":"Item 4", "done":false} 8 | ] 9 | } -------------------------------------------------------------------------------- /example/build/img/done.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/massive-oss/mmvc/9382fbeff7f72bfcb0377a593ae344ca221afcf7/example/build/img/done.png -------------------------------------------------------------------------------- /example/build/img/none.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/massive-oss/mmvc/9382fbeff7f72bfcb0377a593ae344ca221afcf7/example/build/img/none.png -------------------------------------------------------------------------------- /example/build/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | haXe JS 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /example/src/Main.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | class Main 24 | { 25 | /** 26 | Instanciates the main ApplicationView and the ApplicationContext. 27 | This will trigger the ApplicationViewMediator and kick the application off. 28 | */ 29 | public static function main() 30 | { 31 | var view = new example.app.ApplicationView(); 32 | var context = new example.app.ApplicationContext(view); 33 | } 34 | } -------------------------------------------------------------------------------- /example/src/example/app/ApplicationContext.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.app; 24 | 25 | import mmvc.api.IViewContainer; 26 | 27 | 28 | // Main Application 29 | import example.app.ApplicationView; 30 | import example.app.ApplicationViewMediator; 31 | 32 | // TODO Module 33 | import example.todo.signal.LoadTodoList; 34 | import example.todo.command.LoadTodoListCommand; 35 | import example.todo.model.TodoList; 36 | import example.todo.view.TodoListView; 37 | import example.todo.view.TodoListViewMediator; 38 | 39 | 40 | /** 41 | Application wide context. 42 |

Provides mapping of following classes: 43 |

48 |

49 | @see mmvc.impl.Context 50 | */ 51 | class ApplicationContext extends mmvc.impl.Context 52 | { 53 | public function new(?contextView:IViewContainer=null) 54 | { 55 | super(contextView); 56 | } 57 | 58 | /** 59 | Overrides startup to configure all context commands, models and mediators 60 | @see mmvc.impl.Context 61 | */ 62 | override public function startup() 63 | { 64 | // wiring for todo model 65 | commandMap.mapSignalClass(LoadTodoList, LoadTodoListCommand); 66 | 67 | injector.mapSingleton(TodoList); 68 | 69 | mediatorMap.mapView(TodoListView, TodoListViewMediator); 70 | 71 | // wiring for main application module 72 | mediatorMap.mapView(ApplicationView, ApplicationViewMediator); 73 | } 74 | 75 | /** 76 | Overrides shutdown to remove/cleanup mappings 77 | @see mmvc.impl.Context 78 | */ 79 | override public function shutdown() 80 | { 81 | 82 | } 83 | } -------------------------------------------------------------------------------- /example/src/example/app/ApplicationView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.app; 24 | 25 | import example.core.View; 26 | 27 | /** 28 | Main Application View. 29 | 30 | Implements IViewContainer to provide view added/removed events back to the Context.mediatorMap 31 | 32 | Extends core view class for basic event bubbling across platforms 33 | 34 | @see example.core.View 35 | @see mmvc.api.IViewContainer 36 | */ 37 | 38 | class ApplicationView extends View implements mmvc.api.IViewContainer 39 | { 40 | public var viewAdded:Dynamic -> Void; 41 | public var viewRemoved:Dynamic -> Void; 42 | 43 | public function new() 44 | { 45 | super(); 46 | } 47 | 48 | /** 49 | Called by ApplicationViewMediator once application is wired up to the context 50 | @see ApplicationViewMediator.onRegister; 51 | */ 52 | public function createViews() 53 | { 54 | var todoView = new example.todo.view.TodoListView(); 55 | addChild(todoView); 56 | } 57 | 58 | /** 59 | Overrides signal bubbling to trigger view added/removed handlers for IViewContainer 60 | @param event a string event type 61 | @param view instance of view that originally dispatched the event 62 | */ 63 | override public function dispatch(event:String, view:View) 64 | { 65 | switch(event) 66 | { 67 | case View.ADDED: 68 | { 69 | viewAdded(view); 70 | } 71 | case View.REMOVED: 72 | { 73 | viewRemoved(view); 74 | } 75 | default: 76 | { 77 | super.dispatch(event, view); 78 | } 79 | } 80 | } 81 | 82 | /** 83 | Required by IViewContainer 84 | */ 85 | public function isAdded(view:Dynamic):Bool 86 | { 87 | return true; 88 | } 89 | 90 | /** 91 | Overrides View.initialize to add to top level platform specific sprite/element 92 | */ 93 | override function initialize() 94 | { 95 | super.initialize(); 96 | #if flash 97 | flash.Lib.current.addChild(sprite); 98 | #elseif js 99 | js.Browser.document.body.appendChild(element); 100 | #end 101 | } 102 | } -------------------------------------------------------------------------------- /example/src/example/app/ApplicationViewMediator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.app; 24 | 25 | import example.todo.signal.LoadTodoList; 26 | import example.todo.model.TodoList; 27 | import example.todo.model.Todo; 28 | 29 | /** 30 | Main application view mediator. 31 | 32 | Responsible for triggering sub view creation once application is wired up to the context 33 | 34 | @see ApplicationView 35 | */ 36 | class ApplicationViewMediator extends mmvc.impl.Mediator 37 | { 38 | public function new() 39 | { 40 | super(); 41 | } 42 | 43 | /** 44 | Context has now been initialized. Time to create the rest of the main views in the application 45 | @see mmvc.impl.Mediator.onRegister() 46 | */ 47 | override function onRegister() 48 | { 49 | super.onRegister(); 50 | view.createViews(); 51 | } 52 | 53 | /** 54 | @see mmvc.impl.Mediator 55 | */ 56 | override public function onRemove():Void 57 | { 58 | super.onRemove(); 59 | } 60 | } -------------------------------------------------------------------------------- /example/src/example/core/DataView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.core; 24 | 25 | /** 26 | A Typed data view using Haxe generics. 27 | Provides a simple contract for typed data property and associated events 28 | */ 29 | class DataView extends View 30 | { 31 | /** 32 | Event type dispatched when data is modified 33 | @see DataView.setData() 34 | */ 35 | inline public static var DATA_CHANGED:String = "dataChanged"; 36 | 37 | /** 38 | Typed data property 39 | */ 40 | public var data(default, null):T; 41 | 42 | 43 | /** 44 | Reference to previous data object 45 | */ 46 | var previousData(default, null):T; 47 | 48 | /** 49 | Optionally set a data property during construction 50 | */ 51 | public function new(?data:T) 52 | { 53 | super(); 54 | setData(data); 55 | } 56 | 57 | /** 58 | Sets the data property and triggers a DATA_CHANGED event 59 | @param data data to set 60 | @param force forces change even if data object is identical 61 | */ 62 | public function setData(data:T, ?force:Bool=false) 63 | { 64 | if (this.data != data || force == true) 65 | { 66 | 67 | previousData = this.data; 68 | 69 | this.data = data; 70 | 71 | dataChanged(); 72 | update(); 73 | dispatch(DATA_CHANGED, this); 74 | } 75 | } 76 | 77 | /** 78 | Updates instance specific properties and state when data changes 79 | */ 80 | function dataChanged() 81 | { 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /example/src/example/core/View.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.core; 24 | 25 | #if flash 26 | import flash.display.Sprite; 27 | #elseif js 28 | import js.Lib; 29 | import js.Browser; 30 | import js.html.Element; 31 | #end 32 | import msignal.Signal; 33 | 34 | /** 35 | Simple implementation of a cross platform View class that composes a 36 | native element/sprite depending on platform. 37 | 38 | Contains a basic display lifecycle (initialize, update, remove) 39 | Contains a basic display hierarchy (addChild, removeChild) 40 | Contains basic dispatching and bubbling via a Signal (dispatch) 41 | 42 | Each target has a platform specific element for accessing the raw display API (flash: sprite, js: element) 43 | 44 | @see msignal.Signal 45 | @see DataView 46 | 47 | */ 48 | class View 49 | { 50 | /** 51 | Event type dispatched when view is added to stage 52 | @see View.addChild() 53 | */ 54 | inline public static var ADDED:String = "added"; 55 | 56 | /** 57 | Event type dispatched when view is removed from stage 58 | @see View.removeChild() 59 | */ 60 | inline public static var REMOVED:String = "removed"; 61 | 62 | /** 63 | Event type dispatched when view is actioned (e.g. clicked) 64 | */ 65 | inline public static var ACTIONED:String = "actioned"; 66 | 67 | /** 68 | private counter to maintain unique identifieds for created views 69 | */ 70 | static var idCounter:Int = 0; 71 | 72 | /** 73 | Unique identifier (viewXXX); 74 | */ 75 | public var id(default, null):String; 76 | 77 | /** 78 | reference to parent view (if available) 79 | @see View.addChild() 80 | @see View.removeChild() 81 | */ 82 | public var parent(default, null):View; 83 | 84 | /** 85 | reference to the index relative to siblings 86 | defaults to -1 when view has no parent 87 | @see View.addChild() 88 | */ 89 | public var index(default, set):Int; 90 | 91 | 92 | /** 93 | Signal used for dispatching view events 94 | Usage: 95 | view.addListener(viewHandler); 96 | ... 97 | function viewHandler(event:String, view:View); 98 | */ 99 | public var signal(default, null):Signal2; 100 | 101 | #if flash 102 | 103 | /** 104 | native flash sprite representing this view in the display list 105 | */ 106 | public var sprite(default, null):Sprite; 107 | 108 | #elseif js 109 | 110 | /** 111 | native html element representing this view in the DOM 112 | */ 113 | public var element(default, null):Element; 114 | 115 | /** 116 | Optional tag name to use when creating element via Lib.document.createElement 117 | defaults to 'div' 118 | */ 119 | var tagName:String; 120 | #end 121 | 122 | /** 123 | Contains all children currently added to view 124 | */ 125 | var children:Array; 126 | 127 | /** 128 | String representation of unqualified class name 129 | (e.g. example.core.View.className == "View"); 130 | */ 131 | var className:String; 132 | 133 | public function new() 134 | { 135 | //create unique identifier for this view 136 | id = "view" + (idCounter ++); 137 | 138 | //set default index without triggering setter 139 | Reflect.setField(this, "index", -1); 140 | 141 | className = Type.getClassName(Type.getClass(this)).split(".").pop(); 142 | 143 | children = []; 144 | signal = new Signal2(); 145 | 146 | initialize(); 147 | } 148 | 149 | public function toString():String 150 | { 151 | return className + "(" + id + ")"; 152 | } 153 | 154 | /** 155 | dispatches a view event via the signal 156 | @param event string event type 157 | @param view originating view object 158 | */ 159 | public function dispatch(event:String, view:View) 160 | { 161 | if (view == null) view = this; 162 | signal.dispatch(event, view); 163 | } 164 | 165 | 166 | /** 167 | Adds a child view to the display heirachy. 168 | 169 | Dispatches an ADDED event on completion. 170 | 171 | @param view child to add 172 | */ 173 | public function addChild(view:View) 174 | { 175 | view.signal.add(this.dispatch); 176 | view.parent = this; 177 | view.index = children.length; 178 | 179 | children.push(view); 180 | 181 | #if flash 182 | sprite.addChild(view.sprite); 183 | #elseif js 184 | element.appendChild(view.element); 185 | #end 186 | 187 | dispatch(ADDED, view); 188 | } 189 | 190 | 191 | /** 192 | Removes an existing child view from the display heirachy. 193 | 194 | Dispatches an REMOVED event on completion. 195 | 196 | @param view child to remove 197 | */ 198 | public function removeChild(view:View) 199 | { 200 | var removed = children.remove(view); 201 | 202 | if (removed) 203 | { 204 | var oldIndex = view.index; 205 | 206 | view.remove(); 207 | view.signal.remove(this.dispatch); 208 | view.parent = null; 209 | view.index = -1; 210 | 211 | #if flash 212 | sprite.removeChild(view.sprite); 213 | #elseif js 214 | element.removeChild(view.element); 215 | #end 216 | 217 | for(i in oldIndex...children.length) 218 | { 219 | var view = children[i]; 220 | view.index = i; 221 | } 222 | 223 | dispatch(REMOVED, view); 224 | } 225 | } 226 | 227 | ///// internal ////// 228 | 229 | /** 230 | Initializes platform specific properties and state 231 | */ 232 | function initialize() 233 | { 234 | #if flash 235 | sprite = new Sprite(); 236 | #elseif js 237 | if (tagName == null) tagName = "div"; 238 | element = Browser.document.createElement(tagName); 239 | element.setAttribute("id", id); 240 | element.className = className; 241 | #end 242 | } 243 | 244 | /** 245 | Removes platform specific properties and state 246 | */ 247 | function remove() 248 | { 249 | //override in sub class 250 | } 251 | 252 | /** 253 | Updates platform specific properties and state 254 | */ 255 | function update() 256 | { 257 | //override in sub class 258 | } 259 | 260 | /** 261 | Sets index and triggers an update when index changes 262 | @param value target index 263 | */ 264 | function set_index(value:Int):Int 265 | { 266 | if (index != value) 267 | { 268 | index = value; 269 | update(); 270 | } 271 | 272 | return index; 273 | } 274 | 275 | } 276 | -------------------------------------------------------------------------------- /example/src/example/todo/command/LoadTodoListCommand.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.todo.command; 24 | 25 | import example.todo.signal.LoadTodoList; 26 | import example.todo.model.TodoList; 27 | import example.todo.model.Todo; 28 | 29 | import mcore.loader.Loader; 30 | import mcore.loader.JSONLoader; 31 | 32 | /** 33 | Loads an existing todo list from the file system, 34 | 35 | Dispatches LoadTodoList.completed or failed signal based on result of loader. 36 | 37 | @see example.todo.signal.LoadTodoList 38 | @see m.loader.JSONLoader 39 | */ 40 | class LoadTodoListCommand extends mmvc.impl.Command 41 | { 42 | @inject 43 | public var list:TodoList; 44 | 45 | @inject 46 | public var loadTodoList:LoadTodoList; 47 | 48 | var loader:JSONLoader; 49 | 50 | public function new() 51 | { 52 | super(); 53 | } 54 | 55 | /** 56 | loads a json file 57 | */ 58 | override public function execute():Void 59 | { 60 | loader = new JSONLoader("data/data.json"); 61 | loader.completed.addOnce(completed); 62 | loader.failed.addOnce(failed); 63 | loader.load(); 64 | } 65 | 66 | /** 67 | Converts the raw json object into Todo items 68 | Dispatches completed signal on completion. 69 | 70 | @param data raw json object 71 | */ 72 | function completed(data:Dynamic) 73 | { 74 | loader.failed.remove(failed); 75 | 76 | var items:Array = cast data.items; 77 | 78 | for(item in items) 79 | { 80 | var todo = new Todo(item.name); 81 | todo.done = item.done == true; 82 | list.add(todo); 83 | } 84 | 85 | loadTodoList.completed.dispatch(list); 86 | } 87 | 88 | /** 89 | Dispatches failed signal if JSONLoader is unsuccessful 90 | */ 91 | function failed(error:LoaderError) 92 | { 93 | loader.completed.remove(completed); 94 | 95 | loadTodoList.failed.dispatch(Std.string(error)); 96 | } 97 | } -------------------------------------------------------------------------------- /example/src/example/todo/model/Todo.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.todo.model; 24 | 25 | /** 26 | A single todo data object with a name and a done status 27 | */ 28 | class Todo 29 | { 30 | /** 31 | Name of the todo item 32 | */ 33 | public var name:String; 34 | 35 | /** 36 | Indicates if todo item is completed 37 | */ 38 | public var done:Bool; 39 | 40 | public function new(?name:String) 41 | { 42 | if (name == null) name = "New todo"; 43 | this.name = name; 44 | this.done = false; 45 | } 46 | 47 | /** 48 | Serializes the data object as a JSON string 49 | */ 50 | public function toString():String 51 | { 52 | return haxe.Json.stringify(this); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /example/src/example/todo/model/TodoList.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.todo.model; 24 | 25 | /** 26 | List of Todo items. 27 | 28 | @see example.todo.model.Todo 29 | @see mcore.data.ArrayList 30 | */ 31 | 32 | class TodoList extends mcore.data.ArrayList 33 | { 34 | public function new(?values:Array=null) 35 | { 36 | super(values); 37 | } 38 | 39 | /** 40 | returns number of incomplete items (done == false) 41 | */ 42 | public function getRemaining():Int 43 | { 44 | var incomplete = this.filter( 45 | function(todo:Todo) 46 | { 47 | return todo.done; 48 | }); 49 | 50 | return incomplete.size; 51 | } 52 | } -------------------------------------------------------------------------------- /example/src/example/todo/signal/LoadTodoList.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.todo.signal; 24 | 25 | import msignal.Signal; 26 | 27 | import example.todo.model.TodoList; 28 | 29 | /** 30 | Application signal for loading an existing external Todo list. 31 | 32 | Includes sub signals for completed/failed handlers once list is loaded. 33 | 34 | @see example.todo.command.LoadTodoListCommand 35 | @see msignal.Signal 36 | 37 | */ 38 | class LoadTodoList extends msignal.Signal0 39 | { 40 | /** 41 | dispatched once TodoList has been loaded 42 | */ 43 | public var completed:Signal1; 44 | 45 | /** 46 | Dispatched if application unable to load TodoList 47 | */ 48 | public var failed:Signal1; 49 | 50 | public function new() 51 | { 52 | super(); 53 | completed = new Signal1(TodoList); 54 | failed = new Signal1(Dynamic); 55 | } 56 | } -------------------------------------------------------------------------------- /example/src/example/todo/view/TodoListView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.todo.view; 24 | 25 | import example.core.View; 26 | import example.core.DataView; 27 | import example.todo.model.Todo; 28 | import example.todo.model.TodoList; 29 | 30 | /** 31 | Main TodoList view containing a list of Todo items 32 | 33 | Updates individual todo item state when user clicks on a todo item 34 | 35 | @see example.core.DataView 36 | @see example.todo.view.TodoView 37 | @see example.todo.model.TodoList 38 | */ 39 | class TodoListView extends DataView 40 | { 41 | inline public static var CREATE_TODO = "CREATE_TODO"; 42 | var statsView:TodoStatsView; 43 | 44 | /** 45 | Overrides constructor to set js tag name to unordered list (ul) 46 | 47 | @param data default TodoList 48 | @see example.core.DataView 49 | */ 50 | public function new(?data:TodoList) 51 | { 52 | #if js tagName = "ul"; #end 53 | super(data); 54 | } 55 | 56 | /** 57 | Displays an error in the stats view 58 | */ 59 | public function showError(message:String) 60 | { 61 | statsView.setData(message); 62 | } 63 | 64 | /** 65 | Overrides dispatched to handle ACTIONED events from child views. 66 | 67 | @see example.core.DataView 68 | */ 69 | override public function dispatch(event:String, view:View) 70 | { 71 | switch(event) 72 | { 73 | case View.ACTIONED: 74 | { 75 | if (Std.is(view, TodoView)) 76 | { 77 | var todoView = cast view; 78 | toggleTodoViewState(todoView); 79 | } 80 | else if (Std.is(view, TodoStatsView)) 81 | { 82 | super.dispatch(CREATE_TODO, this); 83 | } 84 | } 85 | default: 86 | { 87 | super.dispatch(event, view); 88 | } 89 | } 90 | } 91 | 92 | /** 93 | Toggles the done state of a single TodoView 94 | 95 | @param view TodoView to toggle done state 96 | */ 97 | function toggleTodoViewState(view:TodoView) 98 | { 99 | var data = view.data; 100 | data.done = !data.done; 101 | view.setData(data, true); 102 | 103 | updateStats(); 104 | 105 | } 106 | 107 | 108 | /** 109 | Overrides initialized to create stats view 110 | @see example.core.View 111 | */ 112 | override function initialize() 113 | { 114 | super.initialize(); 115 | 116 | statsView = new TodoStatsView(); 117 | addChild(statsView); 118 | } 119 | 120 | 121 | /** 122 | Overrides dataChanged to add/remove listeners to collection change event 123 | 124 | @see example.core.DataView 125 | */ 126 | override function dataChanged() 127 | { 128 | super.dataChanged(); 129 | 130 | if (this.previousData != null) 131 | this.previousData.changed.remove(collectionChanged); 132 | 133 | if (data != null) 134 | data.changed.add(collectionChanged); 135 | 136 | collectionChanged(); 137 | } 138 | 139 | /** 140 | updates child views based on current size of data 141 | */ 142 | function collectionChanged() 143 | { 144 | updateStats(); 145 | 146 | for(child in children.concat([])) 147 | { 148 | if (Std.is(child, TodoView)) 149 | { 150 | removeChild(child); 151 | } 152 | } 153 | 154 | if (data != null) 155 | { 156 | for(todo in data) 157 | { 158 | var view = new TodoView(todo); 159 | addChild(view); 160 | } 161 | } 162 | } 163 | 164 | /** 165 | Updates the stats view based on the number of done Todo items 166 | */ 167 | function updateStats() 168 | { 169 | if (data == null) 170 | { 171 | statsView.setData("No data available"); 172 | return; 173 | } 174 | var remaining = data.getRemaining(); 175 | 176 | var stats = switch(data.size) 177 | { 178 | case 0: "No Todo Items"; 179 | default: remaining + " of " + data.size + " Todo Items complete"; 180 | } 181 | 182 | statsView.setData(stats); 183 | } 184 | } 185 | 186 | -------------------------------------------------------------------------------- /example/src/example/todo/view/TodoListViewMediator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.todo.view; 24 | 25 | import example.todo.signal.LoadTodoList; 26 | import example.todo.model.TodoList; 27 | import example.todo.model.Todo; 28 | import example.todo.view.TodoListView; 29 | 30 | import example.core.View; 31 | /** 32 | Mediator for TodoListView. 33 | 34 | Loads default TodoList on registration. 35 | Updates view when data has been loaded. 36 | 37 | @see example.todo.view.TodoListView 38 | @see example.todo.signal.LoadTodoList 39 | */ 40 | 41 | class TodoListViewMediator extends mmvc.impl.Mediator 42 | { 43 | @inject public var loadTodoList:LoadTodoList; 44 | 45 | var list:TodoList; 46 | 47 | public function new() 48 | { 49 | super(); 50 | } 51 | 52 | /** 53 | Dispatches loadTodoList on registration of mediator 54 | @see mmvc.impl.Mediator 55 | @see mmvc.base.MediatorBase.mediate() 56 | */ 57 | override function onRegister() 58 | { 59 | //using mediate() to store listeners for easy cleanup during removal 60 | mediate(view.signal.add(viewHandler)); 61 | mediate(loadTodoList.completed.addOnce(loadCompleted)); 62 | mediate(loadTodoList.failed.addOnce(loadFailed)); 63 | 64 | loadTodoList.dispatch(); 65 | } 66 | 67 | /** 68 | Override onRemove to remove any unmediated listeners 69 | @see mmvc.impl.Mediator 70 | */ 71 | override public function onRemove():Void 72 | { 73 | super.onRemove(); 74 | //remove un mediated listeners 75 | } 76 | 77 | /** 78 | callback for successful load of TodoList 79 | @see example.todo.signal.LoadTodoList 80 | */ 81 | function loadCompleted(list:TodoList) 82 | { 83 | this.list = list; 84 | view.setData(list); 85 | } 86 | 87 | function loadFailed(error:Dynamic) 88 | { 89 | view.showError(Std.string(error)); 90 | } 91 | 92 | /** 93 | Adds a new todo item to the model when CREATE_TODO event is dispatched 94 | */ 95 | function viewHandler(event:String, view:View) 96 | { 97 | if (event == TodoListView.CREATE_TODO) 98 | { 99 | list.add(new Todo()); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /example/src/example/todo/view/TodoStatsView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.todo.view; 24 | 25 | import example.core.View; 26 | import example.core.DataView; 27 | import example.todo.model.Todo; 28 | import example.todo.model.TodoList; 29 | 30 | #if js 31 | import js.Browser; 32 | import js.html.Element; 33 | #end 34 | 35 | /** 36 | Provides summary information on the current TodoList 37 | 38 | @see example.core.DataView 39 | @see example.todo.model.TodoList 40 | */ 41 | class TodoStatsView extends DataView 42 | { 43 | #if flash 44 | var textField:flash.text.TextField; 45 | var button:flash.display.Sprite; 46 | #elseif js 47 | var label:Element; 48 | var button:Element; 49 | #end 50 | 51 | /** 52 | Overrides constructor to set js tag name to unordered list (ul) 53 | 54 | @param data default TodoList 55 | @see example.core.DataView 56 | */ 57 | public function new(?data:String) 58 | { 59 | super(data); 60 | } 61 | 62 | /** 63 | Overrides initialized to initialise sub views on flash target 64 | 65 | @see example.core.View 66 | */ 67 | override function initialize() 68 | { 69 | super.initialize(); 70 | 71 | #if flash 72 | textField = new flash.text.TextField(); 73 | textField.text = data != null ? data : "Loading items..."; 74 | textField.width = 180; 75 | sprite.addChild(textField); 76 | 77 | button = new flash.display.Sprite(); 78 | button.graphics.beginFill(0xCCCCCC); 79 | button.graphics.lineStyle(1, 0xAAAAAA); 80 | button.graphics.drawRect(0, 0, 100, 25); 81 | button.x = 200; 82 | button.y = 5; 83 | sprite.addChild(button); 84 | 85 | 86 | sprite.graphics.beginFill(0xCCCCCC); 87 | sprite.graphics.drawRect(0, 0, 320, 35); 88 | 89 | var buttonText = new flash.text.TextField(); 90 | buttonText.text = "New Item"; 91 | button.addChild(buttonText); 92 | button.addEventListener(flash.events.MouseEvent.CLICK, flash_onClick); 93 | 94 | 95 | #elseif js 96 | label = Browser.document.createElement("label"); 97 | label.innerHTML = data != null ? data : "Loading items..."; 98 | element.appendChild(label); 99 | 100 | button = Browser.document.createElement("a"); 101 | button.innerHTML = "New item"; 102 | button.onclick = js_onClick; 103 | element.appendChild(button); 104 | #end 105 | } 106 | 107 | override function remove() 108 | { 109 | super.remove(); 110 | #if js 111 | button.onclick = null; 112 | #end 113 | } 114 | 115 | /** 116 | Overrides update to set view specific properties in flash and js 117 | @see example.core.View 118 | */ 119 | override function update() 120 | { 121 | if (data != null) 122 | { 123 | #if flash 124 | textField.text = data; 125 | #elseif js 126 | label.innerHTML = data; 127 | #elseif (sys||neko||cpp) 128 | Sys.println(data); 129 | #else 130 | trace("ID: " + toString() + ", data: " + data); 131 | #end 132 | } 133 | } 134 | 135 | 136 | #if flash 137 | /** 138 | Flash only: dispatches ACTIONED event on mouse click 139 | */ 140 | function flash_onClick(event:flash.events.MouseEvent) 141 | { 142 | dispatch(View.ACTIONED, this); 143 | } 144 | 145 | 146 | #elseif js 147 | function js_onClick(event:js.html.Event) 148 | { 149 | dispatch(View.ACTIONED, this); 150 | } 151 | #end 152 | } 153 | -------------------------------------------------------------------------------- /example/src/example/todo/view/TodoView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package example.todo.view; 24 | 25 | import example.core.View; 26 | import example.core.DataView; 27 | 28 | import example.todo.model.Todo; 29 | 30 | #if js 31 | import js.Browser; 32 | import js.html.Event; 33 | import js.Browser.document; 34 | #end 35 | 36 | /** 37 | View for a single Todo model. 38 | 39 | @see example.core.DataView 40 | */ 41 | class TodoView extends DataView 42 | { 43 | var label:String; 44 | var done:Bool; 45 | 46 | #if flash 47 | var textField:flash.text.TextField; 48 | var icon:flash.display.Bitmap; 49 | #end 50 | 51 | /** 52 | Overrides constructor to set js tagName to list item (li) 53 | @param data default Todo model 54 | @see example.core.DataView 55 | */ 56 | public function new(?data:Todo) 57 | { 58 | #if js tagName = "li"; #end 59 | label = ""; 60 | super(data); 61 | } 62 | 63 | /** 64 | Overrides dataChanged to update internal properties 65 | @see example.core.DataView 66 | */ 67 | override function dataChanged() 68 | { 69 | super.dataChanged(); 70 | label = data != null ? data.name : ""; 71 | done = data != null && data.done; 72 | } 73 | 74 | /** 75 | Overrides initialized to set click handlers and 76 | to initialise sub views on flash target 77 | 78 | @see example.core.View 79 | */ 80 | override function initialize() 81 | { 82 | super.initialize(); 83 | 84 | #if flash 85 | icon = new flash.display.Bitmap(); 86 | sprite.addChild(icon); 87 | 88 | textField = new flash.text.TextField(); 89 | textField.x = 20; 90 | sprite.addChild(textField); 91 | sprite.addEventListener(flash.events.MouseEvent.CLICK, flash_onClick); 92 | #elseif js 93 | element.onclick = js_onClick; 94 | #end 95 | } 96 | 97 | /** 98 | Overrides removed to clear event listeners 99 | @see example.core.View 100 | */ 101 | override function remove() 102 | { 103 | #if flash 104 | sprite.removeEventListener(flash.events.MouseEvent.CLICK, flash_onClick); 105 | #elseif js 106 | element.onclick = null; 107 | #end 108 | } 109 | 110 | /** 111 | Overrides update to set view specific properties in flash and js 112 | @see example.core.View 113 | */ 114 | override function update() 115 | { 116 | #if flash 117 | sprite.y = (index+1)*25; 118 | textField.text = label; 119 | 120 | var uri = "img/" + (done ? "done" : "none") + ".png"; 121 | var loader = new flash.display.Loader(); 122 | loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, flash_onBitmapLoaderComplete); 123 | loader.load(new flash.net.URLRequest(uri)); 124 | 125 | #elseif js 126 | element.innerHTML = label; 127 | element.className = className + (done? " done" : ""); 128 | #elseif (sys||neko||cpp) 129 | if (index > -1) 130 | { 131 | var msg = label + (done ? " (completed)" : ""); 132 | Sys.println(" " + (index) + ": " + msg); 133 | } 134 | #else 135 | trace("ID: " + toString() + ", label: " + label + ", index: " + index); 136 | #end 137 | 138 | } 139 | 140 | #if flash 141 | 142 | /** 143 | Flash only: updates icon bitmap on load of image 144 | */ 145 | function flash_onBitmapLoaderComplete (event:flash.events.Event) 146 | { 147 | var content = cast (event.target, flash.display.LoaderInfo).content; 148 | icon.bitmapData = cast(content, flash.display.Bitmap).bitmapData; 149 | } 150 | 151 | /** 152 | Flash only: dispatches ACTIONED event on mouse click 153 | */ 154 | function flash_onClick(event:flash.events.MouseEvent) 155 | { 156 | dispatch(View.ACTIONED, this); 157 | } 158 | 159 | #elseif js 160 | 161 | /** 162 | JS only: dispatches ACTIONED event on mouse click 163 | */ 164 | function js_onClick(event:js.html.Event) 165 | { 166 | dispatch(View.ACTIONED, this); 167 | } 168 | 169 | #end 170 | } 171 | -------------------------------------------------------------------------------- /example/src/mcore/README: -------------------------------------------------------------------------------- 1 | These mcore classes are included as a stop-gap measure so that we can release 2 | before mcore is released. 3 | 4 | Use at your own peril. -------------------------------------------------------------------------------- /example/src/mcore/data/ArrayList.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.data; 24 | 25 | /** 26 | An ArrayList is a managed collection of values with a similar API to a native 27 | platform Array. ArrayLists protect against out of range access and can notify 28 | observers when the values the contain change. 29 | * 30 | Example Usage: 31 |
 32 | var list = new ArrayList();
 33 | list.addAll(["foo", "bar", "cat"]);
 34 | trace(list.first);//outputs "foo";
 35 | trace(list.last);//outputs "cat";
 36 | 
37 | 38 | @see mcore.data.Collection 39 | @see mcore.data.CollectionBase 40 | */ 41 | class ArrayList extends CollectionBase 42 | { 43 | /** 44 | Creates a new ArrayList containing an optional array of values. 45 | 46 | @param values optional array of values to populate the ArrayList 47 | */ 48 | public function new(?values:Iterable = null) 49 | { 50 | super(); 51 | 52 | if (values != null) 53 | { 54 | addAll(values); 55 | } 56 | } 57 | 58 | /** 59 | The first item in the collection. 60 | */ 61 | public var first(get, null):T; 62 | 63 | function get_first():T 64 | { 65 | if (isEmpty()) 66 | return null; 67 | 68 | return source[0]; 69 | } 70 | 71 | /** 72 | The last item in the collection. 73 | */ 74 | public var last(get, null):T; 75 | 76 | function get_last():T 77 | { 78 | if (isEmpty()) 79 | return null; 80 | 81 | return source[size - 1]; 82 | } 83 | 84 | /** 85 | The number of items in the collection. 86 | */ 87 | public var length(get, null):Int; 88 | 89 | function get_length():Int 90 | { 91 | return source.length; 92 | } 93 | 94 | /** 95 | Inserts a value at a given index in the list. 96 | 97 | @param index The index at which to inset the value. 98 | @param value The value to insert. 99 | */ 100 | public function insert(index:Int, value:T):Void 101 | { 102 | if (index < 0 || index > size) 103 | { 104 | throw "index out of bounds"; 105 | } 106 | 107 | source.insert(index, value); 108 | notifyChanged(); 109 | } 110 | 111 | /** 112 | Returns a value at a given index in the list. 113 | 114 | @param index The index of the value to return. 115 | @return The requested value. 116 | */ 117 | public function get(index:Int):T 118 | { 119 | if (index < 0 || index >= size) 120 | { 121 | throw "index out of bounds"; 122 | } 123 | 124 | return source[index]; 125 | } 126 | 127 | /** 128 | Returns the first index at which value exists in the list, or -1 if it is 129 | not found. 130 | 131 | @param value The value to index. 132 | @return The index of the value, or -1 if it is not found. 133 | */ 134 | public function indexOf(value:T):Int 135 | { 136 | for (i in 0...source.length) 137 | { 138 | if (source[i] == value) 139 | { 140 | return i; 141 | } 142 | } 143 | 144 | return -1; 145 | } 146 | 147 | /** 148 | Remove the value at a specified index. 149 | 150 | @param index The index of the value to remove. 151 | @return The removed value. 152 | */ 153 | public function removeAt(index:Int):T 154 | { 155 | if (index < 0 || index >= size) 156 | { 157 | throw "index out of bounds"; 158 | } 159 | 160 | var value = source.splice(index, 1)[0]; 161 | notifyChanged(); 162 | return value; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /example/src/mcore/data/Collection.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.data; 24 | 25 | import msignal.Signal; 26 | 27 | /** 28 | The collection interface defines an API for working with collections of values. 29 | The API defines methods for adding, removing and manipulating values in the 30 | collection. 31 | 32 | Creating a concrete instance (e.g. ArrayList, Stack, Set, etc): 33 |
 34 | var collection = new CollectionImpl();
 35 | 
* 36 | Adding and removing values: 37 |
 38 | collection.add(foo1);
 39 | collection.addAll([foo1, foo2, foo3]);		
 40 | collection.remove(foo1);
 41 | collection.clear();
 42 | 
43 | 44 | Measuring and accessing values: 45 |
 46 | collection.size
 47 | collection.contains(foo1);
 48 | collection.isEmpty());
 49 | 
50 | 51 | Iterating through values: 52 |
 53 | for(foo in collection.iterator())
 54 | {
 55 | 	trace(foo.bar);
 56 | }
 57 | var array = collection.toArray();
 58 | 
59 | 60 | Observing changes to collection: 61 |
 62 | collection.changed.addOnce(changeHandler);
 63 | collection.add(foo2);
 64 | ...
 65 | function changeHandler()
 66 | {
 67 | 	//will execute when collection contents changes
 68 | }
 69 | 
70 | * 71 | */ 72 | interface Collection 73 | { 74 | /** 75 | Dispatched when the values of the collection change. 76 | */ 77 | var changed:Signal0; 78 | 79 | /** 80 | The number of values in this collection. 81 | */ 82 | var size(get, null):Int; 83 | 84 | /** 85 | Adds a value to the collection. 86 | 87 | @param value the value to add. 88 | */ 89 | function add(value:T):Void; 90 | 91 | /** 92 | Adds a collection of values to this collection. 93 | 94 | @param values the collection of values to add to this collection. 95 | */ 96 | function addAll(values:Iterable):Void; 97 | 98 | /** 99 | Removes all values in the collection. 100 | */ 101 | function clear():Void; 102 | 103 | /** 104 | Returns true if a value in the collection is equal to the provided value, 105 | using standard equality. 106 | 107 | @param value the value to check for. 108 | @return true if value exists in collection. 109 | * false otherwise 110 | */ 111 | function contains(value:T):Bool; 112 | 113 | /** 114 | @return true if collection contains no values. 115 | * false otherwise 116 | */ 117 | function isEmpty():Bool; 118 | 119 | /** 120 | Directly access an iterator contain the values of the collection 121 |
122 | 	for(foo in collection.iterator())
123 | 	{
124 | 		trace(foo.bar);
125 | 	}
126 | 	
127 | 128 | @return Iterator for the values in the collection. 129 | */ 130 | function iterator():Iterator>; 131 | 132 | /** 133 | Removes a value from the collection if it exists. 134 | 135 | @param value The value to remove. 136 | @return true if value was successfully removed 137 | * false otherwise 138 | */ 139 | function remove(value:T):Bool; 140 | 141 | /** 142 | Returns a collection containing values for which predicate(value) returns 143 | true. 144 | 145 | @param predicate The filtering function, taking a collection value as an 146 | argument and returning a boolean indicating prescence in the resulting 147 | collection. 148 | @return The filtered collection. 149 | */ 150 | function filter(predicate:T -> Bool):Collection; 151 | 152 | /** 153 | Returns an array of the values in the collection. 154 | @return An array of values in the collection. 155 | */ 156 | function toArray():Array; 157 | } 158 | -------------------------------------------------------------------------------- /example/src/mcore/data/CollectionBase.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.data; 24 | 25 | import msignal.Signal; 26 | import mcore.util.Iterables; 27 | import mcore.util.Arrays; 28 | import mcore.util.Types; 29 | 30 | /** 31 | A base collection implementation. 32 | * 33 | @see mcore.data.Collection 34 | */ 35 | class CollectionBase implements Collection 36 | { 37 | /** 38 | Dispatched when the values of the collection change. 39 | */ 40 | public var changed:Signal0; 41 | 42 | /** 43 | The number of values in this collection. 44 | */ 45 | public var size(get, null):Int; 46 | function get_size():Int { return source.length; } 47 | 48 | var source:Array; 49 | 50 | function new() 51 | { 52 | source = []; 53 | changed = new Signal0(); 54 | } 55 | 56 | /** 57 | Adds a value to the collection. 58 | 59 | @param value The value to add. 60 | */ 61 | public function add(value:T) 62 | { 63 | source.push(value); 64 | notifyChanged(); 65 | } 66 | 67 | function notifyChanged() 68 | { 69 | changed.dispatch(); 70 | } 71 | 72 | /** 73 | Adds a collection of values to this collection. 74 | 75 | @param values the collection of values to add to this collection. 76 | */ 77 | public function addAll(values:Iterable) 78 | { 79 | if (values == null) return; 80 | 81 | var s = source.length; 82 | for (value in values) 83 | { 84 | source.push(value); 85 | } 86 | 87 | if (source.length != s) 88 | notifyChanged(); 89 | } 90 | 91 | /** 92 | Removes all values in the colleciton. 93 | */ 94 | public function clear() 95 | { 96 | if (isEmpty()) return; 97 | 98 | source.splice(0, source.length); 99 | notifyChanged(); 100 | } 101 | 102 | /** 103 | Returns true if a value in the collection is equal to the provided value, 104 | using standard equality. 105 | 106 | @param value The value to check for. 107 | @return A boolean indicating the existence of the value in the collection. 108 | */ 109 | public function contains(value:T):Bool 110 | { 111 | return Iterables.contains(source, value); 112 | } 113 | 114 | /** 115 | @return A boolean indicating the abscence of values in the collection. 116 | */ 117 | public function isEmpty():Bool 118 | { 119 | return source.length == 0; 120 | } 121 | 122 | /** 123 | @return An iterator for the values in the collection. 124 | */ 125 | public function iterator():Iterator> 126 | { 127 | return source.iterator(); 128 | } 129 | 130 | /** 131 | Removes a value from the collection if it exists. 132 | 133 | @param value The value to remove. 134 | @return A boolean indicating whether the value was removed. 135 | */ 136 | public function remove(value:T):Bool 137 | { 138 | var hasChanged = false; 139 | var i = source.length; 140 | while (i-- > 0) 141 | { 142 | if (source[i] == value) 143 | { 144 | source.splice(0, 1); 145 | hasChanged = true; 146 | } 147 | } 148 | if (hasChanged) 149 | notifyChanged(); 150 | 151 | return hasChanged; 152 | } 153 | 154 | /** 155 | Returns a collection containing values for which predicate(value) returns 156 | true. 157 | 158 | @param predicate The filtering function, taking a collection value as an 159 | argument and returning a boolean indicating prescence in the resulting 160 | collection. 161 | @return The filtered collection. 162 | */ 163 | public function filter(predicate:T -> Bool):Collection 164 | { 165 | var collectionType = Type.getClass(this); 166 | var collection:Collection = Types.createInstance(collectionType, []); 167 | var filteredValues:Array = Iterables.filter(source, predicate); 168 | 169 | collection.addAll(filteredValues); 170 | return collection; 171 | } 172 | 173 | /** 174 | Returns an array of the values in the collection. 175 | 176 | @return An array of values in the collection. 177 | */ 178 | public function toArray():Array 179 | { 180 | return source.copy(); 181 | } 182 | 183 | /** 184 | Returns a string representation of the collection. 185 | 186 | @return A String representation of the collection. 187 | */ 188 | public function toString():String 189 | { 190 | return Arrays.toString(source); 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /example/src/mcore/loader/HTTPLoader.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.loader; 24 | 25 | import mcore.loader.Loader; 26 | import msignal.Signal; 27 | import haxe.Http; 28 | 29 | using mcore.util.Strings; 30 | 31 | /** 32 | The HTTPLoader class is responsible for loading HTTP requests. The API also 33 | handles the completed and failed signals. 34 | */ 35 | 36 | class HTTPLoader extends LoaderBase 37 | { 38 | /** 39 | The headers to pass through with the http request. 40 | */ 41 | public var headers(default, null):Map; 42 | 43 | /** 44 | HTTP status code of response. 45 | */ 46 | public var statusCode(default, null):Int; 47 | 48 | var http:Http; 49 | 50 | /** 51 | @param uri the uri to load the resource from 52 | @param http optional Http instance to use for the load request 53 | */ 54 | public function new(?uri:String, ?http:Http) 55 | { 56 | super(uri); 57 | 58 | if (http == null) 59 | http = new Http(""); 60 | 61 | this.http = http; 62 | 63 | http.onData = httpData; 64 | http.onError = httpError; 65 | http.onStatus = httpStatus; 66 | headers = new Map(); 67 | } 68 | 69 | /** 70 | Configures and makes the http request. The load method does not pass 71 | through any data with the request. 72 | */ 73 | override public function load() 74 | { 75 | super.load(); 76 | 77 | http.url = uri; 78 | httpConfigure(); 79 | addHeaders(); 80 | 81 | progressed.dispatch(0); 82 | 83 | #if nme 84 | if (uri.indexOf("http:") == 0) 85 | { 86 | haxe.Timer.delay(callback(http.request, false), 10); 87 | } 88 | else 89 | { 90 | var result = nme.installer.Assets.getText("root/" + uri); 91 | haxe.Timer.delay(callback(httpData, result), 10); 92 | } 93 | #elseif neko 94 | if (uri.indexOf("http:") == 0) 95 | { 96 | http.request(false); 97 | } 98 | else 99 | { 100 | loadFromFileSystem(uri); 101 | } 102 | #else 103 | try 104 | { 105 | http.request(false); 106 | } 107 | catch (e:Dynamic) 108 | { 109 | // js can throw synchronous security error 110 | failed.dispatch(SecurityError(Std.string(e))); 111 | } 112 | #end 113 | } 114 | 115 | #if neko 116 | 117 | /** 118 | Workaround to enable loading relative urls in neko 119 | */ 120 | function loadFromFileSystem(uri:String) 121 | { 122 | if (!sys.FileSystem.exists(uri)) 123 | { 124 | failed.dispatch(IOError("Local file does not exist: " + uri)); 125 | } 126 | else 127 | { 128 | var contents = sys.io.File.getContent(uri); 129 | httpData(contents); 130 | } 131 | } 132 | #end 133 | 134 | /** 135 | Configures and makes the http request. The send method can also pass 136 | through data with the request. It also traps any security errors and 137 | dispatches a failed signal. 138 | 139 | @param uri The URI to load. 140 | @param data Data to pass through with the request. 141 | */ 142 | public function send(data:Dynamic) 143 | { 144 | if (uri == null) 145 | throw "No uri defined for Loader"; 146 | 147 | #if debug 148 | checkListeners(); 149 | #end 150 | 151 | if (!headers.exists("Content-Type")) 152 | { 153 | var contentType = getMIMEType(data); 154 | headers.set("Content-Type", contentType); 155 | } 156 | 157 | http.url = uri; 158 | http.setPostData(Std.string(data)); 159 | 160 | httpConfigure(); 161 | addHeaders(); 162 | 163 | progressed.dispatch(0); 164 | 165 | try 166 | { 167 | http.request(true); 168 | } 169 | catch (e:Dynamic) 170 | { 171 | // js can throw synchronous security error 172 | failed.dispatch(SecurityError(Std.string(e))); 173 | } 174 | // #end 175 | } 176 | 177 | /** 178 | Returns the MIME type for the current data. 179 | 180 | Currently only auto-detects Xml and Json. Defaults to 'application/octet-stream'. 181 | 182 | Note: This can be overwritten by adding a 'Content-Type' to the headers hash 183 | */ 184 | function getMIMEType(data:Dynamic):String 185 | { 186 | if (Std.is(data, Xml)) 187 | { 188 | return "application/xml"; 189 | } 190 | else if (Std.is(data, String) && data.length > 0 && 191 | (data.charAt(0) == "{" && data.charAt(data.length - 1) == "}") || 192 | (data.charAt(0) == "[" && data.charAt(data.length - 1) == "]")) 193 | { 194 | return "application/json"; 195 | } 196 | 197 | return "application/octet-stream"; 198 | } 199 | 200 | /** 201 | Cancels the http request. Dispatches the cancelled signal when 202 | called. 203 | */ 204 | override public function cancel() 205 | { 206 | super.cancel(); 207 | cancelled.dispatch(); 208 | } 209 | 210 | function httpConfigure() 211 | { 212 | } 213 | 214 | function addHeaders() 215 | { 216 | for (name in headers.keys()) 217 | { 218 | http.setHeader(name, headers.get(name)); 219 | } 220 | } 221 | 222 | function httpData(data:String) 223 | { 224 | progressed.dispatch(1); 225 | completed.dispatch(cast data); 226 | } 227 | 228 | function httpStatus(status:Int) 229 | { 230 | statusCode = status; 231 | } 232 | 233 | function httpError(error:String) 234 | { 235 | failed.dispatch(IOError(error)); 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /example/src/mcore/loader/JSONLoader.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.loader; 24 | 25 | import mcore.loader.Loader; 26 | using mcore.util.Strings; 27 | 28 | /** 29 | The JSONLoader is an extension of the HTTPLoader. It's responsible for loading 30 | JSON resources and serializing them into objects. 31 | 32 | Example 33 | 34 | var loader = new JSONLoader(); 35 | loader.completed.add(completed); 36 | loader.load("http://some/url/to/load"); 37 | 38 | function completed(result:Dynamic) 39 | { 40 | trace(result.someValue) 41 | } 42 | */ 43 | class JSONLoader extends HTTPLoader 44 | { 45 | /** 46 | @param uri the uri to load the resource from 47 | @param http optional Http instance to use for the load request 48 | */ 49 | public function new(?uri:String, ?http:haxe.Http) 50 | { 51 | super(uri, http); 52 | } 53 | 54 | /** 55 | override httpData to deserialize JSON string into an object. 56 | triggers FormatError if invalid JSON. 57 | */ 58 | override function httpData(data:String) 59 | { 60 | progressed.dispatch(1); 61 | 62 | try 63 | { 64 | var json:Dynamic = haxe.Json.parse(data); 65 | completed.dispatch(json); 66 | } 67 | catch (e:Dynamic) 68 | { 69 | failed.dispatch(FormatError(Std.string(e))); 70 | return; 71 | } 72 | 73 | 74 | } 75 | 76 | 77 | /** 78 | Ensures POST data is valid JSON string 79 | 80 | @param uri The URI to load. 81 | @param data object or JSON string to pass through with the request. 82 | */ 83 | override public function send(data:Dynamic) 84 | { 85 | if (uri == null) 86 | throw "No uri defined for Loader"; 87 | 88 | try 89 | { 90 | if (!Std.is(data, String)) 91 | { 92 | data = haxe.Json.stringify(data); 93 | } 94 | 95 | if (!headers.exists("Content-Type")) 96 | { 97 | headers.set("Content-Type", "application/json"); 98 | } 99 | 100 | super.send(data); 101 | } 102 | catch(e:Dynamic) 103 | { 104 | failed.dispatch(FormatError(Std.string(e))); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /example/src/mcore/loader/Loader.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.loader; 24 | import msignal.Signal; 25 | 26 | typedef AnyLoader = Loader; 27 | 28 | /** 29 | The Loader class defines an API for loading uri's. The API also defines signals 30 | for progressed, completed and failed requests. 31 | */ 32 | 33 | interface Loader 34 | { 35 | var uri:String; 36 | var progress(get, null):Float; 37 | 38 | var progressed(default, null):Signal1; 39 | var completed(default, null):Signal1; 40 | var failed(default, null):Signal1; 41 | var cancelled(default, null):Signal0; 42 | 43 | function load():Void; 44 | function cancel():Void; 45 | } 46 | 47 | enum LoaderError 48 | { 49 | IOError(info:String); 50 | SecurityError(info:String); 51 | FormatError(info:String); 52 | DataError(info:String, data:String); 53 | } 54 | -------------------------------------------------------------------------------- /example/src/mcore/loader/LoaderBase.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.loader; 24 | 25 | import msignal.Signal; 26 | import mcore.loader.Loader; 27 | 28 | /** 29 | The LoaderBase class is an abstract implementation of the Loader class. 30 | */ 31 | 32 | class LoaderBase implements Loader 33 | { 34 | /** 35 | The uri to load the resource from. 36 | */ 37 | public var uri:String; 38 | 39 | /** 40 | 41 | */ 42 | public var asset(default, null):T; 43 | 44 | /** 45 | The percentage of loading complete. Between 0 and 1. 46 | */ 47 | public var progress(get, null):Float; 48 | function get_progress() { return 0; } 49 | 50 | /** 51 | A signal indicating a request has progressed 52 | */ 53 | public var progressed(default, null):Signal1; 54 | 55 | /** 56 | A signal indicating a request is completed 57 | */ 58 | public var completed(default, null):Signal1; 59 | 60 | /** 61 | A signal indicating a request has failed 62 | */ 63 | public var failed(default, null):Signal1; 64 | 65 | /** 66 | A signal indicating a request has been cancelled 67 | */ 68 | public var cancelled(default, null):Signal0; 69 | 70 | /** 71 | @param uri the uri to load the resource from 72 | */ 73 | public function new(?uri:String) 74 | { 75 | this.uri = uri; 76 | 77 | progressed = new Signal1(Float); 78 | completed = new Signal1(null); 79 | failed = new Signal1(LoaderError); 80 | cancelled = new Signal0(); 81 | } 82 | 83 | /** 84 | Called when the loader should begin the loading of a resource from the defined uri. 85 | 86 | Concrete instances should override this method to initiate their loading process. 87 | */ 88 | public function load():Void 89 | { 90 | if (uri == null) 91 | throw "No uri defined for Loader"; 92 | 93 | #if debug 94 | checkListeners(); 95 | #end 96 | } 97 | 98 | /** 99 | Called when the loader should cancel its request to load a resource. 100 | */ 101 | public function cancel():Void 102 | { 103 | } 104 | 105 | #if debug 106 | @:IgnoreCover 107 | function checkListeners() 108 | { 109 | var className = Type.getClassName(Type.getClass(this)); 110 | if (completed.numListeners == 0) Console.warn("No completed listeners for " + className); 111 | if (failed.numListeners == 0) Console.warn("No failed listeners for " + className); 112 | } 113 | #end 114 | } 115 | -------------------------------------------------------------------------------- /example/src/mcore/util/Arrays.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.util; 24 | 25 | class Arrays 26 | { 27 | /** 28 | Normalises toString() output between platforms 29 | For example: ["a", "b", "c"] becomes "a,b,c" 30 | Note: in neko array.toString includes the '[]' and has space between each value. 31 | Where as in js/flash it doesnt. 32 | 33 | @param source The source array to convert to string; 34 | @return string in format "a,b,c" 35 | */ 36 | public static inline function toString(source:Array):String 37 | { 38 | #if neko 39 | return source.join(","); 40 | #else 41 | return source.toString(); 42 | #end 43 | } 44 | 45 | /** 46 | Returns a copy of the source array, with its elements randomly reordered 47 | */ 48 | public static function shuffle(source:Array):Array 49 | { 50 | var copy = source.copy(); 51 | var shuffled = []; 52 | while (copy.length > 0) 53 | shuffled.push(copy.splice(Std.random(copy.length), 1)[0]); 54 | return shuffled; 55 | } 56 | 57 | /** 58 | Convenience method to get the last item in an array. 59 | */ 60 | public static inline function lastItem(source:Array):T 61 | { 62 | return source[source.length - 1]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /example/src/mcore/util/Iterables.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.util; 24 | 25 | /** 26 | Utility methods to operate on Iterables. 27 | 28 | Has some similarities to Haxe's Lambda class with the following main differences: 29 | 30 | a) Favor native Arrays over Haxe based Lists 31 | b) Inline methods where it makes sense for speed. 32 | */ 33 | class Iterables 34 | { 35 | /** 36 | Determine if a value is present in an iterable. 37 | Standard equality is used for comparison. 38 | */ 39 | public static inline function contains(iterable:Iterable, value:T):Bool 40 | { 41 | return indexOf(iterable, value) != -1; 42 | } 43 | 44 | /** 45 | Returns the index of a value in an iterable, or -1 if not found. 46 | Standard equality is used for comparison. 47 | */ 48 | public static function indexOf(iterable:Iterable, value:T):Int 49 | { 50 | var i = 0; 51 | for (member in iterable) 52 | { 53 | if (member == value) 54 | return i; 55 | i++; 56 | } 57 | return -1; 58 | } 59 | 60 | /** 61 | Returns the first element of an iterable that satisfies the predicate, or null 62 | if there is no such element. 63 | */ 64 | public static inline function find(iterable:Iterable, predicate:T->Bool):Null 65 | { 66 | var item:Null = null; 67 | for (member in iterable) 68 | { 69 | if (predicate(member)) 70 | { 71 | item = member; 72 | break; 73 | } 74 | } 75 | return item; 76 | } 77 | 78 | /** 79 | Filter an iterable by a predicate and return the matching elements in an array. 80 | */ 81 | public static inline function filter(iterable:Iterable, predicate:T -> Bool):Array 82 | { 83 | var items:Array = []; 84 | for (member in iterable) 85 | if (predicate(member)) 86 | items.push(member); 87 | return items; 88 | } 89 | 90 | /** 91 | Concatenate the elements of two iterables into a single array. 92 | */ 93 | public static inline function concat(iterableA:Iterable, iterableB:Iterable):Array 94 | { 95 | var items:Array = []; 96 | for (iterable in [iterableA, iterableB]) 97 | for (item in iterable) 98 | items.push(item); 99 | return items; 100 | } 101 | 102 | /** 103 | Apply a selector function to each element of an iterable, and return the array of results. 104 | */ 105 | public static inline function map(iterable:Iterable, selector:A -> B):Array 106 | { 107 | var items:Array = []; 108 | for (item in iterable) 109 | items.push(selector(item)); 110 | return items; 111 | } 112 | 113 | /** 114 | Apply a selector function to each element of an iterable, also passing in the index, and return the array of results. 115 | */ 116 | public static inline function mapWithIndex(iterable:Iterable, selector:A -> Int -> B):Array 117 | { 118 | var items:Array = []; 119 | for (item in iterable) 120 | items.push(selector(item, items.length)); 121 | return items; 122 | } 123 | 124 | /** 125 | Perform a functional left fold. 126 | 127 | From tail to head, each element of the iterable is passed to the aggregator function along with the 128 | current aggregate. This should then return the new aggregate. 129 | 130 | @return the final aggregate of the fold 131 | */ 132 | public static inline function fold(iterable:Iterable, aggregator:A -> B -> B, seed:B):B 133 | { 134 | for (member in iterable) 135 | seed = aggregator(member, seed); 136 | return seed; 137 | } 138 | 139 | /** 140 | Perform a functional right fold. 141 | 142 | From head to tail, each element of the iterable is passed to the aggregator function along with the 143 | current aggregate. This should then return the new aggregate. 144 | 145 | @return the final aggregate of the fold 146 | */ 147 | public static inline function foldRight(iterable:Iterable, aggregator:A -> B -> B, seed:B):B 148 | { 149 | return fold(reverse(iterable), aggregator, seed); 150 | } 151 | 152 | /** 153 | Reverse an iterable's order and return as an array. 154 | */ 155 | public static inline function reverse(iterable:Iterable):Array 156 | { 157 | var items:Array = []; 158 | for (member in iterable) 159 | items.unshift(member); 160 | return items; 161 | } 162 | 163 | /** 164 | Determine if an iterable has any elements. 165 | */ 166 | public static inline function isEmpty(iterable:Iterable):Bool 167 | { 168 | return !iterable.iterator().hasNext(); 169 | } 170 | 171 | /** 172 | Convert an iterable to an array. 173 | */ 174 | public static inline function toArray(iterable:Iterable):Array 175 | { 176 | var result:Array = []; 177 | for (member in iterable) 178 | result.push(member); 179 | return result; 180 | } 181 | 182 | /** 183 | Return the number of elements in an iterable. 184 | */ 185 | public static inline function size(iterable:Iterable):Int 186 | { 187 | var i = 0; 188 | for (member in iterable) 189 | i++; 190 | return i; 191 | } 192 | 193 | /** 194 | Count the number of elements in an iterable which fulfill a given predicate. 195 | */ 196 | public static inline function count(iterable:Iterable, predicate:T->Bool):Int 197 | { 198 | var i = 0; 199 | for (member in iterable) 200 | if (predicate(member)) 201 | i++; 202 | return i; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /example/src/mcore/util/Strings.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.util; 24 | 25 | /** 26 | Utility methods for working with strings. 27 | */ 28 | class Strings 29 | { 30 | /** 31 | Removes all the HTML markup from a string 32 | 33 | @param content the string to strip 34 | @return the stripped string 35 | */ 36 | public static function stripHTML(content:String):String 37 | { 38 | var pattern:EReg = ~/<[^>]*>/g; 39 | return pattern.replace(content, ""); 40 | } 41 | 42 | /** 43 | Capitalizes a string of words separated by spaces. 44 | 45 | @param value the string to capitalize 46 | @return the capitalized string 47 | */ 48 | public static function capitalize(value:String):String 49 | { 50 | // dp: this function really needs improvement 51 | 52 | var words = value.split(" "); 53 | for (i in 0...words.length) 54 | { 55 | var word = words[i]; 56 | words[i] = word.charAt(0).toUpperCase() + word.substr(1); 57 | } 58 | 59 | return words.join(" "); 60 | } 61 | 62 | 63 | /** 64 | Replaces token markers in source string with supplied token values. 65 | The index of a token value maps to its id in the source string. 66 | 67 | e.g. StringTools.substitute("Red {0} {1}", ["Green", "Blue"]); // outputs Red Green Blue 68 | 69 | @param source the string with tokens to be substituted 70 | @param values an array of substitute tokens 71 | @return a copy of the source string with any substitutions made 72 | */ 73 | public static function substitute(source:String, values:Array):String 74 | { 75 | for (i in 0...values.length) 76 | source = source.split("{" + i + "}").join(values[i]); 77 | return source; 78 | } 79 | 80 | /** 81 | Returns true if the subject string is found within the source string 82 | 83 | @param source the string to search 84 | @param subject the string to search for in source 85 | 86 | @return true if the subject is found, false if not 87 | */ 88 | public static inline function contains(source:String, subject:String):Bool 89 | { 90 | return source.indexOf(subject) != -1; 91 | } 92 | 93 | /** 94 | Convenience method to the get the last character in a string. 95 | 96 | @param source the string to grab the last character from 97 | @return the last character in the source string 98 | */ 99 | public static inline function lastChar(source:String):String 100 | { 101 | return (source == "") ? "" : source.charAt(source.length - 1); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /example/src/mcore/util/Types.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mcore.util; 24 | 25 | /** 26 | Utility methods for working with types. 27 | */ 28 | class Types 29 | { 30 | /** 31 | Checks if an object is an instance of, or instance of a subclass of 32 | a given type. 33 | 34 | @param object the instance to check 35 | @param type the type to compare against 36 | @return true if object is instance of type or subclass else false 37 | */ 38 | public static function isSubClassOf(object:Dynamic, type:Dynamic):Bool 39 | { 40 | return (Std.is(object, type) && Type.getClass(object) != type); 41 | } 42 | 43 | /** 44 | Wraps Type.createInstance to support optional constructor arguments in neko 45 | 46 | @param forClass the class type to instanciate 47 | @param args optional array of arguments 48 | @return instance of type 49 | */ 50 | public static function createInstance(forClass:Class, ?args:Array):T 51 | { 52 | if (args == null) args = []; 53 | 54 | #if !neko 55 | try 56 | { 57 | return Type.createInstance(forClass, args); 58 | } 59 | catch(e:Dynamic) 60 | { 61 | throw "Error creating instance of " + Type.getClassName(forClass) + "(" + args.toString() + ")"; 62 | } 63 | 64 | #else 65 | var attempts = 0; 66 | do 67 | { 68 | try 69 | { 70 | return Type.createInstance(forClass, args); 71 | } 72 | catch(e:Dynamic) 73 | { 74 | if (e != "Invalid call") 75 | { 76 | throw "Error creating instance of " + Type.getClassName(forClass) + "(" + args.toString() + ")"; 77 | } 78 | } 79 | 80 | attempts ++; 81 | args.push(null); 82 | } 83 | while (attempts < 10); 84 | 85 | throw "Unable to create instance of " + Type.getClassName(forClass); 86 | 87 | return null; 88 | #end 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "hamcrest":"1.2.1", 3 | "mconsole":"1.6.1", 4 | "mcore":"1.3.12", 5 | "mcover":"2.1.1", 6 | "minject":"1.6.0", 7 | "mlib":"2.0.2", 8 | "msignal":"1.2.3", 9 | "msys":"1.2.2", 10 | "mtask":"3.7.0", 11 | "munit":"2.1.1" 12 | } -------------------------------------------------------------------------------- /mdk/info.config: -------------------------------------------------------------------------------- 1 | name: mmvc 2 | version: 1.6.1 3 | dependencies: 4 | minject: ^1.4.0 5 | msignal: ^1.2.0 6 | dev-dependencies: 7 | mcover: ^2.0.0 8 | hamcrest: ^1.0.0 9 | mtask: ^3.0.0 10 | munit: ^2.0.0 11 | hxcpp: 12 | source: haxelib 13 | version: ^3.1.0 14 | -------------------------------------------------------------------------------- /mdk/lib.config: -------------------------------------------------------------------------------- 1 | hamcrest: 1.2.1 2 | hxcpp: 3.2.81 3 | mconsole: 1.6.1 4 | mcore: 1.3.13 5 | mcover: 2.1.1 6 | minject: 1.6.0 7 | mlib: 2.0.2 8 | msignal: 1.2.3 9 | msys: 1.2.2 10 | mtask: 3.7.1 11 | munit: 2.1.1 -------------------------------------------------------------------------------- /project.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": 3 | { 4 | "name": "MassiveMVC", 5 | "version": "1.6.3", 6 | "id": "mmvc", 7 | "devDependencies": 8 | { 9 | "mcover": "2.x", 10 | "hamcrest": "1.x", 11 | "mtask": "3.x", 12 | "munit": "2.x" 13 | }, 14 | "dependencies": 15 | { 16 | "minject": ">=1.4 <2", 17 | "msignal": ">=1.2 <2" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mmvc", 3 | "license": "MIT", 4 | "tags": [ 5 | "cross", 6 | "massive", 7 | "mvc" 8 | ], 9 | "description": "A Haxe port of the ActionScript 3 RobotLegs MVC framework with signals and Haxe refinements. Supports AVM1, AVM2, JavaScript, Neko and C++.", 10 | "contributors": [ 11 | "massive" 12 | ], 13 | "releasenote": "Add TriggerMap", 14 | "version": "1.6.3", 15 | "url": "http://github.com/massiveinteractive/mmvc", 16 | "dependencies": 17 | { 18 | "minject": "", 19 | "msignal": "" 20 | } 21 | } -------------------------------------------------------------------------------- /src/haxelib.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/mmvc/api/ICommand.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | interface ICommand 26 | { 27 | public function execute():Void; 28 | } 29 | -------------------------------------------------------------------------------- /src/mmvc/api/ICommandMap.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | import msignal.Signal; 26 | import mmvc.api.ICommand; 27 | 28 | typedef CommandClass = Class; 29 | typedef SignalClass = Class; 30 | 31 | interface ICommandMap 32 | { 33 | function mapSignal(signal:AnySignal, commandClass:CommandClass, ?oneShot:Bool=false):Void; 34 | 35 | function mapSignalClass(signalClass:SignalClass, commandClass:CommandClass, ?oneShot:Bool=false):AnySignal; 36 | 37 | function hasSignalCommand(signal:AnySignal, commandClass:CommandClass):Bool; 38 | 39 | function unmapSignal(signal:AnySignal, commandClass:CommandClass):Void; 40 | 41 | function unmapSignalClass(signalClass:SignalClass, commandClass:CommandClass):Void; 42 | 43 | function detain(command:ICommand):Void; 44 | 45 | function release(command:ICommand):Void; 46 | } 47 | -------------------------------------------------------------------------------- /src/mmvc/api/IContext.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | /** 26 | The mmvc Context contract 27 | **/ 28 | interface IContext 29 | { 30 | var commandMap(get, null):ICommandMap; 31 | } 32 | -------------------------------------------------------------------------------- /src/mmvc/api/IGuard.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | interface IGuard 26 | { 27 | function approve():Bool; 28 | } 29 | -------------------------------------------------------------------------------- /src/mmvc/api/IGuardedCommandMap.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | import msignal.Signal; 26 | import mmvc.api.ICommand; 27 | import mmvc.api.ICommandMap; 28 | import mmvc.api.IGuard; 29 | 30 | typedef GuardClassArray = Array>; 31 | 32 | interface IGuardedCommandMap extends ICommandMap 33 | { 34 | /** 35 | Map a Command to an instance of a Signal, with Guards 36 | 37 | - The `signal` - an instance of `Signal` 38 | - The `commandClass` must implement an `execute()` method 39 | - The `guards` must be a class which implements an `approve()` method or an `Array` of 40 | classes which implement an `approve()` method 41 | 42 | @param signal The signal instance to trigger this command. Values dispatched by this signal 43 | are available for injection into guards and the command. 44 | @param commandClass The class to instantiate - must have an `execute()` method 45 | @param guards The Classes of the guard or guards to instantiate - must have an `approve()` method 46 | @param oneshot Unmap the class after execution 47 | @throws `mmvc.base.ContextError` 48 | **/ 49 | function mapGuardedSignal(signal:AnySignal, commandClass:CommandClass, guards:GuardClassArray, 50 | oneshot:Bool=false):Void; 51 | 52 | /** 53 | Map a Command to an instance of a Signal, with Guards 54 | 55 | - The `signalClass` - a class implementing ISignal 56 | - The `commandClass` must implement an `execute()` method 57 | - The `guards` must be a class which implements an `approve()` method 58 | - or an `Array` of Classes which implements an `approve()` method 59 | 60 | @param commandClass The signal class to be created - an instance of this class is then 61 | available for injection as a singleton in the main Injector. 62 | @param commandClass The class to instantiate - must have an `execute()` method 63 | @param guards The Classes of the guard or guards to instantiate - must have an 64 | `approve()` method 65 | @param oneshot Unmap the class after execution? 66 | @throws `mmvc.base.ContextError` 67 | **/ 68 | function mapGuardedSignalClass(signalClass:SignalClass, commandClass:CommandClass, 69 | guards:GuardClassArray, oneShot:Bool=false):AnySignal; 70 | 71 | /** 72 | Map a Command to an instance of a Signal, with Guards and a fallback Command 73 | 74 | - The `signal` - an instance of ISignal 75 | - The `commandClass` must implement an `execute()` method - executed if the guards approve 76 | - The `fallbackCommandClass` must implement an `execute()` method 77 | - executed if the guards disapprove 78 | - The `guards` must be a class which implements an `approve()` method 79 | - or an `Array` of Classes which implements an `approve()` method 80 | 81 | @param signal The signal instance to trigger this command. Values dispatched by this signal 82 | are available for injection into guards and the command. 83 | @param commandClass The class to instantiate - must have an `execute()` method - executed if 84 | the guards approve 85 | @param fallbackCommandClass The class to instantiate - must have an `execute()` method - 86 | executed if the guards disapprove 87 | @param guards The Classes of the guard or guards to instantiate - must have an 88 | `approve()` method 89 | @param oneshot Unmap the class after execution? 90 | @throws `mmvc.base.ContextError` 91 | **/ 92 | function mapGuardedSignalWithFallback(signal:AnySignal, commandClass:CommandClass, 93 | fallbackCommandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):Void; 94 | 95 | /** 96 | Map a Command to an instance of a Signal, with Guards and a fallback Command 97 | 98 | - The `signalClass` - a class implementing ISignal 99 | - The `commandClass` must implement an `execute()` method - executed if the guards approve 100 | - The `fallbackCommandClass` must implement an `execute()` method 101 | - executed if the guards disapprove 102 | - The `guards` must be a class which implements an `approve()` method 103 | - or an `Array` of Classes which implements an `approve()` method 104 | 105 | @param signal The signal class to be created - an instance of this class is then available 106 | for injection as a singleton in the main Injector. 107 | @param commandClass The class to instantiate - must have an `execute()` method - executed 108 | if the guards approve 109 | @param fallbackCommandClass The class to instantiate - must have an `execute()` method - 110 | executed if the guards disapprove 111 | @param guards The Classes of the guard or guards to instantiate - must have an 112 | `approve()` method 113 | @param oneshot Unmap the class after execution? 114 | @throws `mmvc.base.ContextError` 115 | **/ 116 | function mapGuardedSignalClassWithFallback(signalClass:SignalClass, commandClass:CommandClass, 117 | fallbackCommandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):AnySignal; 118 | } 119 | -------------------------------------------------------------------------------- /src/mmvc/api/IMediator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | **/ 22 | 23 | package mmvc.api; 24 | 25 | /** 26 | The mmvc Mediator contract 27 | **/ 28 | interface IMediator 29 | { 30 | /** 31 | Should be invoked by the `IMediatorMap` during `IMediator` registration 32 | **/ 33 | function preRegister():Void; 34 | 35 | /** 36 | Should be invoked by the `IMediator` itself when it is ready to be interacted with. 37 | 38 | Override and place your initialization code here. 39 | **/ 40 | function onRegister():Void; 41 | 42 | /** 43 | Invoked when the `IMediator` has been removed by the `IMediatorMap`. 44 | **/ 45 | function preRemove():Void; 46 | 47 | /** 48 | Should be invoked by the `IMediator` itself when it is ready to for cleanup. 49 | 50 | Override and place your cleanup code here. 51 | **/ 52 | function onRemove():Void; 53 | 54 | /** 55 | The `IMediator`'s view component 56 | 57 | @return The view component 58 | **/ 59 | function getViewComponent():Dynamic; 60 | 61 | /** 62 | The `IMediator`'s view component 63 | 64 | @param The view component 65 | **/ 66 | function setViewComponent(viewComponent:Dynamic):Void; 67 | } 68 | -------------------------------------------------------------------------------- /src/mmvc/api/IMediatorMap.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | import mmvc.api.IViewContainer; 26 | 27 | /** 28 | The mmvc MediatorMap contract 29 | **/ 30 | interface IMediatorMap 31 | { 32 | 33 | /** 34 | Map an `IMediator` to a view class 35 | 36 | @param viewClassOrName The concrete view class or Fully Qualified classname 37 | @param mediatorClass The `IMediator` class 38 | @param injectViewAs The explicit view Interface or class that the mediator depends on *or* 39 | an Array of such Interfaces/Classes. 40 | @param autoCreate Automatically construct and register an instance of class `mediatorClass` 41 | when an instance of class `viewClass` is detected 42 | @param autoRemove Automatically remove an instance of class `mediatorClass` when its 43 | `viewClass` leaves the ancestory of the context view 44 | **/ 45 | function mapView(viewClassOrName:Dynamic, mediatorClass:Class, 46 | ?injectViewAs:Dynamic = null, ?autoCreate:Bool = true, ?autoRemove:Bool = true):Void; 47 | 48 | /** 49 | Unmap a view class 50 | 51 | @param viewClassOrName The concrete view class or Fully Qualified classname 52 | **/ 53 | function unmapView(viewClassOrName:Dynamic):Void; 54 | 55 | /** 56 | Create an instance of a mapped `IMediator` 57 | 58 | This will instantiate and register a Mediator for a given View Component. Mediator 59 | dependencies will be automatically resolved. 60 | 61 | @param viewComponent An instance of the view class previously mapped to an `IMediator` class 62 | @return The `IMediator` 63 | **/ 64 | function createMediator(viewComponent:Dynamic):IMediator; 65 | 66 | /** 67 | Manually register an `IMediator` instance 68 | 69 | > Registering a Mediator will *not* inject its dependencies. It is assumed that 70 | > dependencies are already satisfied. 71 | 72 | @param viewComponent The view component for the `IMediator` 73 | @param mediator The `IMediator` to register 74 | **/ 75 | function registerMediator(viewComponent:Dynamic, mediator:IMediator):Void; 76 | 77 | /** 78 | Remove a registered `IMediator` instance 79 | 80 | @param mediator The `IMediator` to remove 81 | @return The `IMediator` that was removed 82 | **/ 83 | function removeMediator(mediator:IMediator):IMediator; 84 | 85 | /** 86 | Remove a registered `IMediator` instance 87 | 88 | @param viewComponent The view that the `IMediator` was registered with 89 | @return The `IMediator` that was removed 90 | **/ 91 | function removeMediatorByView(viewComponent:Dynamic):IMediator; 92 | 93 | /** 94 | Retrieve a registered `IMediator` instance 95 | 96 | @param viewComponent The view that the `IMediator` was registered with 97 | @return The `IMediator` 98 | **/ 99 | function retrieveMediator(viewComponent:Dynamic):IMediator; 100 | 101 | /** 102 | Check if the view class has been mapped or not 103 | 104 | @param viewClassOrName The concrete view class or Fully Qualified classname 105 | @return Whether this view class has been mapped 106 | **/ 107 | function hasMapping(viewClassOrName:Dynamic):Bool; 108 | 109 | /** 110 | Check if the `IMediator` has been registered 111 | 112 | @param mediator The `IMediator` instance 113 | @return Whether this `IMediator` has been registered 114 | **/ 115 | function hasMediator(mediator:IMediator):Bool; 116 | 117 | /** 118 | Check if an `IMediator` has been registered for a view instance 119 | 120 | @param viewComponent The view that the `IMediator` was registered with 121 | @return Whether an `IMediator` has been registered for this view instance 122 | **/ 123 | function hasMediatorForView(viewComponent:Dynamic):Bool; 124 | 125 | /** 126 | The `IMediatorMap`'s `IViewContainer` 127 | 128 | @return view The `IViewContainer` to use as scope for this `IMediatorMap` 129 | **/ 130 | var contextView(default, set):IViewContainer; 131 | 132 | /** 133 | The `IMediatorMap`'s enabled status 134 | 135 | @return Whether the `IMediatorMap` is enabled 136 | **/ 137 | var enabled(default, set):Bool; 138 | } 139 | -------------------------------------------------------------------------------- /src/mmvc/api/ITriggerMap.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | interface ITriggerMap 26 | { 27 | /** 28 | Map trigger to a command. Trigger can be instance of a class, string or enum value. 29 | 30 | @param trigger Class to trigger the command 31 | @param trigger Command to be triggered 32 | **/ 33 | function map(trigger:Dynamic, command:Class):Void; 34 | 35 | /** 36 | Unmap trigger and a command. Trigger can be instance of a class, string or enum value. 37 | 38 | @param trigger Class to unmap 39 | **/ 40 | function unmap(trigger:Dynamic, command:Class):Void; 41 | 42 | /** 43 | Dispatch a trigger. A class of the trigger is evaluated and mapped command is executed. 44 | 45 | @param trigger Instance of a class 46 | **/ 47 | function dispatch(trigger:Dynamic):Void; 48 | } -------------------------------------------------------------------------------- /src/mmvc/api/IViewContainer.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | interface IViewContainer 26 | { 27 | var viewAdded:Dynamic -> Void; 28 | var viewRemoved:Dynamic -> Void; 29 | 30 | function isAdded(view:Dynamic):Bool; 31 | } 32 | -------------------------------------------------------------------------------- /src/mmvc/api/IViewMap.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.api; 24 | 25 | import mmvc.api.IViewContainer; 26 | 27 | /** 28 | The mmvc ViewMap contract. All IViewMap automatic injections occur AFTER 29 | the view components are added to the stage. 30 | **/ 31 | interface IViewMap 32 | { 33 | /** 34 | Map an entire package (including sub-packages) for automatic injection 35 | 36 | @param packageName The substring to compare 37 | **/ 38 | function mapPackage(packageName:String):Void; 39 | 40 | /** 41 | Unmap a package 42 | 43 | @param packageName The substring to compare 44 | **/ 45 | function unmapPackage(packageName:String):Void; 46 | 47 | /** 48 | Check if a package has been registered for automatic injection 49 | 50 | @param packageName The substring to compare 51 | @return Whether a package has been registered for automatic injection 52 | **/ 53 | function hasPackage(packageName:String):Bool; 54 | 55 | /** 56 | Map a view component class or interface for automatic injection 57 | 58 | @param type The concrete view Interface 59 | **/ 60 | function mapType(type:Class):Void; 61 | 62 | /** 63 | Unmap a view component class or interface 64 | 65 | @param type The concrete view Interface 66 | **/ 67 | function unmapType(type:Class):Void; 68 | 69 | /** 70 | Check if a class or interface has been registered for automatic injection 71 | 72 | @param type The concrete view interface 73 | @return Whether an interface has been registered for automatic injection 74 | **/ 75 | function hasType(type:Class):Bool; 76 | 77 | /** 78 | The `IViewMap`'s `IViewContainer` 79 | 80 | @return view The `IViewContainer` to use as scope for this `IViewMap` 81 | **/ 82 | var contextView(default, set):IViewContainer; 83 | 84 | /** 85 | The `IViewMap`'s enabled status 86 | 87 | @return Whether the `IViewMap` is enabled 88 | **/ 89 | var enabled(default, set):Bool; 90 | } 91 | -------------------------------------------------------------------------------- /src/mmvc/base/CommandMap.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base; 24 | 25 | import msignal.Signal; 26 | import minject.Injector; 27 | import minject.ClassMap; 28 | import mmvc.api.ICommand; 29 | import mmvc.api.ICommandMap; 30 | 31 | class CommandMap implements ICommandMap 32 | { 33 | var injector:Injector; 34 | var signalMap:Map>; 35 | var signalClassMap:ClassMap; 36 | var detainedCommands:Map; 37 | 38 | public function new(injector:Injector) 39 | { 40 | this.injector = injector; 41 | 42 | signalMap = new Map(); 43 | signalClassMap = new ClassMap(); 44 | detainedCommands = new Map(); 45 | } 46 | 47 | public function mapSignalClass(signalClass:SignalClass, commandClass:CommandClass, ?oneShot:Bool=false):AnySignal 48 | { 49 | var signal = getSignalClassInstance(signalClass); 50 | mapSignal(signal, commandClass, oneShot); 51 | return signal; 52 | } 53 | 54 | public function mapSignal(signal:AnySignal, commandClass:CommandClass, ?oneShot:Bool=false):Void 55 | { 56 | if (hasSignalCommand(signal, commandClass)) return; 57 | 58 | var signalCommandMap:ClassMap; 59 | 60 | if (signalMap.exists(signal)) 61 | { 62 | signalCommandMap = signalMap.get(signal); 63 | } 64 | else 65 | { 66 | signalCommandMap = new ClassMap(); 67 | signalMap.set(signal, signalCommandMap); 68 | } 69 | 70 | var me = this; 71 | var callbackFunction = Reflect.makeVarArgs(function(args) 72 | { 73 | me.routeSignalToCommand(signal, args, commandClass, oneShot); 74 | }); 75 | 76 | signalCommandMap.set(commandClass, callbackFunction); 77 | signal.add(callbackFunction); 78 | } 79 | 80 | public function unmapSignalClass(signalClass:SignalClass, commandClass:CommandClass) 81 | { 82 | var signal = getSignalClassInstance(signalClass); 83 | unmapSignal(signal, commandClass); 84 | if (!hasCommand(signal)) 85 | { 86 | injector.unmap(signalClass); 87 | signalClassMap.remove(signalClass); 88 | } 89 | } 90 | 91 | public function unmapSignal(signal:AnySignal, commandClass:CommandClass) 92 | { 93 | var callbacksByCommandClass = signalMap.get(signal); 94 | if (callbacksByCommandClass == null) return; 95 | 96 | var callbackFunction = callbacksByCommandClass.get(commandClass); 97 | if (callbackFunction == null) return; 98 | 99 | if (!hasCommand(signal)) signalMap.remove(signal); 100 | signal.remove(callbackFunction); 101 | callbacksByCommandClass.remove(commandClass); 102 | } 103 | 104 | function getSignalClassInstance(signalClass:SignalClass):AnySignal 105 | { 106 | if (signalClassMap.exists(signalClass)) 107 | { 108 | return cast(signalClassMap.get(signalClass), AnySignal); 109 | } 110 | 111 | return createSignalClassInstance(signalClass); 112 | } 113 | 114 | function createSignalClassInstance(signalClass:SignalClass):AnySignal 115 | { 116 | var injectorForSignalInstance = injector; 117 | 118 | if (injector.hasMapping(Injector)) 119 | { 120 | injectorForSignalInstance = injector.getInstance(Injector); 121 | } 122 | 123 | var signal:AnySignal = injectorForSignalInstance.instantiate(signalClass); 124 | injectorForSignalInstance.mapValue(signalClass, signal); 125 | signalClassMap.set(signalClass, signal); 126 | 127 | return signal; 128 | } 129 | 130 | public function hasCommand(signal:AnySignal):Bool 131 | { 132 | var callbacksByCommandClass = signalMap.get(signal); 133 | if (callbacksByCommandClass == null) return false; 134 | 135 | var count = 0; 136 | for (key in callbacksByCommandClass) count ++; 137 | return count > 0; 138 | } 139 | 140 | public function hasSignalCommand(signal:AnySignal, commandClass:Class):Bool 141 | { 142 | var callbacksByCommandClass = signalMap.get(signal); 143 | if (callbacksByCommandClass == null) return false; 144 | 145 | var callbackFunction = callbacksByCommandClass.get(commandClass); 146 | return callbackFunction != null; 147 | } 148 | 149 | function routeSignalToCommand(signal:AnySignal, valueObjects:Array, commandClass:CommandClass, oneshot:Bool) 150 | { 151 | injector.mapValue(AnySignal, signal); 152 | 153 | mapSignalValues(signal.valueClasses, valueObjects); 154 | var command = createCommandInstance(commandClass); 155 | injector.unmap(AnySignal); 156 | unmapSignalValues(signal.valueClasses, valueObjects); 157 | command.execute(); 158 | injector.attendedToInjectees.remove(command); 159 | 160 | if (oneshot) 161 | { 162 | unmapSignal(signal, commandClass); 163 | } 164 | } 165 | 166 | function createCommandInstance(commandClass:CommandClass):ICommand 167 | { 168 | return injector.instantiate(commandClass); 169 | } 170 | 171 | function mapSignalValues(valueClasses:Array, valueObjects:Array):Void 172 | { 173 | for (i in 0...valueClasses.length) 174 | { 175 | injector.mapValue(valueClasses[i], valueObjects[i]); 176 | } 177 | } 178 | 179 | function unmapSignalValues(valueClasses:Array, valueObjects:Array) 180 | { 181 | for (i in 0...valueClasses.length) 182 | { 183 | injector.unmap(valueClasses[i]); 184 | } 185 | } 186 | 187 | public function detain(command:ICommand) 188 | { 189 | detainedCommands.set(command, true); 190 | } 191 | 192 | public function release(command:ICommand) 193 | { 194 | if (detainedCommands.exists(command)) 195 | { 196 | detainedCommands.remove(command); 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /src/mmvc/base/ContextError.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base; 24 | 25 | /** 26 | A framework Error implementation 27 | **/ 28 | class ContextError 29 | { 30 | public var message:String; 31 | public var id:Int; 32 | 33 | public function new(?message:String = "", ?id:Int = 0) 34 | { 35 | this.message = message; 36 | this.id = id; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/mmvc/base/GuardedCommandMap.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base; 24 | 25 | import msignal.Signal; 26 | import minject.ClassMap; 27 | import minject.Injector; 28 | import mmvc.api.ICommandMap; 29 | import mmvc.api.IGuardedCommandMap; 30 | import mmvc.api.IGuard; 31 | import mmvc.api.ICommand; 32 | 33 | class GuardedCommandMap extends CommandMap implements IGuardedCommandMap 34 | { 35 | public function new(injector:Injector) 36 | { 37 | super(injector); 38 | } 39 | 40 | public function mapGuardedSignal(signal:AnySignal, commandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):Void 41 | { 42 | mapGuardedSignalWithFallback(signal, commandClass, null, guards, oneShot); 43 | } 44 | 45 | public function mapGuardedSignalClass(signalClass:SignalClass, commandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):AnySignal 46 | { 47 | return mapGuardedSignalClassWithFallback(signalClass, commandClass, null, guards, oneShot); 48 | } 49 | 50 | public function mapGuardedSignalWithFallback(signal:AnySignal, commandClass:CommandClass, fallbackCommandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):Void 51 | { 52 | if (hasSignalCommand(signal, commandClass)) 53 | { 54 | return; 55 | } 56 | 57 | var signalCommandMap:ClassMap; 58 | 59 | if (!signalMap.exists(signal)) 60 | { 61 | signalCommandMap = new ClassMap(); 62 | signalMap.set(signal, signalCommandMap); 63 | } 64 | else 65 | { 66 | signalCommandMap = signalMap.get(signal); 67 | } 68 | 69 | var me = this; 70 | var callbackFunction = Reflect.makeVarArgs(function(args) 71 | { 72 | me.routeSignalToGuardedCommand(signal, args, commandClass, fallbackCommandClass, oneShot, guards); 73 | }); 74 | 75 | signalCommandMap.set(commandClass, callbackFunction); 76 | signal.add(callbackFunction); 77 | } 78 | 79 | public function mapGuardedSignalClassWithFallback(signalClass:SignalClass, commandClass:CommandClass, fallbackCommandClass:CommandClass, guards:GuardClassArray, oneShot:Bool=false):AnySignal 80 | { 81 | var signal = getSignalClassInstance(signalClass); 82 | mapGuardedSignalWithFallback(signal, commandClass, fallbackCommandClass, guards, oneShot); 83 | return signal; 84 | } 85 | 86 | function routeSignalToGuardedCommand(signal:AnySignal, valueObjects:Array, commandClass:CommandClass, fallbackCommandClass:CommandClass, oneshot:Bool, guardClasses:GuardClassArray):Void 87 | { 88 | mapSignalValues(signal.valueClasses, valueObjects); 89 | 90 | var approved:Bool = true; 91 | 92 | for (guardClass in guardClasses) 93 | { 94 | var nextGuard:IGuard = injector.instantiate(guardClass); 95 | approved = (approved && nextGuard.approve()); 96 | 97 | if ((!approved) && (fallbackCommandClass == null)) 98 | { 99 | unmapSignalValues(signal.valueClasses, valueObjects); 100 | return; 101 | } 102 | } 103 | 104 | var commandToInstantiate:Class = approved ? commandClass : fallbackCommandClass; 105 | 106 | var command:ICommand = injector.instantiate(commandToInstantiate); 107 | unmapSignalValues(signal.valueClasses, valueObjects); 108 | command.execute(); 109 | 110 | if (oneshot) unmapSignal(signal, commandClass); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/mmvc/base/MediatorBase.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base; 24 | 25 | import mmvc.api.IMediator; 26 | import msignal.Slot; 27 | 28 | /** 29 | An abstract `IMediator` implementation 30 | **/ 31 | @:keepSub class MediatorBase implements IMediator 32 | { 33 | /** 34 | This Mediator's View - used by the mmvc framework internally. You should declare a 35 | dependency on a concrete view component in your implementation instead of working with 36 | this property 37 | **/ 38 | public var view:T; 39 | 40 | /* 41 | In the case of deffered instantiation, onRemove might get called before 42 | `onCreationComplete` has fired. This here Bool helps us track that scenario. 43 | **/ 44 | var removed:Bool; 45 | 46 | /** 47 | An array of slots to remove when the mediator is removed to ensure garbage collection. 48 | **/ 49 | var slots:Array; 50 | 51 | public function new() 52 | { 53 | slots = []; 54 | } 55 | 56 | public function preRegister():Void 57 | { 58 | removed = false; 59 | onRegister(); 60 | } 61 | 62 | public function onRegister():Void 63 | { 64 | } 65 | 66 | public function preRemove():Void 67 | { 68 | removed = true; 69 | onRemove(); 70 | } 71 | 72 | public function onRemove():Void 73 | { 74 | for (slot in slots) slot.remove(); 75 | } 76 | 77 | public function getViewComponent():Dynamic 78 | { 79 | return view; 80 | } 81 | 82 | public function setViewComponent(viewComponent:Dynamic):Void 83 | { 84 | view = viewComponent; 85 | } 86 | 87 | /** 88 | Stores reference to any signal listeners, ensuring they are removed during onRemove 89 | 90 | ```haxe 91 | mediate(something.completed.add(completed)); 92 | ``` 93 | **/ 94 | function mediate(slot:AnySlot) 95 | { 96 | slots.push(slot); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/mmvc/base/ViewMap.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base; 24 | 25 | import haxe.ds.ObjectMap; 26 | 27 | import minject.Injector; 28 | import minject.ClassMap; 29 | import mmvc.api.IViewMap; 30 | import mmvc.api.IViewContainer; 31 | 32 | using Lambda; 33 | 34 | /** 35 | An abstract `IViewMap` implementation 36 | **/ 37 | class ViewMap extends ViewMapBase implements IViewMap 38 | { 39 | var mappedPackages:Array; 40 | var mappedTypes:ClassMap>; 41 | var injectedViews:ObjectMap<{}, Dynamic>; 42 | 43 | /** 44 | Creates a new `ViewMap` object 45 | 46 | @param contextView The root view node of the context. 47 | @param injector An `Injector` to use for this context 48 | **/ 49 | public function new(contextView:IViewContainer, injector:Injector) 50 | { 51 | super(contextView, injector); 52 | mappedPackages = new Array(); 53 | mappedTypes = new ClassMap(); 54 | injectedViews = new ObjectMap(); 55 | } 56 | 57 | public function mapPackage(packageName:String):Void 58 | { 59 | if (mappedPackages.indexOf(packageName) > -1) return; 60 | mappedPackages.push(packageName); 61 | viewListenerCount++; 62 | if (viewListenerCount == 1) addListeners(); 63 | } 64 | 65 | public function unmapPackage(packageName:String):Void 66 | { 67 | if (!mappedPackages.remove(packageName)) return; 68 | viewListenerCount--; 69 | if (viewListenerCount == 0) removeListeners(); 70 | } 71 | 72 | public function mapType(type:Class):Void 73 | { 74 | if (mappedTypes.exists(type)) return; 75 | mappedTypes.set(type, type); 76 | viewListenerCount++; 77 | if (viewListenerCount == 1) addListeners(); 78 | if (contextView != null && Std.is(contextView, type)) injectInto(contextView); 79 | } 80 | 81 | public function unmapType(type:Class):Void 82 | { 83 | if (!mappedTypes.exists(type)) return; 84 | mappedTypes.remove(type); 85 | viewListenerCount--; 86 | if (viewListenerCount == 0) removeListeners(); 87 | } 88 | 89 | public function hasType(type:Class):Bool 90 | { 91 | return mappedTypes.exists(type); 92 | } 93 | 94 | public function hasPackage(packageName:String):Bool 95 | { 96 | return mappedPackages.indexOf(packageName) > -1; 97 | } 98 | 99 | override function addListeners():Void 100 | { 101 | if (contextView == null || !enabled) return; 102 | contextView.viewAdded = onViewAdded; 103 | contextView.viewRemoved = onViewAdded; 104 | } 105 | 106 | override function removeListeners():Void 107 | { 108 | if (contextView == null) return; 109 | contextView.viewAdded = null; 110 | contextView.viewRemoved = null; 111 | } 112 | 113 | override function onViewAdded(view:Dynamic):Void 114 | { 115 | if (injectedViews.exists(view)) return; 116 | 117 | for (type in mappedTypes) 118 | { 119 | if (Std.is(view, type)) 120 | { 121 | injectInto(view); 122 | return; 123 | } 124 | } 125 | 126 | var len = mappedPackages.length; 127 | 128 | if (len > 0) 129 | { 130 | var className = Type.getClassName(Type.getClass(view)); 131 | 132 | for (i in 0...len) 133 | { 134 | var packageName = mappedPackages[i]; 135 | 136 | if (className.indexOf(packageName) == 0) 137 | { 138 | injectInto(view); 139 | return; 140 | } 141 | } 142 | } 143 | } 144 | 145 | override function onViewRemoved(view:Dynamic):Void 146 | { 147 | // abstract 148 | } 149 | 150 | function injectInto(view:Dynamic):Void 151 | { 152 | injector.injectInto(view); 153 | injectedViews.set(view, true); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/mmvc/base/ViewMapBase.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base; 24 | 25 | import minject.Injector; 26 | import mmvc.api.IViewContainer; 27 | 28 | /** 29 | A base ViewMap implementation 30 | **/ 31 | class ViewMapBase 32 | { 33 | var injector:Injector; 34 | var viewListenerCount:Int; 35 | 36 | public var contextView(default, set):IViewContainer; 37 | public var enabled(default, set):Bool; 38 | 39 | /** 40 | Creates a new `ViewMap` object 41 | 42 | @param contextView The root view node of the context 43 | @param injector An `Injector` to use for this context 44 | **/ 45 | public function new(contextView:IViewContainer, injector:Injector) 46 | { 47 | viewListenerCount = 0; 48 | enabled = true; 49 | this.injector = injector; 50 | // this must come last, see the setter 51 | this.contextView = contextView; 52 | } 53 | 54 | public function set_contextView(value:IViewContainer):IViewContainer 55 | { 56 | if (value != contextView) 57 | { 58 | removeListeners(); 59 | contextView = value; 60 | if (viewListenerCount > 0) addListeners(); 61 | } 62 | return contextView; 63 | } 64 | 65 | public function set_enabled(value:Bool):Bool 66 | { 67 | if (value != enabled) 68 | { 69 | removeListeners(); 70 | enabled = value; 71 | if (viewListenerCount > 0) addListeners(); 72 | } 73 | return value; 74 | } 75 | 76 | function addListeners():Void {} 77 | function removeListeners():Void {} 78 | 79 | function onViewAdded(view:Dynamic):Void {} 80 | function onViewRemoved(view:Dynamic):Void {} 81 | } 82 | -------------------------------------------------------------------------------- /src/mmvc/impl/Actor.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | 25 | import minject.Injector; 26 | 27 | /** 28 | As part of the MVCS implementation the `Actor` provides core functionality to an applications 29 | various working parts. 30 | 31 | Some possible uses for the `Actor` include, but are no means limited to: 32 | 33 | - Service classes 34 | - Model classes 35 | - Controller classes 36 | - Presentation model classes 37 | 38 | Essentially any class where it might be advantageous to have basic dependency injection supplied 39 | is a candidate for extending `Actor`. 40 | **/ 41 | @:keepSub class Actor 42 | { 43 | @inject public var injector:Injector; 44 | 45 | public function new():Void {} 46 | } 47 | -------------------------------------------------------------------------------- /src/mmvc/impl/Command.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | import msignal.Signal; 25 | import minject.Injector; 26 | import mmvc.api.ICommandMap; 27 | import mmvc.api.ICommand; 28 | import mmvc.api.IMediatorMap; 29 | import mmvc.api.IViewContainer; 30 | 31 | /** 32 | Abstract MVCS command implementation 33 | **/ 34 | @:keepSub class Command implements ICommand 35 | { 36 | @inject public var contextView:IViewContainer; 37 | 38 | @inject public var commandMap:ICommandMap; 39 | 40 | @inject public var injector:Injector; 41 | 42 | @inject public var mediatorMap:IMediatorMap; 43 | 44 | @inject public var signal:AnySignal; 45 | 46 | public function new():Void {} 47 | 48 | public function execute():Void {} 49 | } 50 | -------------------------------------------------------------------------------- /src/mmvc/impl/Context.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | 25 | import mmvc.api.ICommandMap; 26 | import mmvc.api.IContext; 27 | import mmvc.api.IMediatorMap; 28 | import mmvc.api.ITriggerMap; 29 | import mmvc.api.IViewContainer; 30 | import mmvc.api.IViewMap; 31 | import mmvc.base.CommandMap; 32 | import mmvc.base.MediatorMap; 33 | import mmvc.base.TriggerMap; 34 | import mmvc.base.ViewMap; 35 | import minject.Injector; 36 | import minject.Reflector; 37 | 38 | /** 39 | Abstract MVCS `IContext` implementation 40 | **/ 41 | class Context implements IContext 42 | { 43 | var autoStartup:Bool; 44 | 45 | public var contextView(default, set):IViewContainer; 46 | 47 | public var commandMap(get, null):ICommandMap; 48 | 49 | public var injector(get, null):Injector; 50 | 51 | public var mediatorMap(get, null):IMediatorMap; 52 | 53 | public var reflector(get, null):Reflector; 54 | 55 | public var viewMap(get, null):IViewMap; 56 | 57 | public var triggerMap(get, null):ITriggerMap; 58 | 59 | /** 60 | Abstract Context Implementation 61 | 62 | Extend this class to create a Framework or Application context. 63 | 64 | @param contextView The root view node of the context. 65 | @param autoStartup Should this context automatically invoke it's `startup` method when it's 66 | `contextView` arrives on Stage 67 | **/ 68 | public function new(?contextView:IViewContainer=null, ?autoStartup:Bool=true) 69 | { 70 | this.autoStartup = autoStartup; 71 | this.contextView = contextView; 72 | } 73 | 74 | /** 75 | The startup hook. Override this in your Application context. 76 | **/ 77 | public function startup():Void {} 78 | 79 | /** 80 | The shutdown hook. Override this in your Application context. 81 | **/ 82 | public function shutdown():Void {} 83 | 84 | public function set_contextView(value:IViewContainer):IViewContainer 85 | { 86 | if (contextView != value) 87 | { 88 | contextView = value; 89 | commandMap = null; 90 | mediatorMap = null; 91 | viewMap = null; 92 | triggerMap = null; 93 | 94 | mapInjections(); 95 | checkAutoStartup(); 96 | } 97 | 98 | return value; 99 | } 100 | 101 | /** 102 | The `Injector` for this `IContext` 103 | **/ 104 | public function get_injector():Injector 105 | { 106 | if (injector == null) 107 | { 108 | return createInjector(); 109 | } 110 | 111 | return injector; 112 | } 113 | 114 | /** 115 | The `Reflector` for this `IContext` 116 | **/ 117 | function get_reflector():Reflector 118 | { 119 | if (reflector == null) 120 | { 121 | reflector = new Reflector(); 122 | } 123 | 124 | return reflector; 125 | } 126 | 127 | /** 128 | The `ICommandMap` for this `IContext` 129 | **/ 130 | function get_commandMap():ICommandMap 131 | { 132 | if (commandMap == null) 133 | { 134 | commandMap = new CommandMap(createChildInjector()); 135 | } 136 | 137 | return commandMap; 138 | } 139 | 140 | /** 141 | The `IMediatorMap` for this `IContext` 142 | **/ 143 | function get_mediatorMap():IMediatorMap 144 | { 145 | if (mediatorMap == null) 146 | { 147 | mediatorMap = new MediatorMap(contextView, createChildInjector(), reflector); 148 | } 149 | 150 | return mediatorMap; 151 | } 152 | 153 | /** 154 | The `IViewMap` for this `IContext` 155 | **/ 156 | function get_viewMap():IViewMap 157 | { 158 | if (viewMap == null) 159 | { 160 | viewMap = new ViewMap(contextView, injector); 161 | } 162 | 163 | return viewMap; 164 | } 165 | 166 | /** 167 | The `ITriggerMap` for this `IContext` 168 | **/ 169 | function get_triggerMap():ITriggerMap 170 | { 171 | if (triggerMap == null) 172 | { 173 | triggerMap = new TriggerMap(injector); 174 | } 175 | 176 | return triggerMap; 177 | } 178 | 179 | /** 180 | Injection Mapping Hook 181 | 182 | Override this in your application context to change the default configuration 183 | 184 | > Beware of collisions in your container 185 | **/ 186 | function mapInjections():Void 187 | { 188 | injector.mapValue(Reflector, reflector); 189 | injector.mapValue(Injector, injector); 190 | injector.mapValue(IViewContainer, contextView); 191 | injector.mapValue(ICommandMap, commandMap); 192 | injector.mapValue(IMediatorMap, mediatorMap); 193 | injector.mapValue(IViewMap, viewMap); 194 | injector.mapValue(ITriggerMap, triggerMap); 195 | } 196 | 197 | function checkAutoStartup():Void 198 | { 199 | if (autoStartup && contextView != null) 200 | { 201 | startup(); 202 | } 203 | } 204 | 205 | function createInjector():Injector 206 | { 207 | injector = new Injector(); 208 | return injector; 209 | } 210 | 211 | function createChildInjector():Injector 212 | { 213 | return injector.createChildInjector(); 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /src/mmvc/impl/Mediator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | 25 | import mmvc.base.MediatorBase; 26 | import mmvc.api.IMediatorMap; 27 | import mmvc.api.IViewContainer; 28 | import minject.Injector; 29 | 30 | /** 31 | Abstract MVCS `IMediator` implementation 32 | **/ 33 | class Mediator extends MediatorBase 34 | { 35 | @inject public var injector:Injector; 36 | 37 | @inject public var contextView:IViewContainer; 38 | 39 | @inject public var mediatorMap:IMediatorMap; 40 | 41 | public function new() 42 | { 43 | super(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/mmvc/impl/TriggerCommand.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | 25 | import minject.Injector; 26 | 27 | import mmvc.api.ICommand; 28 | import mmvc.api.ICommandMap; 29 | import mmvc.api.IMediatorMap; 30 | import mmvc.api.ITriggerMap; 31 | import mmvc.api.IViewContainer; 32 | 33 | // @:generic 34 | class TriggerCommand implements ICommand 35 | { 36 | @inject public var contextView:IViewContainer; 37 | @inject public var commandMap:ICommandMap; 38 | @inject public var injector:Injector; 39 | @inject public var mediatorMap:IMediatorMap; 40 | @inject public var triggerMap:ITriggerMap; 41 | 42 | public var trigger:T; 43 | 44 | public function new():Void{} 45 | public function execute(){} 46 | 47 | function dispatch(trigger:Dynamic) 48 | { 49 | triggerMap.dispatch(trigger); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/mmvc/impl/TriggerMediator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | 25 | import mmvc.api.ITriggerMap; 26 | 27 | class TriggerMediator extends Mediator 28 | { 29 | @inject public var triggerMap:ITriggerMap; 30 | 31 | function dispatch(trigger:Dynamic) 32 | { 33 | triggerMap.dispatch(trigger); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /target/haxelib/haxedoc.xml.hxml: -------------------------------------------------------------------------------- 1 | -js haxedoc.js 2 | --no-output 3 | -cp src 4 | -lib msignal 5 | -lib minject 6 | --macro include('mmvc') -------------------------------------------------------------------------------- /test/TestMain.hx: -------------------------------------------------------------------------------- 1 | import massive.munit.client.PrintClient; 2 | import massive.munit.client.RichPrintClient; 3 | import massive.munit.client.HTTPClient; 4 | import massive.munit.client.JUnitReportClient; 5 | import massive.munit.client.SummaryReportClient; 6 | import massive.munit.TestRunner; 7 | 8 | /** 9 | * Auto generated Test Application. 10 | * Refer to munit command line tool for more information (haxelib run munit) 11 | */ 12 | class TestMain 13 | { 14 | static function main(){ new TestMain(); } 15 | 16 | public function new() 17 | { 18 | var suites = new Array>(); 19 | suites.push(TestSuite); 20 | 21 | #if MCOVER 22 | var client = new mcover.coverage.munit.client.MCoverPrintClient(); 23 | var httpClient = new HTTPClient(new mcover.coverage.munit.client.MCoverSummaryReportClient()); 24 | #else 25 | var client = new RichPrintClient(); 26 | var httpClient = new HTTPClient(new SummaryReportClient()); 27 | #end 28 | 29 | var runner:TestRunner = new TestRunner(client); 30 | runner.addResultClient(httpClient); 31 | runner.addResultClient(new HTTPClient(new JUnitReportClient())); 32 | 33 | runner.completionHandler = completionHandler; 34 | runner.run(suites); 35 | } 36 | 37 | /* 38 | updates the background color and closes the current browser 39 | for flash and html targets (useful for continous integration servers) 40 | */ 41 | function completionHandler(successful:Bool):Void 42 | { 43 | try 44 | { 45 | #if flash 46 | flash.external.ExternalInterface.call("testResult", successful); 47 | #elseif js 48 | js.Lib.eval("testResult(" + successful + ");"); 49 | #elseif (neko || cpp || php) 50 | Sys.exit(0); 51 | #end 52 | } 53 | // if run from outside browser can get error which we can ignore 54 | catch (e:Dynamic) 55 | { 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/mmvc/base/TriggerMapTest.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base; 24 | 25 | import massive.munit.Assert; 26 | 27 | import mmvc.base.support.MockClass; 28 | import mmvc.base.support.MockEnum; 29 | import mmvc.base.support.MockResult; 30 | import mmvc.base.support.TriggerCommand_EnumValue; 31 | import mmvc.base.support.TriggerCommand_Instance; 32 | import mmvc.base.support.TriggerCommand_Int; 33 | import mmvc.base.support.TriggerCommand_MockClass; 34 | import mmvc.base.support.TriggerCommand_String; 35 | import mmvc.impl.Context; 36 | 37 | class TriggerMapTest 38 | { 39 | public function new(){} 40 | 41 | @Before 42 | public function before():Void 43 | { 44 | } 45 | 46 | @After 47 | public function after():Void 48 | { 49 | } 50 | 51 | @Test 52 | public function dispatched_triggers_command():Void 53 | { 54 | MockResult.result = null; 55 | MockResult.count = 0; 56 | var valueClass = new MockClass(); 57 | var valueString = "asdwe8fw4f"; 58 | var valueEnumValue = MockEnum.A; 59 | 60 | var context = new Context(new mmvc.base.support.TestContextView()); 61 | context.triggerMap.map(MockClass, TriggerCommand_MockClass); 62 | context.triggerMap.unmap(MockClass, TriggerCommand_MockClass); 63 | context.triggerMap.map(MockClass, TriggerCommand_MockClass); 64 | context.triggerMap.map(MockClass, TriggerCommand_MockClass); 65 | 66 | context.triggerMap.map(valueString, TriggerCommand_String); 67 | context.triggerMap.unmap(valueString, TriggerCommand_String); 68 | context.triggerMap.map(valueString, TriggerCommand_String); 69 | context.triggerMap.map(valueString, TriggerCommand_String); 70 | 71 | context.triggerMap.map(valueEnumValue, TriggerCommand_EnumValue); 72 | context.triggerMap.unmap(valueEnumValue, TriggerCommand_EnumValue); 73 | context.triggerMap.map(valueEnumValue, TriggerCommand_EnumValue); 74 | context.triggerMap.map(valueEnumValue, TriggerCommand_EnumValue); 75 | 76 | context.triggerMap.dispatch(valueClass); 77 | Assert.areEqual(valueClass, MockResult.result); 78 | Assert.areEqual(2, MockResult.count); 79 | 80 | context.triggerMap.dispatch(valueString); 81 | Assert.areEqual(valueString, MockResult.result); 82 | Assert.areEqual(4, MockResult.count); 83 | 84 | context.triggerMap.dispatch(valueEnumValue); 85 | Assert.areEqual(valueEnumValue, MockResult.result); 86 | Assert.areEqual(6, MockResult.count); 87 | } 88 | 89 | @Test 90 | public function dispatched_class_triggers_command():Void 91 | { 92 | MockResult.result = null; 93 | var mockClass = new MockClass(); 94 | 95 | var context = new Context(new mmvc.base.support.TestContextView()); 96 | var triggerMap:TriggerMap = cast context.triggerMap; 97 | triggerMap.mapClass(MockClass, TriggerCommand_MockClass); 98 | triggerMap.dispatchClass(mockClass); 99 | 100 | Assert.areEqual(mockClass, MockResult.result); 101 | } 102 | 103 | @Test 104 | public function dispatched_string_triggers_command():Void 105 | { 106 | MockResult.result = null; 107 | var value = "hello world"; 108 | 109 | var context = new Context(new mmvc.base.support.TestContextView()); 110 | var triggerMap:TriggerMap = cast context.triggerMap; 111 | triggerMap.mapString(value, TriggerCommand_String); 112 | triggerMap.dispatchString(value); 113 | 114 | Assert.areEqual(value, MockResult.result); 115 | } 116 | 117 | @Test 118 | public function dispatched_enumValue_triggers_command():Void 119 | { 120 | MockResult.result = null; 121 | 122 | var context = new Context(new mmvc.base.support.TestContextView()); 123 | var triggerMap:TriggerMap = cast context.triggerMap; 124 | triggerMap.mapEnumValue(MockEnum.A, TriggerCommand_EnumValue); 125 | triggerMap.dispatchEnumValue(MockEnum.A); 126 | 127 | Assert.areEqual(MockEnum.A, MockResult.result); 128 | } 129 | 130 | @Test 131 | public function dispatched_int_triggers_command():Void 132 | { 133 | MockResult.result = null; 134 | var value = 1; 135 | 136 | var context = new Context(new mmvc.base.support.TestContextView()); 137 | var triggerMap:TriggerMap = cast context.triggerMap; 138 | triggerMap.mapInt(value, TriggerCommand_Int); 139 | triggerMap.dispatchInt(value); 140 | 141 | Assert.areEqual(value, MockResult.result); 142 | } 143 | 144 | @Test 145 | public function dispatched_instance_triggers_command():Void 146 | { 147 | MockResult.result = null; 148 | 149 | var value = new MockClass(); 150 | 151 | var context = new Context(new mmvc.base.support.TestContextView()); 152 | var triggerMap:TriggerMap = cast context.triggerMap; 153 | triggerMap.mapInstance(value, TriggerCommand_Instance); 154 | triggerMap.dispatchInstance(value); 155 | 156 | Assert.areEqual(value, MockResult.result); 157 | } 158 | 159 | @Test 160 | public function dispatched_invalid_trigger_type_throws_exception():Void 161 | { 162 | var context = new Context(new mmvc.base.support.TestContextView()); 163 | var triggerMap:TriggerMap = cast context.triggerMap; 164 | var myDynamic:Dynamic = 1; 165 | var isError:Bool; 166 | 167 | isError = false; 168 | try 169 | { 170 | triggerMap.dispatch(1.1); 171 | } 172 | catch(error:Dynamic) 173 | { 174 | isError = true; 175 | } 176 | Assert.isTrue(isError); 177 | 178 | isError = false; 179 | try 180 | { 181 | triggerMap.dispatch(MockClass); 182 | } 183 | catch(error:Dynamic) 184 | { 185 | isError = true; 186 | } 187 | Assert.isTrue(isError); 188 | 189 | isError = false; 190 | try 191 | { 192 | triggerMap.dispatch(MockEnum); 193 | } 194 | catch(error:Dynamic) 195 | { 196 | isError = true; 197 | } 198 | Assert.isTrue(isError); 199 | 200 | isError = false; 201 | try 202 | { 203 | triggerMap.dispatchInstance("a"); 204 | } 205 | catch(error:Dynamic) 206 | { 207 | isError = true; 208 | } 209 | Assert.isTrue(isError); 210 | 211 | isError = false; 212 | try 213 | { 214 | triggerMap.dispatchInstance(myDynamic); 215 | } 216 | catch(error:Dynamic) 217 | { 218 | isError = true; 219 | } 220 | Assert.isTrue(isError); 221 | 222 | isError = false; 223 | try 224 | { 225 | triggerMap.dispatchInstance(MockClass); 226 | } 227 | catch(error:Dynamic) 228 | { 229 | isError = true; 230 | } 231 | Assert.isTrue(isError); 232 | 233 | isError = false; 234 | try 235 | { 236 | triggerMap.dispatchInstance(MockEnum); 237 | } 238 | catch(error:Dynamic) 239 | { 240 | isError = true; 241 | } 242 | Assert.isTrue(isError); 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /test/mmvc/base/ViewMapTest.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | 24 | package mmvc.base; 25 | 26 | import massive.munit.Assert; 27 | import minject.Injector; 28 | import minject.Reflector; 29 | import mmvc.base.support.TestView; 30 | import mmvc.base.support.ITestView; 31 | import mmvc.base.support.TestContextView; 32 | import minject.Injector; 33 | import minject.Reflector; 34 | import mmvc.api.IViewMap; 35 | import mmvc.api.IViewContainer; 36 | 37 | class ViewMapTest 38 | { 39 | public function new(){} 40 | 41 | static var INJECTION_NAME = "injectionName"; 42 | static var INJECTION_STRING = "injectionString"; 43 | 44 | var contextView:TestContextView; 45 | var testView:TestView; 46 | var injector:Injector; 47 | var reflector:Reflector; 48 | var viewMap:IViewMap; 49 | 50 | @Before 51 | public function before():Void 52 | { 53 | contextView = new TestContextView(); 54 | testView = new TestView(); 55 | injector = new Injector(); 56 | reflector = new Reflector(); 57 | viewMap = new ViewMap(contextView, injector); 58 | 59 | injector.mapValue(String, INJECTION_STRING, INJECTION_NAME); 60 | } 61 | 62 | @After 63 | public function after():Void 64 | { 65 | contextView = null; 66 | testView = null; 67 | injector = null; 68 | reflector = null; 69 | viewMap = null; 70 | injector = null; 71 | } 72 | 73 | @Test 74 | public function map_type():Void 75 | { 76 | viewMap.mapType(TestView); 77 | var mapped = viewMap.hasType(TestView); 78 | Assert.isTrue(mapped); 79 | } 80 | 81 | @Test 82 | public function unmap_type():Void 83 | { 84 | viewMap.mapType(TestView); 85 | viewMap.unmapType(TestView); 86 | var mapped = viewMap.hasType(TestView); 87 | Assert.isFalse(mapped); 88 | } 89 | 90 | @Test 91 | public function map_type_and_add_to_display():Void 92 | { 93 | viewMap.mapType(TestView); 94 | contextView.addView(testView); 95 | Assert.areEqual(INJECTION_STRING, testView.injectionPoint); 96 | } 97 | 98 | @Test 99 | public function unmap_type_and_add_to_display():Void 100 | { 101 | viewMap.mapType(TestView); 102 | viewMap.unmapType(TestView); 103 | contextView.addView(testView); 104 | Assert.isNull(testView.injectionPoint); 105 | } 106 | 107 | @Test 108 | public function map_type_and_add_to_display_twice():Void 109 | { 110 | viewMap.mapType(TestView); 111 | contextView.addView(testView); 112 | testView.injectionPoint = null; 113 | contextView.removeView(testView); 114 | contextView.addView(testView); 115 | Assert.isNull(testView.injectionPoint); 116 | } 117 | 118 | @Test 119 | public function map_type_of_context_view_should_inject_into_it():Void 120 | { 121 | viewMap.mapType(TestContextView); 122 | Assert.areEqual(INJECTION_STRING, contextView.injectionPoint); 123 | } 124 | 125 | @Test 126 | public function map_type_of_context_view_twice_should_inject_only_once():Void 127 | { 128 | viewMap.mapType(TestContextView); 129 | contextView.injectionPoint = null; 130 | viewMap.mapType(TestContextView); 131 | Assert.isNull(testView.injectionPoint); 132 | } 133 | 134 | @Test 135 | public function map_package():Void 136 | { 137 | viewMap.mapPackage('mmvc'); 138 | var mapped = viewMap.hasPackage('mmvc'); 139 | Assert.isTrue(mapped); 140 | } 141 | 142 | @Test 143 | public function unmap_package():Void 144 | { 145 | viewMap.mapPackage("mmvc"); 146 | viewMap.unmapPackage("mmvc"); 147 | var mapped = viewMap.hasPackage("mmvc"); 148 | Assert.isFalse(mapped); 149 | } 150 | 151 | @Test 152 | public function mapped_package_is_injected():Void 153 | { 154 | viewMap.mapPackage("mmvc"); 155 | contextView.addView(testView); 156 | Assert.areEqual(INJECTION_STRING, testView.injectionPoint); 157 | } 158 | 159 | @Test 160 | public function mapped_absolute_package_is_injected():Void 161 | { 162 | viewMap.mapPackage("mmvc.base.support"); 163 | contextView.addView(testView); 164 | Assert.areEqual(INJECTION_STRING, testView.injectionPoint); 165 | } 166 | 167 | @Test 168 | public function unmapped_package_should_not_be_injected():Void 169 | { 170 | viewMap.mapPackage("mmvc"); 171 | viewMap.unmapPackage("mmvc"); 172 | contextView.addView(testView); 173 | Assert.isNull(testView.injectionPoint); 174 | } 175 | 176 | @Test 177 | public function mapped_package_not_injected_twice_when_removed_and_added():Void 178 | { 179 | viewMap.mapPackage("mmvc"); 180 | contextView.addView(testView); 181 | testView.injectionPoint = null; 182 | contextView.removeView(testView); 183 | contextView.addView(testView); 184 | 185 | Assert.isNull(testView.injectionPoint); 186 | } 187 | 188 | @Test 189 | public function map_interface():Void 190 | { 191 | viewMap.mapType(ITestView); 192 | var mapped = viewMap.hasType(ITestView); 193 | Assert.isTrue(mapped); 194 | } 195 | 196 | @Test 197 | public function unmap_interface():Void 198 | { 199 | viewMap.mapType(ITestView); 200 | viewMap.unmapType(ITestView); 201 | var mapped = viewMap.hasType(ITestView); 202 | Assert.isFalse(mapped); 203 | } 204 | 205 | @Test 206 | public function mapped_interface_is_injected():Void 207 | { 208 | viewMap.mapType(ITestView); 209 | contextView.addView(testView); 210 | Assert.areEqual(INJECTION_STRING, testView.injectionPoint); 211 | } 212 | 213 | @Test 214 | public function unmapped_interface_should_not_be_injected():Void 215 | { 216 | viewMap.mapType(ITestView); 217 | viewMap.unmapType(ITestView); 218 | contextView.addView(testView); 219 | Assert.isNull(testView.injectionPoint); 220 | } 221 | 222 | @Test 223 | public function mapped_interface_not_injected_twice_when_removed_and_added():Void 224 | { 225 | viewMap.mapType(ITestView); 226 | contextView.addView(testView); 227 | testView.injectionPoint = null; 228 | contextView.removeView(testView); 229 | contextView.addView(testView); 230 | Assert.isNull(testView.injectionPoint); 231 | } 232 | 233 | @Test 234 | public function setting_enabled_does_stuff():Void 235 | { 236 | viewMap.enabled = true; 237 | viewMap.enabled = false; 238 | viewMap.enabled = true; 239 | 240 | viewMap.contextView = contextView; 241 | viewMap.contextView = null; 242 | viewMap.contextView = contextView; 243 | Assert.isTrue(true); 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /test/mmvc/base/support/ITestView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base.support; 24 | 25 | interface ITestView {} 26 | -------------------------------------------------------------------------------- /test/mmvc/base/support/MockClass.hx: -------------------------------------------------------------------------------- 1 | package mmvc.base.support; 2 | 3 | class MockClass 4 | { 5 | public function new(){} 6 | } -------------------------------------------------------------------------------- /test/mmvc/base/support/MockEnum.hx: -------------------------------------------------------------------------------- 1 | package mmvc.base.support; 2 | 3 | enum MockEnum 4 | { 5 | A; B; C; 6 | } -------------------------------------------------------------------------------- /test/mmvc/base/support/MockResult.hx: -------------------------------------------------------------------------------- 1 | package mmvc.base.support; 2 | 3 | class MockResult 4 | { 5 | public static var result:Dynamic; 6 | public static var count:Int = 0; 7 | } -------------------------------------------------------------------------------- /test/mmvc/base/support/TestCommand.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base.support; 24 | 25 | import mmvc.impl.support.ICommandTester; 26 | 27 | class TestCommand implements mmvc.api.ICommand 28 | { 29 | public function new(){} 30 | 31 | @inject 32 | public var testSuite:ICommandTester; 33 | 34 | public function execute():Void 35 | { 36 | testSuite.markCommandExecuted(); 37 | } 38 | } 39 | 40 | class TestCommand_InjectSignal implements mmvc.api.ICommand 41 | { 42 | public function new() { } 43 | 44 | @inject 45 | public var testSignal:TestSignal; 46 | 47 | @inject 48 | public var testSuite:ICommandTester; 49 | 50 | public function execute():Void 51 | { 52 | testSuite.markCommandExecuted(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TestCommand1.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base.support; 24 | 25 | import mmvc.impl.support.ICommandTester; 26 | 27 | class TestCommand1 implements mmvc.api.ICommand 28 | { 29 | public function new(){} 30 | 31 | @inject public var testSuite:ICommandTester; 32 | 33 | public function execute():Void 34 | { 35 | testSuite.markCommandExecuted(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TestCommand2.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base.support; 24 | 25 | import mmvc.impl.support.ICommandTester; 26 | 27 | class TestCommand2 implements mmvc.api.ICommand 28 | { 29 | public function new(){} 30 | 31 | @inject public var testSuite:ICommandTester; 32 | 33 | @inject public var param1:Int; 34 | @inject public var param2:String; 35 | 36 | public function execute():Void 37 | { 38 | testSuite.markCommand2Executed(param1, param2); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TestContextView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base.support; 24 | 25 | import haxe.ds.ObjectMap; 26 | 27 | import mmvc.api.IViewContainer; 28 | 29 | class TestContextView implements IViewContainer 30 | { 31 | var views:ObjectMap<{}, Bool>; 32 | 33 | public var viewAdded:Dynamic -> Void; 34 | public var viewRemoved:Dynamic -> Void; 35 | 36 | @inject("injectionName") 37 | public var injectionPoint:String; 38 | 39 | public function new() 40 | { 41 | views = new ObjectMap<{}, Bool>(); 42 | } 43 | 44 | public function addView(view:Dynamic) 45 | { 46 | views.set(view, true); 47 | 48 | if (viewAdded != null) 49 | { 50 | viewAdded(view); 51 | } 52 | } 53 | 54 | public function removeView(view:Dynamic) 55 | { 56 | views.remove(view); 57 | 58 | if (viewRemoved != null) 59 | { 60 | viewRemoved(view); 61 | } 62 | } 63 | 64 | public function isAdded(view:Dynamic) 65 | { 66 | return views.exists(view); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TestSignal.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base.support; 24 | 25 | import msignal.Signal; 26 | 27 | class TestSignal extends Signal0 28 | { 29 | public function new() 30 | { 31 | super(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TestSignal2.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base.support; 24 | 25 | import msignal.Signal; 26 | 27 | class TestSignal2 extends Signal2 28 | { 29 | public function new() 30 | { 31 | super(Int, String); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TestView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.base.support; 24 | 25 | class TestView implements ITestView 26 | { 27 | @inject("injectionName") 28 | public var injectionPoint:String; 29 | 30 | public function new() 31 | { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TriggerCommand_EnumValue.hx: -------------------------------------------------------------------------------- 1 | package mmvc.base.support; 2 | 3 | class TriggerCommand_EnumValue extends mmvc.impl.TriggerCommand 4 | { 5 | override function execute() 6 | { 7 | MockResult.result = trigger; 8 | MockResult.count++; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TriggerCommand_Instance.hx: -------------------------------------------------------------------------------- 1 | package mmvc.base.support; 2 | 3 | class TriggerCommand_Instance extends mmvc.impl.TriggerCommand 4 | { 5 | override public function execute() 6 | { 7 | MockResult.result = trigger; 8 | MockResult.count++; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TriggerCommand_Int.hx: -------------------------------------------------------------------------------- 1 | package mmvc.base.support; 2 | 3 | class TriggerCommand_Int extends mmvc.impl.TriggerCommand 4 | { 5 | override function execute() 6 | { 7 | MockResult.result = trigger; 8 | MockResult.count++; 9 | } 10 | } -------------------------------------------------------------------------------- /test/mmvc/base/support/TriggerCommand_MockClass.hx: -------------------------------------------------------------------------------- 1 | package mmvc.base.support; 2 | 3 | class TriggerCommand_MockClass extends mmvc.impl.TriggerCommand 4 | { 5 | override public function execute() 6 | { 7 | MockResult.result = trigger; 8 | MockResult.count++; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/mmvc/base/support/TriggerCommand_String.hx: -------------------------------------------------------------------------------- 1 | package mmvc.base.support; 2 | 3 | class TriggerCommand_String extends mmvc.impl.TriggerCommand 4 | { 5 | override function execute() 6 | { 7 | MockResult.result = trigger; 8 | MockResult.count++; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/mmvc/impl/ActorTest.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | 25 | import massive.munit.Assert; 26 | 27 | class ActorTest 28 | { 29 | public function new(){} 30 | 31 | @Test 32 | public function passingTest():Void 33 | { 34 | var actor = new Actor(); 35 | Assert.isType(actor, Actor); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/mmvc/impl/CommandTest.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | 25 | import massive.munit.Assert; 26 | 27 | class CommandTest 28 | { 29 | public function new(){} 30 | 31 | @Test 32 | public function create_command() 33 | { 34 | var command = new Command(); 35 | Assert.isType(command, Command); 36 | command.execute(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/mmvc/impl/ContextTest.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl; 24 | 25 | import massive.munit.Assert; 26 | import massive.munit.async.AsyncFactory; 27 | import mmvc.api.IViewContainer; 28 | import mmvc.impl.support.TestContext; 29 | import mmvc.impl.support.ICommandTester; 30 | import mmvc.base.support.TestContextView; 31 | 32 | class ContextTest implements ICommandTester 33 | { 34 | var context:TestContext; 35 | var contextView:TestContextView; 36 | var commandExecuted:Bool; 37 | 38 | public function new(){} 39 | 40 | @Before 41 | public function before():Void 42 | { 43 | commandExecuted = true; 44 | contextView = new TestContextView(); 45 | } 46 | 47 | @After 48 | public function after():Void 49 | { 50 | contextView = null; 51 | } 52 | 53 | @Test 54 | public function context_has_view_map():Void 55 | { 56 | var viewMap = context.viewMap; 57 | Assert.areEqual(viewMap, context.viewMap); 58 | } 59 | 60 | @Test 61 | public function autoStartupWithViewComponent():Void 62 | { 63 | context = new TestContext(contextView, true); 64 | Assert.isTrue(context.startupComplete); 65 | } 66 | 67 | @Test 68 | public function autoStartupWithLateViewComponent():Void 69 | { 70 | context = new TestContext(null, true); 71 | Assert.isFalse(context.startupComplete); 72 | context.contextView = contextView; 73 | Assert.isTrue(context.startupComplete); 74 | } 75 | 76 | @Test 77 | public function manualStartupWithViewComponent():Void 78 | { 79 | context = new TestContext(contextView, false); 80 | Assert.isFalse(context.startupComplete); 81 | context.startup(); 82 | Assert.isTrue(context.startupComplete); 83 | } 84 | 85 | @Test 86 | public function manualStartupWithLateViewComponent():Void 87 | { 88 | context = new TestContext(null, false); 89 | Assert.isFalse(context.startupComplete); 90 | context.contextView = contextView; 91 | context.startup(); 92 | Assert.isTrue(context.startupComplete); 93 | } 94 | 95 | @Test 96 | public function contextInitializationComplete():Void 97 | { 98 | context = new TestContext(contextView); 99 | Assert.isTrue(context.isInitialized); 100 | } 101 | 102 | @Test 103 | public function command_map_works():Void 104 | { 105 | context = new TestContext(contextView); 106 | context.injector.mapValue(ICommandTester, this); 107 | 108 | var signal = new mmvc.base.support.TestSignal(); 109 | context.commandMap.mapSignal(signal, mmvc.base.support.TestCommand); 110 | signal.dispatch(); 111 | 112 | Assert.isTrue(commandExecuted); 113 | } 114 | 115 | public function markCommandExecuted():Void 116 | { 117 | commandExecuted = true; 118 | } 119 | 120 | public function markCommand2Executed(param1:Int, param2:String){} 121 | 122 | public function resetCommandExecuted():Void 123 | { 124 | commandExecuted = false; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/ICommandTester.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | interface ICommandTester 26 | { 27 | function resetCommandExecuted():Void; 28 | function markCommandExecuted():Void; 29 | function markCommand2Executed(param1:Int, param2:String):Void; 30 | } 31 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/TestActor.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | import mmvc.impl.Actor; 26 | import mmvc.impl.ActorTest; 27 | 28 | class TestActor extends Actor 29 | { 30 | public function new() 31 | { 32 | super(); 33 | } 34 | 35 | public function dispatchTestEvent():Void 36 | { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/TestCommand.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | class TestCommand 26 | { 27 | public function new(){} 28 | 29 | @inject 30 | public var testSuite:ICommandTester; 31 | 32 | public function execute():Void 33 | { 34 | testSuite.markCommandExecuted(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/TestContext.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | import minject.Injector; 26 | import mmvc.api.IViewContainer; 27 | import mmvc.impl.Context; 28 | 29 | class TestContext extends Context 30 | { 31 | public var isInitialized(get, null):Bool; 32 | public var startupComplete:Bool ; 33 | 34 | public function new(?contextView:IViewContainer=null, ?autoStartup:Bool=true) 35 | { 36 | startupComplete = false; 37 | super(contextView, autoStartup); 38 | } 39 | 40 | public override function startup():Void 41 | { 42 | startupComplete = true; 43 | super.startup(); 44 | } 45 | 46 | public function getInjector():Injector 47 | { 48 | return this.injector; 49 | } 50 | 51 | public function get_isInitialized():Bool 52 | { 53 | var initialized:Bool = true; 54 | initialized = (commandMap != null && initialized); 55 | initialized = (mediatorMap != null && initialized); 56 | return initialized; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/TestContextView.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | import haxe.ds.ObjectMap; 26 | 27 | import mmvc.api.IViewContainer; 28 | 29 | class TestContextView implements IViewContainer 30 | { 31 | var views:ObjectMap<{}, Bool>; 32 | 33 | public var viewAdded:Dynamic -> Void; 34 | public var viewRemoved:Dynamic -> Void; 35 | 36 | @inject("injectionName") 37 | public var injectionPoint:String; 38 | 39 | public function new() 40 | { 41 | views = new ObjectMap(); 42 | } 43 | 44 | public function addView(view:Dynamic) 45 | { 46 | views.set(view, true); 47 | 48 | if (viewAdded != null) 49 | { 50 | viewAdded(view); 51 | } 52 | } 53 | 54 | public function removeView(view:Dynamic) 55 | { 56 | views.remove(view); 57 | 58 | if (viewRemoved != null) 59 | { 60 | viewRemoved(view); 61 | } 62 | } 63 | 64 | public function isAdded(view:Dynamic) 65 | { 66 | return views.exists(view); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/TestContextViewMediator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | import mmvc.impl.Mediator; 26 | import msignal.Signal; 27 | 28 | class TestContextViewMediator extends Mediator 29 | { 30 | public var registered(default, null):Signal0; 31 | 32 | public function new() 33 | { 34 | super(); 35 | 36 | registered = new Signal0(); 37 | } 38 | 39 | public override function onRegister():Void 40 | { 41 | registered.dispatch(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/ViewComponent.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | class ViewComponent 26 | { 27 | public function new() 28 | { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/ViewComponentAdvanced.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | class ViewComponentAdvanced extends ViewComponent 26 | { 27 | public function new() 28 | { 29 | super(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/ViewMediator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | import mmvc.impl.Mediator; 26 | 27 | class ViewMediator extends Mediator 28 | { 29 | public function new() 30 | { 31 | super(); 32 | } 33 | 34 | public override function onRegister():Void 35 | { 36 | 37 | } 38 | 39 | public override function onRemove():Void 40 | { 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/mmvc/impl/support/ViewMediatorAdvanced.hx: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Massive Interactive 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package mmvc.impl.support; 24 | 25 | class ViewMediatorAdvanced extends ViewMediator 26 | { 27 | @inject 28 | public var viewAdvanced:ViewComponentAdvanced; 29 | 30 | public function new() 31 | { 32 | super(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/targets.hxml: -------------------------------------------------------------------------------- 1 | -main TestMain 2 | -debug 3 | -lib munit 4 | -lib hamcrest 5 | -lib msignal 6 | -lib minject 7 | -cp src 8 | -cp test 9 | -swf-version 9 10 | -swf bin/test/as3_test.swf 11 | 12 | --next 13 | 14 | -main TestMain 15 | -debug 16 | -lib munit 17 | -lib hamcrest 18 | -lib msignal 19 | -lib minject 20 | -cp src 21 | -cp test 22 | -js bin/test/js_test.js 23 | 24 | --next 25 | 26 | -main TestMain 27 | -debug 28 | -lib munit 29 | -lib hamcrest 30 | -lib msignal 31 | -lib minject 32 | -cp src 33 | -cp test 34 | -neko bin/test/neko_test.n 35 | 36 | --next 37 | 38 | -main TestMain 39 | -debug 40 | -lib munit 41 | -lib hamcrest 42 | -lib msignal 43 | -lib minject 44 | -cp src 45 | -cp test 46 | -cpp bin/test/cpp_test 47 | --------------------------------------------------------------------------------