Skip to content

Commit e2dc35d

Browse files
committed
Proxy message sending visualization added.
1 parent efa5ce9 commit e2dc35d

File tree

10 files changed

+130
-16
lines changed

10 files changed

+130
-16
lines changed

mvcExpressLogger/com/mindscriptact/mvcExpressLogger/screens/MvcExpressVisualizerScreen.as

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ public class MvcExpressVisualizerScreen extends Sprite {
110110
}
111111

112112
public function drawMessageToMediator(messageLogObj:Object, possition:int):void {
113+
var messageFromObject:Object;
113114
var messageShape:Shape;
114115
if (mediators[possition]) {
115116
var mediatorLabel:Label = mediators[possition].view;
116117
if (mediatorLabel) {
117118
// handle message from mediator
118-
var messageFromObject:Object = messageLogObj.messageFromMediator;
119+
messageFromObject = messageLogObj.messageFromMediator;
119120
if (messageFromObject) {
120121
for (var j:int = 0; j < mediators.length; j++) {
121122
if (mediators[j].mediatorObject == messageFromObject) {
@@ -142,6 +143,34 @@ public class MvcExpressVisualizerScreen extends Sprite {
142143
}
143144
}
144145
}
146+
// handle message from proxy
147+
messageFromObject = messageLogObj.messageFromProxy;
148+
if (messageFromObject) {
149+
for (var k:int = 0; k < proxies.length; k++) {
150+
if (proxies[k].proxyObject == messageFromObject) {
151+
var sourceProxyLabel:Label = proxies[k].view;
152+
if (sourceProxyLabel) {
153+
154+
messageShape = new Shape();
155+
messageShape.graphics.lineStyle(2, 0xD2D2FF, 0.3);
156+
//messageShape.graphics.lineTo(50, (sourceProxyLabel.y - mediatorLabel.y) * 0.2);
157+
messageShape.graphics.lineTo(600 - 300, sourceProxyLabel.y - mediatorLabel.y);
158+
159+
messageShape.graphics.moveTo(0, 0);
160+
messageShape.graphics.lineTo(10, -2);
161+
messageShape.graphics.lineTo(10, 2);
162+
messageShape.graphics.lineTo(0, 0);
163+
164+
messageShape.x = mediatorLabel.width;
165+
messageShape.y = 10;
166+
mediatorLabel.addChild(messageShape);
167+
168+
setTimeout(hideShape, 1500, messageShape);
169+
}
170+
break;
171+
}
172+
}
173+
}
145174
}
146175
}
147176
}
@@ -234,6 +263,7 @@ public class MvcExpressVisualizerScreen extends Sprite {
234263
//----------------------------------
235264

236265
public function addCommand(commandLogObj:Object):void {
266+
var messageFromObject:Object;
237267
var commandPosition:int = -1;
238268
//
239269
for (var i:int = 0; i < commands.length; i++) {
@@ -262,7 +292,7 @@ public class MvcExpressVisualizerScreen extends Sprite {
262292
this.addChild(commandLabel);
263293

264294
// handle message from mediator
265-
var messageFromObject:Object = commandLogObj.messageFromMediator;
295+
messageFromObject = commandLogObj.messageFromMediator;
266296
if (messageFromObject) {
267297
for (var j:int = 0; j < mediators.length; j++) {
268298
if (mediators[j].mediatorObject == messageFromObject) {
@@ -280,6 +310,26 @@ public class MvcExpressVisualizerScreen extends Sprite {
280310
}
281311
}
282312
}
313+
// handle message from proxy
314+
messageFromObject = commandLogObj.messageFromProxy;
315+
if (messageFromObject) {
316+
for (var k:int = 0; k < proxies.length; k++) {
317+
if (proxies[k].proxyObject == messageFromObject) {
318+
var proxyLabel:Label = proxies[k].view;
319+
if (proxyLabel) {
320+
commandLabel.graphics.lineStyle(2, 0xFFFFD9, 0.3);
321+
commandLabel.graphics.moveTo(commandLabel.width, 10);
322+
commandLabel.graphics.lineTo(-commandLabel.x + proxyLabel.x, -commandLabel.y + proxyLabel.y + proxyLabel.height - 10);
323+
//
324+
commandLabel.graphics.moveTo(commandLabel.width, 10);
325+
commandLabel.graphics.lineTo(commandLabel.width + 10, 10 - 2);
326+
commandLabel.graphics.lineTo(commandLabel.width + 10, 10 + 2);
327+
commandLabel.graphics.lineTo(commandLabel.width, 10);
328+
}
329+
break;
330+
}
331+
}
332+
}
283333

284334
setTimeout(removeObject, 1500, commandPosition, commandLogObj);
285335
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ public class VisualizerManager {
144144
if (topObject.moduleName == logObj.moduleName && topObject.type == logObj.type && topObject.params == logObj.params) {
145145
if (topObject.mediatorObject) {
146146
logObj.messageFromMediator = topObject.mediatorObject;
147+
} else if (topObject.proxyObject) {
148+
logObj.messageFromProxy = topObject.proxyObject;
149+
} else {
150+
CONFIG::debug {
151+
throw Error("NOT HANDLED:" + logObj);
152+
}
147153
}
148154
}
149155
this.mvcExpressVisualizerScreen.addCommand(logObj);
@@ -163,9 +169,11 @@ public class VisualizerManager {
163169
}
164170
break;
165171
case "Mediator.sendMessage":
172+
case "Proxy.sendMessage":
166173
sendMessageStack.push(logObj);
167174
break;
168175
case "Mediator.sendMessage.CLEAN":
176+
case "Proxy.sendMessage.CLEAN":
169177
topObject = sendMessageStack.pop();
170178
if (logObj.type != topObject.type) {
171179
CONFIG::debug {
@@ -230,17 +238,24 @@ public class VisualizerManager {
230238
for (var m:int = 0; m < handlerObjects.length; m++) {
231239
if (handlerObjects[m].handler == logObj.handler) {
232240
if (topObject.moduleName == logObj.moduleName && topObject.type == logObj.type && topObject.params == logObj.params) {
241+
// remember there message comes from.
233242
if (topObject.mediatorObject) {
234243
logObj.messageFromMediator = topObject.mediatorObject;
244+
} else if (topObject.proxyObject) {
245+
logObj.messageFromProxy = topObject.proxyObject;
246+
} else {
247+
CONFIG::debug {
248+
throw Error("NOT HANDLED:" + logObj);
249+
}
235250
}
251+
this.mvcExpressVisualizerScreen.drawMessageToMediator(logObj, l);
236252
}
237-
this.mvcExpressVisualizerScreen.drawMessageToMediator(logObj, l);
253+
238254
}
239255
}
240256
}
241257
}
242258
}
243-
244259
} else {
245260
CONFIG::debug {
246261
throw Error("NOT HANDLED:" + logObj);

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/VisualLoggerTestModule.as

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.mindScriptAct.modules.ModuleNames;
55
import com.mindscriptact.mvcExpressLogger.MvcExpressLogger;
66
import com.mindScriptAct.mvcExpressVisualizer.controller.TestCommandA;
77
import com.mindScriptAct.mvcExpressVisualizer.controller.TestCommandB;
8+
import com.mindScriptAct.mvcExpressVisualizer.controller.TestCommandBlank;
89
import com.mindScriptAct.mvcExpressVisualizer.messages.Message;
910
import com.mindScriptAct.mvcExpressVisualizer.model.ITestProxyB;
1011
import com.mindScriptAct.mvcExpressVisualizer.model.TestProxyA;
@@ -40,6 +41,8 @@ public class VisualLoggerTestModule extends ModuleSprite {
4041
private var testViewB2:TestViewB;
4142
private var testProxyCButton:PushButton;
4243
private var testProxyC:TestProxyC;
44+
private var testMessageB1Button:PushButton;
45+
private var testMessageB2Button:PushButton;
4346

4447
public function VisualLoggerTestModule() {
4548
CONFIG::debug {
@@ -59,6 +62,7 @@ public class VisualLoggerTestModule extends ModuleSprite {
5962
commandMap.map(Message.TEST_COMMAND_B, TestCommandB);
6063
commandMap.map(Message.TEST_MEDIATOR_A_COMMAND, TestCommandA);
6164
commandMap.map(Message.TEST_MEDIATOR_B_COMMAND, TestCommandB);
65+
commandMap.map(Message.TEST_PROXY_TO_COMMAND, TestCommandBlank);
6266

6367
// set up data
6468
proxyMap.map(new TestProxyA());
@@ -79,10 +83,10 @@ public class VisualLoggerTestModule extends ModuleSprite {
7983
testViewB1Button = new PushButton(this, 10, 530, "Add TestViewB 1", handleAddMediatorB1);
8084
testViewB2Button = new PushButton(this, 150, 530, "Add TestViewB 2", handleAddMediatorB2);
8185

82-
testViewB1Button = new PushButton(this, 300, 500, "Module:Execute CommandA", handleCommandA);
83-
testViewB1Button.width = 150;
84-
testViewB2Button = new PushButton(this, 300, 530, "Module:Send message", handleCommandB);
85-
testViewB2Button.width = 150;
86+
testMessageB1Button = new PushButton(this, 300, 500, "Module:Execute CommandA", handleCommandA);
87+
testMessageB1Button.width = 150;
88+
testMessageB2Button = new PushButton(this, 300, 530, "Module:Send message", handleCommandB);
89+
testMessageB2Button.width = 150;
8690

8791
testProxyCButton = new PushButton(this, 180, 570, "Add TestProxyC", handleAddProxyC);
8892

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.mindScriptAct.mvcExpressVisualizer.controller {
2+
import org.mvcexpress.mvc.Command;
3+
4+
/**
5+
* TODO:CLASS COMMENT
6+
* @author Raimundas Banevicius (http://www.mindscriptact.com/)
7+
*/
8+
public class TestCommandBlank extends Command{
9+
10+
//[Inject]
11+
//public var myProxy:MyProxy;
12+
13+
public function execute(blank:Object):void{
14+
15+
}
16+
17+
}
18+
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/messages/Message.as

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class Message {
1010
static public const TEST_MEDIATOR_B_COMMAND:String = "testMediatorBCommand";
1111
static public const TEST_MESSAGE_TO_MEDIATORS_B:String = "testMessageToMediatorsB";
1212
static public const TEST_MESSAGE_TO_MEDIATORS_A:String = "testMessageToMediatorsA";
13+
static public const TEST_PROXY_TO_MEDIATOR:String = "testProxyToMediator";
14+
static public const TEST_PROXY_TO_COMMAND:String = "testProxyToCommand";
1315

1416

1517
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/model/TestProxyA.as

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.mindScriptAct.mvcExpressVisualizer.model {
2+
import com.mindScriptAct.mvcExpressVisualizer.messages.Message;
23
import org.mvcexpress.mvc.Proxy;
34

45
/**
@@ -11,6 +12,10 @@ public class TestProxyA extends Proxy{
1112

1213
}
1314

15+
public function changeSomething():void {
16+
sendMessage(Message.TEST_PROXY_TO_MEDIATOR);
17+
}
18+
1419
override protected function onRegister():void{
1520

1621
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/model/TestProxyB.as

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.mindScriptAct.mvcExpressVisualizer.model {
2+
import com.mindScriptAct.mvcExpressVisualizer.messages.Message;
23
import org.mvcexpress.mvc.Proxy;
34

45
/**
@@ -25,7 +26,7 @@ public class TestProxyB extends Proxy implements ITestProxyB {
2526
/* INTERFACE com.mindScriptAct.mvcExpressVisualizer.model.ITestProxyB */
2627

2728
public function testFunction():void {
28-
29+
sendMessage(Message.TEST_PROXY_TO_COMMAND);
2930
}
3031
}
3132
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/view/testA/TestViewAMediator.as

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class TestViewAMediator extends Mediator {
4242
}
4343

4444
private function handleSendProxyMessage(event:Event):void {
45-
45+
testProxyA.changeSomething();
4646
}
4747

4848
override public function onRemove():void {

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/view/testB/TestViewBMediator.as

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ public class TestViewBMediator extends Mediator {
2828
pushButton.width = 150;
2929

3030
addHandler(Message.TEST_MESSAGE_TO_MEDIATORS_B, handleMediatorTest);
31-
}
32-
33-
private function handleMediatorTest(blank:Object):void {
34-
31+
addHandler(Message.TEST_PROXY_TO_MEDIATOR, handleProxyTest);
3532
}
3633

3734
private function handleSendCommandMessage(event:Event):void {
@@ -43,12 +40,19 @@ public class TestViewBMediator extends Mediator {
4340
}
4441

4542
private function handleSendProxyMessage(event:Event):void {
46-
43+
testProxyB.testFunction();
4744
}
4845

4946
override public function onRemove():void {
47+
// do nothing.
48+
}
5049

50+
private function handleProxyTest(blank:Object):void {
51+
// do nothing.
52+
}
53+
54+
private function handleMediatorTest(blank:Object):void {
55+
// do nothing.
5156
}
52-
5357
}
5458
}

src/org/mvcexpress/mvc/Proxy.as

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.mvcexpress.core.interfaces.IProxyMap;
44
import org.mvcexpress.core.messenger.Messenger;
55
import org.mvcexpress.core.namespace.pureLegsCore;
66
import org.mvcexpress.core.ProxyMap;
7+
import org.mvcexpress.MvcExpress;
78

89
/**
910
* Proxy holds and manages application data, provide API to work with it. </br>
@@ -36,8 +37,22 @@ public class Proxy {
3637
* @param params Object that will be passed to Command execute() function and to handle functions.
3738
*/
3839
protected function sendMessage(type:String, params:Object = null):void {
40+
// log the action
41+
CONFIG::debug {
42+
if (MvcExpress.loggerFunction != null) {
43+
MvcExpress.loggerFunction({action: "Proxy.sendMessage", proxyObject: this, type: type, params: params});
44+
}
45+
}
46+
//
3947
use namespace pureLegsCore;
4048
messenger.send(type, params);
49+
//
50+
// clean up loging the action
51+
CONFIG::debug {
52+
if (MvcExpress.loggerFunction != null) {
53+
MvcExpress.loggerFunction({action: "Proxy.sendMessage.CLEAN", proxyObject: this, type: type, params: params});
54+
}
55+
}
4156
}
4257

4358
/**

0 commit comments

Comments
 (0)