Skip to content

Commit 9953768

Browse files
committed
Channeling message to commands added.
1 parent df87082 commit 9953768

File tree

12 files changed

+115
-28
lines changed

12 files changed

+115
-28
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,18 @@ public class VisualizerManager {
176176
}
177177
break;
178178
case MvcTraceActions.MODULEBASE_SENDMESSAGE:
179+
case MvcTraceActions.MODULEBASE_SENDCHANNELMESSAGE:
179180
case MvcTraceActions.MEDIATOR_SENDMESSAGE:
180-
case MvcTraceActions.MEDIATOR_CHANNELMESSAGE:
181+
case MvcTraceActions.MEDIATOR_SENDCHANNELMESSAGE:
181182
case MvcTraceActions.PROXY_SENDMESSAGE:
182183
case MvcTraceActions.COMMAND_SENDMESSAGE:
183184
case MvcTraceActions.MESSENGER_SENDTOALL:
184185
sendMessageStack.push(logObj);
185186
break;
186187
case MvcTraceActions.MODULEBASE_SENDMESSAGE_CLEAN:
188+
case MvcTraceActions.MODULEBASE_SENDCHANNELMESSAGE_CLEAN:
187189
case MvcTraceActions.MEDIATOR_SENDMESSAGE_CLEAN:
188-
case MvcTraceActions.MEDIATOR_CHANNELMESSAGE_CLEAN:
190+
case MvcTraceActions.MEDIATOR_SENDCHANNELMESSAGE_CLEAN:
189191
case MvcTraceActions.PROXY_SENDMESSAGE_CLEAN:
190192
case MvcTraceActions.COMMAND_SENDMESSAGE_CLEAN:
191193
case MvcTraceActions.MESSENGER_SENDTOALL_CLEAN:

src/org/mvcexpress/core/CommandMap.as

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import flash.utils.describeType;
44
import flash.utils.Dictionary;
55
import flash.utils.getDefinitionByName;
66
import flash.utils.getQualifiedClassName;
7-
import integration.channeling.testObj.moduleA.ComTest1Command;
87
import org.mvcexpress.core.messenger.Messenger;
98
import org.mvcexpress.core.namespace.pureLegsCore;
109
import org.mvcexpress.core.traceObjects.MvcTraceActions;
@@ -140,16 +139,25 @@ public class CommandMap {
140139
//----------------------------------
141140

142141
public function channelMap(type:String, commandClass:Class, scopeName:String = "global"):void {
143-
trace( "CommandMap.channelMap > type : " + type + ", commandClass : " + commandClass + ", scopeName : " + scopeName );
144-
142+
trace("CommandMap.channelMap > type : " + type + ", commandClass : " + commandClass + ", scopeName : " + scopeName);
143+
use namespace pureLegsCore;
144+
//
145+
var scopedType:String = scopeName + "_«¬_" + type;
146+
if (!classRegistry[scopedType]) {
147+
classRegistry[scopedType] = new Vector.<Class>();
148+
// TODO : check if chonnelCommandMap must be here...
149+
ModuleManager.channelCommandMap(handleCommandExecute, type, commandClass, scopeName);
150+
}
151+
// TODO : check if command is already added. (in DEBUG mode only?.)
152+
classRegistry[scopedType].push(commandClass);
145153
}
146154

147155
//----------------------------------
148156
// INTERNAL
149157
//----------------------------------
150158

151159
/** function to be called by messenger on needed message type sent */
152-
private function handleCommandExecute(messageType:String, params:Object):void {
160+
pureLegsCore function handleCommandExecute(messageType:String, params:Object):void {
153161
var commandList:Vector.<Class>;
154162
commandList = classRegistry[messageType];
155163

src/org/mvcexpress/core/ModuleBase.as

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.mvcexpress.core.ModuleManager;
99
import org.mvcexpress.core.namespace.pureLegsCore;
1010
import org.mvcexpress.core.ProxyMap;
1111
import org.mvcexpress.core.traceObjects.MvcTraceActions;
12+
import org.mvcexpress.core.traceObjects.TraceModuleBase_sendChannelMessage;
1213
import org.mvcexpress.core.traceObjects.TraceModuleBase_sendMessage;
1314
import org.mvcexpress.core.traceObjects.TraceObj;
1415
import org.mvcexpress.MvcExpress;
@@ -158,6 +159,28 @@ public class ModuleBase {
158159
_messenger.sendToAll(type, params);
159160
}
160161

162+
/**
163+
* TODO : comment
164+
* @param type
165+
* @param params
166+
* @param scopeName
167+
*/
168+
public function sendChannelMessage(type:String, params:Object, scopeName:String):void {
169+
use namespace pureLegsCore;
170+
// log the action
171+
CONFIG::debug {
172+
use namespace pureLegsCore;
173+
MvcExpress.debug(new TraceModuleBase_sendChannelMessage(MvcTraceActions.MODULEBASE_SENDCHANNELMESSAGE, _moduleName, this, type, params));
174+
}
175+
ModuleManager.sendChannelMessage(type, params, scopeName);
176+
//
177+
// clean up loging the action
178+
CONFIG::debug {
179+
use namespace pureLegsCore;
180+
MvcExpress.debug(new TraceModuleBase_sendChannelMessage(MvcTraceActions.MODULEBASE_SENDCHANNELMESSAGE_CLEAN, _moduleName, this, type, params));
181+
}
182+
}
183+
161184
//----------------------------------
162185
// utils
163186
//----------------------------------

src/org/mvcexpress/core/ModuleManager.as

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class ModuleManager {
110110
use namespace pureLegsCore;
111111
var channelMesanger:Messenger = channels[scopeName];
112112
if (channelMesanger) {
113-
channelMesanger.send(type, params);
113+
channelMesanger.send(scopeName + "_«¬_" + type, params);
114114
}
115115
}
116116

@@ -123,17 +123,35 @@ public class ModuleManager {
123123
Messenger.allowInstantiation = false;
124124
channels[scopeName] = channelMesanger;
125125
}
126-
return channelMesanger.addHandler(type, handler);
126+
return channelMesanger.addHandler(scopeName + "_«¬_" + type, handler);
127127
}
128128

129129
static pureLegsCore function removeChannelHandler(type:String, handler:Function, scopeName:String):void {
130130
//use namespace pureLegsCore;
131131
var channelMesanger:Messenger = channels[scopeName];
132132
if (channelMesanger) {
133-
channelMesanger.removeHandler(type, handler);
133+
channelMesanger.removeHandler(scopeName + "_«¬_" + type, handler);
134134
}
135135
}
136136

137+
138+
//----------------------------------
139+
// Command channeling
140+
//----------------------------------
141+
142+
static public function channelCommandMap(handleCommandExecute:Function, type:String, commandClass:Class, scopeName:String = "global"):void {
143+
var channelMesanger:Messenger = channels[scopeName];
144+
if (!channelMesanger) {
145+
use namespace pureLegsCore;
146+
Messenger.allowInstantiation = true;
147+
channelMesanger = new Messenger("$channel_" + scopeName);
148+
Messenger.allowInstantiation = false;
149+
channels[scopeName] = channelMesanger;
150+
}
151+
channelMesanger.addCommandHandler(scopeName + "_«¬_" + type, handleCommandExecute, commandClass);
152+
}
153+
154+
137155
//----------------------------------
138156
// DEBUG
139157
//----------------------------------

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class MvcTraceActions {
3030
static public const MESSENGER_SEND:String = "Messenger.send";
3131
static public const MESSENGER_SENDTOALL:String = "Messenger.sendToAll";
3232

33+
34+
3335

3436
//----------------------------------
3537
// For internal use
@@ -39,16 +41,20 @@ public class MvcTraceActions {
3941

4042
static pureLegsCore const MESSENGER_SEND_HANDLER:String = "Messenger.send.HANDLER";
4143
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";
4444

4545
static pureLegsCore const MODULEBASE_SENDMESSAGE:String = "ModuleBase.sendMessage";
4646
static pureLegsCore const MODULEBASE_SENDMESSAGE_CLEAN:String = "ModuleBase.sendMessage.CLEAN";
47+
static pureLegsCore const MODULEBASE_SENDCHANNELMESSAGE:String = "ModuleBase.sendChannelMessage";
48+
static pureLegsCore const MODULEBASE_SENDCHANNELMESSAGE_CLEAN:String = "ModuleBase.sendChannelMessage.CLEAN";
49+
50+
4751
static pureLegsCore const COMMAND_SENDMESSAGE:String = "Command.sendMessage";
4852
static pureLegsCore const COMMAND_SENDMESSAGE_CLEAN:String = "Command.sendMessage.CLEAN";
4953

5054
static pureLegsCore const MEDIATOR_SENDMESSAGE:String = "Mediator.sendMessage";
5155
static pureLegsCore const MEDIATOR_SENDMESSAGE_CLEAN:String = "Mediator.sendMessage.CLEAN";
56+
static pureLegsCore const MEDIATOR_SENDCHANNELMESSAGE:String = "Mediator.sendChannelMessage";
57+
static pureLegsCore const MEDIATOR_SENDCHANNELMESSAGE_CLEAN:String = "Mediator.sendChannelMessage.CLEAN";
5258
static pureLegsCore const MEDIATOR_ADDHANDLER:String = "Mediator.addHandler";
5359

5460
static pureLegsCore const PROXY_SENDMESSAGE:String = "Proxy.sendMessage";
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.core.ModuleBase;
5+
6+
/**
7+
* COMMENT
8+
* @author Raimundas Banevicius (http://www.mindscriptact.com/)
9+
*/
10+
public class TraceModuleBase_sendChannelMessage extends TraceObj_SendMessage {
11+
12+
public var type:String;
13+
public var params:Object;
14+
15+
public function TraceModuleBase_sendChannelMessage(action:String, moduleName:String, moduleObject:ModuleBase, type:String, params:Object) {
16+
super(action, moduleName);
17+
this.moduleObject = moduleObject;
18+
this.type = type;
19+
this.params = params;
20+
//
21+
canPrint = false;
22+
}
23+
24+
}
25+
}

src/org/mvcexpress/modules/ModuleCore.as

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ public class ModuleCore {
104104
moduleBase.sendMessageToAll(type, params);
105105
}
106106

107+
/**
108+
* TODO : comment
109+
* @param type
110+
* @param params
111+
* @param scopeName
112+
*/
107113
protected function sendChannelMessage(type:String, params:Object = null, scopeName:String = "global"):void {
108-
trace("ModuleCore.sendChannelMessage > type : " + type + ", params : " + params + ", scopeName : " + scopeName);
114+
moduleBase.sendChannelMessage(type, params, scopeName);
109115
}
110116

111117
//----------------------------------

src/org/mvcexpress/mvc/Mediator.as

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ public class Mediator {
175175
// log the action
176176
CONFIG::debug {
177177
use namespace pureLegsCore;
178-
MvcExpress.debug(new TraceMediator_channelMessage(MvcTraceActions.MEDIATOR_CHANNELMESSAGE, messenger.moduleName, this, type, params));
178+
MvcExpress.debug(new TraceMediator_channelMessage(MvcTraceActions.MEDIATOR_SENDCHANNELMESSAGE, messenger.moduleName, this, type, params));
179179
}
180180
ModuleManager.sendChannelMessage(type, params, scopeName);
181181
//
182182
// clean up loging the action
183183
CONFIG::debug {
184184
use namespace pureLegsCore;
185-
MvcExpress.debug(new TraceMediator_channelMessage(MvcTraceActions.MEDIATOR_CHANNELMESSAGE_CLEAN, messenger.moduleName, this, type, params));
185+
MvcExpress.debug(new TraceMediator_channelMessage(MvcTraceActions.MEDIATOR_SENDCHANNELMESSAGE_CLEAN, messenger.moduleName, this, type, params));
186186
}
187187
}
188188

test/integration/channeling/ChannelingTests.as

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,19 @@ public class ChannelingTests {
138138
Assert.assertFalse(channelModulA.view.test3handled);
139139
}
140140

141-
[Test]
141+
[Test]
142142

143143
public function channeling_messegeToCommandChanneling_addChannelCommand_commandsHandlesMessage():void {
144144
//
145145
channelModulA.mapCommand_ComTest1();
146146
//
147-
Assert.assertFalse("Cammand test1 executed flag mast be false", channelModulA.command1executed);
147+
Assert.assertFalse("Cammand test1 executed flag mast be false", channelModulB.command1executed);
148148
//
149-
channelModulA.sendChannelMessage_comTest1();
149+
channelModulB.sendChannelMessage_comTest1();
150150
//
151-
Assert.assertTrue("Command test1 must be true after commandMap.channelMap() and sendChannelMessage()", channelModulA.command1executed);
152-
153-
}
151+
Assert.assertTrue("Command test1 must be true after commandMap.channelMap() and sendChannelMessage()", channelModulB.command1executed);
154152

153+
}
155154

156155
}
157156
}

test/integration/channeling/testObj/moduleA/ChannelModuleA.as

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public class ChannelModuleA extends ModuleCore {
1212

1313
static public const NAME:String = "ChannelModuleA";
1414

15-
public var command1executed:Boolean = false;
16-
1715
public function ChannelModuleA() {
1816
super(ChannelModuleA.NAME);
1917
}
@@ -48,10 +46,6 @@ public class ChannelModuleA extends ModuleCore {
4846
commandMap.channelMap("CommTest1", ComTest1Command);
4947
}
5048

51-
public function sendChannelMessage_comTest1():void {
52-
sendChannelMessage("CommTest1", this);
53-
}
54-
5549
override protected function onInit():void {
5650

5751
}

0 commit comments

Comments
 (0)