Skip to content

Commit f83083c

Browse files
committed
Module to module channeling with tests.
1 parent 412a30a commit f83083c

File tree

18 files changed

+479
-22
lines changed

18 files changed

+479
-22
lines changed

mvcExpressLogger/com/mindscriptact/mvcExpressLogger/visualizer/VisualizerManager.as

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,18 @@ public class VisualizerManager {
177177
break;
178178
case MvcTraceActions.MODULEBASE_SENDMESSAGE:
179179
case MvcTraceActions.MEDIATOR_SENDMESSAGE:
180+
case MvcTraceActions.MEDIATOR_CHANNELMESSAGE:
180181
case MvcTraceActions.PROXY_SENDMESSAGE:
181182
case MvcTraceActions.COMMAND_SENDMESSAGE:
182183
case MvcTraceActions.MESSENGER_SENDTOALL:
183184
sendMessageStack.push(logObj);
184185
break;
185186
case MvcTraceActions.MODULEBASE_SENDMESSAGE_CLEAN:
186187
case MvcTraceActions.MEDIATOR_SENDMESSAGE_CLEAN:
188+
case MvcTraceActions.MEDIATOR_CHANNELMESSAGE_CLEAN:
187189
case MvcTraceActions.PROXY_SENDMESSAGE_CLEAN:
188190
case MvcTraceActions.COMMAND_SENDMESSAGE_CLEAN:
189-
case MvcTraceActions.MESSENGER_SENDTOALL_CLEAN:
191+
case MvcTraceActions.MESSENGER_SENDTOALL_CLEAN:
190192
topObject = sendMessageStack.pop();
191193
if (logObj.type != topObject.type) {
192194
CONFIG::debug {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.mindScriptAct.modularSample.constants {
2+
3+
/**
4+
* COMMENT
5+
* @author Raimundas Banevicius ([email protected])
6+
*/
7+
public class ChannelNames {
8+
static public const FIRST_CHANNEL:String = "firstChannel";
9+
static public const EVEN_CHANNEL:String = "evenChannel";
10+
11+
12+
}
13+
}

sampleProjects/com/mindScriptAct/modularSample/view/ModularSampleMediator.as

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mindScriptAct.modularSample.view {
22
import com.bit101.components.PushButton;
3+
import com.mindScriptAct.modularSample.constants.ChannelNames;
34
import com.mindScriptAct.modularSample.ModularSample;
45
import com.mindScriptAct.modules.console.Console;
56
import com.mindScriptAct.modules.console.msg.ConsoleMsg;
@@ -106,15 +107,15 @@ public class ModularSampleMediator extends Mediator {
106107
}
107108

108109
public function handleMessageToFirst(event:MouseEvent):void {
109-
sendMessageToAll(GlobalMessage.SEND_TARGETED_INPUT_MESSAGE, new ConsoleParams("Message to FIRST module!!!", [1]));
110+
sendChannelMessage(GlobalMessage.SEND_TARGETED_INPUT_MESSAGE, new ConsoleParams("Message to FIRST module!!!", [1]), ChannelNames.FIRST_CHANNEL);
110111
}
111112

112113
public function handleMessageToEven(event:MouseEvent):void {
113-
sendMessageToAll(GlobalMessage.SEND_TARGETED_INPUT_MESSAGE, new ConsoleParams("Message to even modules!!! (2 and 4)", [2, 4]));
114+
sendChannelMessage(GlobalMessage.SEND_TARGETED_INPUT_MESSAGE, new ConsoleParams("Message to even modules!!! (2 and 4)", [2, 4]), ChannelNames.EVEN_CHANNEL);
114115
}
115116

116117
public function handleMessageToAll(event:MouseEvent):void {
117-
sendMessageToAll(GlobalMessage.SEND_INPUT_MESSAGE_TO_ALL, "Global message to all modules!!!");
118+
sendChannelMessage(GlobalMessage.SEND_INPUT_MESSAGE_TO_ALL, "Global message to all modules!!!");
118119
}
119120

120121
//public function handleMessageToAllNoStore(event:MouseEvent):void {

sampleProjects/com/mindScriptAct/modules/console/Console.as

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Console extends ModuleSprite {
4747
//commandMap.mapRemote(GlobalMessage.SEND_TARGETED_INPUT_MESSAGE, HandleTargetedMessageCommand, ModuleNames.SHELL);
4848
//commandMap.mapRemote(GlobalMessage.SEND_INPUT_MESSAGE_TO_ALL, HandleInputCommand, ModuleNames.SHELL);
4949
commandMap.map(ConsoleViewMsg.INPUT_MESSAGE, HandleInputCommand);
50+
5051
commandMap.map(GlobalMessage.SEND_INPUT_MESSAGE_TO_ALL, HandleInputCommand);
5152
commandMap.map(GlobalMessage.SEND_TARGETED_INPUT_MESSAGE, HandleTargetedMessageCommand);
5253

sampleProjects/com/mindScriptAct/modules/console/view/ConsoleMediator.as

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.mindScriptAct.modules.console.view {
2+
import com.mindScriptAct.modularSample.constants.ChannelNames;
23
import com.mindScriptAct.modules.console.Console;
34
import com.mindScriptAct.modules.console.msg.ConsoleDataMsg;
45
import com.mindScriptAct.modules.console.msg.ConsoleViewMsg;
@@ -23,6 +24,13 @@ public class ConsoleMediator extends Mediator {
2324
addHandler(ConsoleDataMsg.MESSAGE_ADDED, handleMessageAdded);
2425
//addRemoteHandler(GlobalMessage.SEND_INPUT_MESSAGE_TO_ALL_DONT_STORE, handleMessageAdded, ModuleNames.SHELL);
2526

27+
addChannelHandler(GlobalMessage.SEND_TARGETED_INPUT_MESSAGE, handleTargeterMessage, ChannelNames.FIRST_CHANNEL);
28+
29+
}
30+
31+
private function handleTargeterMessage(params:ConsoleParams):void {
32+
trace( "ConsoleMediator.handleTargeterMessage > params : " + params );
33+
2634
}
2735

2836
override public function onRemove():void {

src/org/mvcexpress/MvcExpress.as

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class MvcExpress {
1515
/** Current framework major version */
1616
public static const MAJOR_VERSION:uint = 1;
1717
/** Current framework minor version */
18-
public static const MINOR_VERSION:uint = 0;
18+
public static const MINOR_VERSION:uint = 1;
1919
/** Current framework revision version */
20-
public static const REVISION:uint = 1;
20+
public static const REVISION:uint = 0;
2121

2222
/** Current framework version */
2323
public static function get VERSION():String {

src/org/mvcexpress/core/ModuleManager.as

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
22
package org.mvcexpress.core {
33
import flash.utils.Dictionary;
4+
import org.mvcexpress.core.messenger.HandlerVO;
45
import org.mvcexpress.core.messenger.Messenger;
56
import org.mvcexpress.core.namespace.pureLegsCore;
67
import org.mvcexpress.core.traceObjects.MvcTraceActions;
@@ -22,9 +23,12 @@ public class ModuleManager {
2223
/* modules stored by moduleName */
2324
static private var moduleRegistry:Dictionary = new Dictionary(); /* of ModuleBase by String */
2425

25-
/* TODO : comment */
26+
/* all modules stared by module name */
2627
static private var allModules:Vector.<ModuleBase> = new Vector.<ModuleBase>();
2728

29+
/* all channel messengers stored by channel name */
30+
static private var channels:Dictionary = new Dictionary(); /* of Messenger by String*/
31+
2832
/** CONSTRUCTOR */
2933
public function ModuleManager() {
3034
throw Error("ModuleFactory is static framework class for internal use. Not meant to be instantiated.");
@@ -97,16 +101,36 @@ public class ModuleManager {
97101
}
98102
}
99103

100-
/**
101-
* sends message to all messengers.
102-
* @param type message type to find needed handlers
103-
* @param params parameter object that will be sent to all handler functions as single parameter.
104-
* @private
105-
*/
106-
static pureLegsCore function sendMessageToAll(type:String, params:Object):void {
104+
//----------------------------------
105+
// channel
106+
//----------------------------------
107+
108+
static pureLegsCore function sendChannelMessage(type:String, params:Object, channelName:String):void {
109+
trace("ModuleManager.channelMessage > type : " + type + ", params : " + params + ", channelName : " + channelName);
107110
use namespace pureLegsCore;
108-
for (var i:int = 0; i < allModules.length; i++) {
109-
allModules[i].messenger.send(type, params);
111+
var channelMesanger:Messenger = channels[channelName];
112+
if (channelMesanger) {
113+
channelMesanger.send(type, params);
114+
}
115+
}
116+
117+
static pureLegsCore function addChannelHandler(type:String, handler:Function, channelName:String):HandlerVO {
118+
var channelMesanger:Messenger = channels[channelName];
119+
if (!channelMesanger) {
120+
use namespace pureLegsCore;
121+
Messenger.allowInstantiation = true;
122+
channelMesanger = new Messenger("$channel_" + channelName);
123+
Messenger.allowInstantiation = false;
124+
channels[channelName] = channelMesanger;
125+
}
126+
return channelMesanger.addHandler(type, handler);
127+
}
128+
129+
static pureLegsCore function removeChannelHandler(type:String, handler:Function, channelName:String):void {
130+
//use namespace pureLegsCore;
131+
var channelMesanger:Messenger = channels[channelName];
132+
if (channelMesanger) {
133+
channelMesanger.removeHandler(type, handler);
110134
}
111135
}
112136

@@ -169,6 +193,22 @@ public class ModuleManager {
169193
return "Module with name :" + moduleName + " is not found.";
170194
}
171195
}
172-
196+
197+
//----------------------------------
198+
// DEPRICATED
199+
//----------------------------------
200+
201+
/**
202+
* sends message to all messengers.
203+
* @param type message type to find needed handlers
204+
* @param params parameter object that will be sent to all handler functions as single parameter.
205+
* @private
206+
*/
207+
static pureLegsCore function sendMessageToAll(type:String, params:Object):void {
208+
use namespace pureLegsCore;
209+
for (var i:int = 0; i < allModules.length; i++) {
210+
allModules[i].messenger.send(type, params);
211+
}
212+
}
173213
}
174214
}

src/org/mvcexpress/core/messenger/Messenger.as

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,15 @@ public class Messenger {
160160
}
161161

162162
/**
163-
* sends message to all existing modules.
163+
*
164+
* DEPRICATED : sends message to all existing modules.
164165
* @param type message type to find needed handlers
165166
* @param params parameter object that will be sent to all handler and execute functions as single parameter.
167+
* @deprecated 1.1
166168
*/
167169
public function sendToAll(type:String, params:Object = null):void {
170+
trace("WARNING: sendToAll() is depricated in favour of sendChannelMessage().");
171+
//
168172
use namespace pureLegsCore;
169173
// debug this action
170174
CONFIG::debug {

src/org/mvcexpress/core/traceObjects/MvcTraceActions.as

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class MvcTraceActions {
2929
static public const MESSENGER_REMOVEHANDLER:String = "Messenger.removeHandler";
3030
static public const MESSENGER_SEND:String = "Messenger.send";
3131
static public const MESSENGER_SENDTOALL:String = "Messenger.sendToAll";
32+
3233

3334
//----------------------------------
3435
// For internal use
@@ -38,6 +39,8 @@ public class MvcTraceActions {
3839

3940
static pureLegsCore const MESSENGER_SEND_HANDLER:String = "Messenger.send.HANDLER";
4041
static pureLegsCore const MESSENGER_SENDTOALL_CLEAN:String = "Messenger.sendToAll.CLEAN";
42+
static pureLegsCore const MEDIATOR_CHANNELMESSAGE:String = "Mediator.channelmessage";
43+
static pureLegsCore const MEDIATOR_CHANNELMESSAGE_CLEAN:String = "Mediator.channelmessage.CLEAN";
4144

4245
static pureLegsCore const MODULEBASE_SENDMESSAGE:String = "ModuleBase.sendMessage";
4346
static pureLegsCore const MODULEBASE_SENDMESSAGE_CLEAN:String = "ModuleBase.sendMessage.CLEAN";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
2+
package org.mvcexpress.core.traceObjects {
3+
import flash.display.DisplayObject;
4+
import org.mvcexpress.mvc.Mediator;
5+
6+
/**
7+
* COMMENT
8+
* @author Raimundas Banevicius (http://www.mindscriptact.com/)
9+
*/
10+
public class TraceMediator_channelMessage extends TraceObj_SendMessage {
11+
12+
public var type:String;
13+
public var params:Object;
14+
15+
public function TraceMediator_channelMessage(action:String, moduleName:String, mediatorObject:Mediator, type:String, params:Object) {
16+
super(action, moduleName);
17+
this.mediatorObject = mediatorObject;
18+
this.type = type;
19+
this.params = params;
20+
//
21+
canPrint = false;
22+
}
23+
24+
}
25+
}

0 commit comments

Comments
 (0)