Skip to content

Commit 2bead0f

Browse files
committed
Mapping same proxy under different id improved.
1 parent 6795d51 commit 2bead0f

File tree

5 files changed

+67
-26
lines changed

5 files changed

+67
-26
lines changed

sampleProjects/com/mindScriptAct/codeSnippets/SpriteModuleTest.as

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.mindScriptAct.codeSnippets {
2+
import com.mindScriptAct.codeSnippets.controller.ManyInjectsCommand;
23
import com.mindScriptAct.codeSnippets.controller.params.ComplexParams;
34
import com.mindScriptAct.codeSnippets.controller.SampleCommand;
45
import com.mindScriptAct.codeSnippets.messages.DataMsg;
@@ -12,6 +13,7 @@ import com.mindScriptAct.codeSnippets.view.keyboard.KeyboardMediator;
1213
import com.mindScriptAct.codeSnippets.view.MainAppMediator;
1314
import flash.display.StageAlign;
1415
import flash.display.StageScaleMode;
16+
import flash.utils.Proxy;
1517
import flash.utils.setTimeout;
1618
import org.mvcexpress.modules.ModuleSprite;
1719
import org.mvcexpress.MvcExpress;
@@ -54,10 +56,14 @@ public class SpriteModuleTest extends ModuleSprite {
5456
proxyMap.map(new SampleEmptyProxy("Named proxy"), SampleEmptyProxy, "namedSampleProxy");
5557
proxyMap.map(new SampleEmptyProxy("Named and interfaced proxy"), ISampleEmptyProxy, "namedSampleInterfacedProxy");
5658

57-
proxyMap.map(new SampleProxy());
58-
proxyMap.map(new SampleProxy(), ISampleProxy);
59-
proxyMap.map(new SampleProxy(), SampleProxy, "testType");
60-
proxyMap.map(new SampleProxy(), ISampleProxy, "interfaceProxy");
59+
var sameSampleProxy:SampleProxy = new SampleProxy()
60+
61+
proxyMap.unmap(SampleEmptyProxy);
62+
63+
proxyMap.map(sameSampleProxy);
64+
proxyMap.map(sameSampleProxy, ISampleProxy);
65+
proxyMap.map(sameSampleProxy, SampleProxy, "testType");
66+
proxyMap.map(sameSampleProxy, ISampleProxy, "interfaceProxy");
6167

6268
////////////////////////////
6369
// View
@@ -83,6 +89,11 @@ public class SpriteModuleTest extends ModuleSprite {
8389
commandMap.execute(SampleCommand, "single execute parameter");
8490
commandMap.execute(SampleCommand, new ComplexParams("complex execute parameters"));
8591

92+
93+
94+
// command with many injects
95+
commandMap.execute(ManyInjectsCommand);
96+
8697
////////////////////////////
8798
// comunication
8899
////////////////////////////
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.mindScriptAct.codeSnippets.controller {
2+
import com.mindScriptAct.codeSnippets.model.ISampleProxy;
3+
import com.mindScriptAct.codeSnippets.model.SampleProxy;
4+
import org.mvcexpress.mvc.Command;
5+
6+
/**
7+
* TODO:CLASS COMMENT
8+
* @author Raimundas Banevicius ([email protected])
9+
*/
10+
public class ManyInjectsCommand extends Command{
11+
12+
[Inject]
13+
public var sample:SampleProxy;
14+
15+
[Inject]
16+
public var sampleInterface:ISampleProxy;
17+
18+
[Inject(name='testType')]
19+
public var sampleNamed:SampleProxy;
20+
21+
[Inject(name='interfaceProxy')]
22+
public var sampleInterfaceNamed:ISampleProxy;
23+
24+
public function execute(blank:Object):void {
25+
trace( "ManyInjectsCommand.execute > blank : " + blank );
26+
}
27+
28+
}
29+
}

sampleProjects/com/mindScriptAct/codeSnippets/model/SampleProxy.as

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ public class SampleProxy extends Proxy implements ISampleProxy {
1111
////////////////////////////
1212
// geting proxies...
1313
////////////////////////////
14-
[Inject]
15-
public var sampleEmptyProxy:SampleEmptyProxy;
14+
//[Inject]
15+
//public var sampleEmptyProxy:SampleEmptyProxy;
1616

1717
[Inject]
1818
public var sampleEmptyProxyInterfaced:ISampleEmptyProxy;
1919

20-
[Inject(namespace = 'namedSampleEmptyProxy')]
20+
[Inject(name = 'namedSampleProxy')]
21+
public var sampleEmptyProxyNamed:SampleEmptyProxy;
22+
23+
[Inject(name = 'namedSampleInterfacedProxy')]
2124
public var sampleEmptyProxyInterfacedAndNamed:ISampleEmptyProxy;
2225

2326
public var testData:String = "someTestData";
@@ -26,6 +29,11 @@ public class SampleProxy extends Proxy implements ISampleProxy {
2629

2730
}
2831

32+
override protected function onRegister():void {
33+
trace( "SampleProxy.onRegister" );
34+
35+
}
36+
2937
public function sendTestMessage():void {
3038
sendMessage(Msg.TEST_DATA_MESSAGE, "sent message about proxy change...");
3139
}

src/org/mvcexpress/core/ProxyMap.as

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public class ProxyMap implements IProxyMap {
2929
/** dictionary of (Vector of PendingInject), it holds array of pending data with proxies and mediators that has pending injections, stored by needed injection key(className + inject name). */
3030
private var pendingInjectionsRegistry:Dictionary = new Dictionary(); /* of Vector.<PendingInject> by String */
3131

32-
/** all hosted proxy objects stored by key */
33-
static private var hostObjectRegistry:Dictionary = new Dictionary(); /* of HostedProxy by String */
34-
3532
/** all hostedProxy data stored by hosted Proxy objects stored */
3633
static private var hostedProxyRegistry:Dictionary = new Dictionary(); /* of HostedProxy by Proxy */
3734

@@ -66,24 +63,14 @@ public class ProxyMap implements IProxyMap {
6663
injectClass = proxyClass;
6764
}
6865

69-
var className:String = getQualifiedClassName(injectClass);
70-
if (!injectObjectRegistry[className + name]) {
71-
use namespace pureLegsCore;
66+
use namespace pureLegsCore;
67+
if (proxyObject.messenger == null) {
7268
proxyObject.messenger = messenger;
7369
proxyObject.setProxyMap(this);
70+
7471
// inject dependencies
7572
var isAllInjected:Boolean = injectStuff(proxyObject, proxyClass);
76-
// store proxy injection to other classes.
77-
injectObjectRegistry[className + name] = proxyObject;
78-
// check if there is no waiting hosted proxies with this key.
79-
if (hostObjectRegistry[className + name]) {
80-
// check if hosted object is pending..
81-
if (hostObjectRegistry[className + name].proxy) {
82-
if (hostObjectRegistry[className + name].proxy != proxyObject) {
83-
throw Error("Hosted proxy object is already mapped for:[injectClass:" + className + " name:" + name + "] only one hosted proxy can be mapped at any given time.");
84-
}
85-
}
86-
}
73+
8774
// check if there is no pending injection with this key.
8875
if (pendingInjectionsRegistry[className + name]) {
8976
injectPendingStuff(className + name, proxyObject);
@@ -92,9 +79,17 @@ public class ProxyMap implements IProxyMap {
9279
if (isAllInjected) {
9380
proxyObject.register();
9481
}
82+
83+
}
84+
85+
var className:String = getQualifiedClassName(injectClass);
86+
if (!injectObjectRegistry[className + name]) {
87+
// store proxy injection for other classes.
88+
injectObjectRegistry[className + name] = proxyObject;
9589
} else {
9690
throw Error("Proxy object class is already mapped.[injectClass:" + className + " name:" + name + "]");
9791
}
92+
9893
}
9994

10095
/**

src/org/mvcexpress/mvc/Proxy.as

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public class Proxy {
5959
if (!_isReady) {
6060
_isReady = true;
6161
onRegister();
62-
} else {
63-
throw Error("Proxy:" + this + " is already registered. You can register one proxy only once.");
6462
}
6563
}
6664

0 commit comments

Comments
 (0)