Skip to content

Commit cb5438d

Browse files
committed
CommandTriggerBuilder should request new reflection process for module and injector annotated properties.
1 parent 897ea81 commit cb5438d

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/hex/control/trigger/CommandTriggerBuilder.hx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ class CommandTriggerBuilder
3434

3535
macro static public function build() : Array<Field>
3636
{
37-
var fields = Context.getBuildFields();
37+
var fields = Context.getBuildFields();
3838

3939
if ( Context.getLocalClass().get().isInterface )
4040
{
4141
return fields;
4242
}
4343

44-
var CommandClassType = MacroUtil.getClassType( Type.getClassName( Command ) );
45-
var MacroCommandClassType = MacroUtil.getClassType( Type.getClassName( MacroCommand ) );
46-
var IContextModuleClassType = MacroUtil.getClassType( Type.getClassName( IContextModule ) );
44+
var CommandClassType = MacroUtil.getClassType( Type.getClassName( Command ) );
45+
var MacroCommandClassType = MacroUtil.getClassType( Type.getClassName( MacroCommand ) );
46+
var IContextModuleClassType = MacroUtil.getClassType( Type.getClassName( IContextModule ) );
4747
var IDependencyInjectorClassType = MacroUtil.getClassType( Type.getClassName( IDependencyInjector ) );
4848

4949
for ( f in fields )
@@ -107,7 +107,6 @@ class CommandTriggerBuilder
107107
"' annotation) to '" + f.name + "' method in '" + className + "' class", command.pos );
108108
}
109109

110-
111110
var typePath = MacroUtil.getTypePath( command.name, command.pos );
112111

113112
if ( !MacroUtil.isSubClassOf( MacroUtil.getClassType( command.name ), CommandClassType ) )
@@ -116,7 +115,6 @@ class CommandTriggerBuilder
116115
"' annotation), but it doesn't extend '" + CommandClassType.module + "' class", command.pos );
117116
}
118117

119-
120118
var arguments :Array<Expr> = [];
121119
for ( arg in func.args )
122120
{
@@ -139,7 +137,6 @@ class CommandTriggerBuilder
139137
];
140138
arguments.push( { expr: EObjectDecl( fields ), pos: Context.currentPos() } );
141139
}
142-
143140
}
144141

145142
var className = MacroUtil.getPack( command.name );
@@ -158,7 +155,7 @@ class CommandTriggerBuilder
158155
this.injector.mapClassNameToValue( 'Array<hex.control.payload.ExecutionPayload>', payloads );
159156

160157
hex.control.payload.PayloadUtil.mapPayload( payloads, this.injector );
161-
var command = this.injector.getOrCreateNewInstance( $p { className } );
158+
var command = this.injector.instantiateUnmapped( $p { className } );
162159
hex.control.payload.PayloadUtil.unmapPayload( payloads, this.injector );
163160

164161
command.setOwner( this.module );
@@ -173,22 +170,20 @@ class CommandTriggerBuilder
173170
{
174171
func.expr = macro
175172
{
176-
var injections : Array<{value:Dynamic, className:String, mapName:String}> = $a { arguments };
173+
var injections : Array<{value: Dynamic, className: String, mapName: String}> = $a { arguments };
177174
var payloads = [];
178175
for ( injected in injections )
179176
{
180177
payloads.push( new hex.control.payload.ExecutionPayload( injected.value, null, injected.mapName ).withClassName( injected.className ) );
181178
}
182179

183180
hex.control.payload.PayloadUtil.mapPayload( payloads, this.injector );
184-
var command = this.injector.getOrCreateNewInstance( $p { className } );
181+
var command = this.injector.instantiateUnmapped( $p { className } );
185182
hex.control.payload.PayloadUtil.unmapPayload( payloads, this.injector );
186183

187184
command.setOwner( this.module );
188185
command.execute();
189-
190-
191-
186+
192187
return command;
193188
};
194189
}
@@ -220,7 +215,7 @@ class CommandTriggerBuilder
220215
pos: Context.currentPos()
221216
});
222217

223-
return fields;
218+
return hex.di.annotation.AnnotationTransformer.reflect( macro hex.di.IInjectorContainer, fields );
224219
}
225220

226221
static function _searchForInjection( expr : Expr ) : Void

test/hex/control/trigger/CommandTriggerTest.hx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ class CommandTriggerTest
118118
vos[ 6 ] = [ 'hello', 'world' ];
119119
vos[ 7 ] = [ 'hello' => 'world' ];
120120
vos[ 8 ] = Date.now();
121+
vos[ 9 ] = MockEnum.TEST;
121122

122123
var result = '';
123-
controller.doSomething( vos[ 0 ], vos[ 1 ], vos[ 2 ], vos[ 3 ], vos[ 4 ], vos[ 5 ], vos[ 6 ], vos[ 7 ], [3, 4], vos[ 8 ] )
124-
.onComplete( function(r) result = r );
124+
controller.doSomething( vos[ 0 ], vos[ 1 ], vos[ 2 ], vos[ 3 ], vos[ 4 ], vos[ 5 ], vos[ 6 ], vos[ 7 ], [3, 4], vos[ 8 ], vos[ 9 ] )
125+
.onComplete( function(r) { result = r; } );
125126

126127
Assert.equals( 'string2', result );
127128

@@ -135,6 +136,7 @@ class CommandTriggerTest
135136
Assert.equals( vos[ 6 ], mo.pArray );
136137
Assert.equals( vos[ 7 ], mo.pStringMap );
137138
Assert.equals( vos[ 8 ], mo.pDate );
139+
Assert.equals( vos[ 9 ], mo.pEnum );
138140

139141
//
140142
var cmd = MockCommand.command;
@@ -147,6 +149,7 @@ class CommandTriggerTest
147149
Assert.equals( vos[ 6 ], cmd.pArray );
148150
Assert.equals( vos[ 7 ], cmd.pStringMap );
149151
Assert.equals( vos[ 8 ], cmd.pDate );
152+
Assert.equals( vos[ 9 ], cmd.pEnum );
150153

151154
//
152155
var acmd = AnotherMockCommand.command;
@@ -159,5 +162,6 @@ class CommandTriggerTest
159162
Assert.equals( vos[ 6 ], acmd.pArray );
160163
Assert.equals( vos[ 7 ], acmd.pStringMap );
161164
Assert.equals( vos[ 8 ], acmd.pDate );
165+
Assert.equals( vos[ 9 ], acmd.pEnum );
162166
}
163167
}

test/hex/control/trigger/mock/MockMacroController.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hex.control.trigger.mock;
22

33
import hex.collection.ILocator;
4+
import hex.control.MockEnum;
45
import hex.control.async.Expect;
56

67
/**
@@ -12,8 +13,6 @@ class MockMacroController
1213
{
1314
public function new(){}
1415

15-
16-
1716
@Map( hex.control.trigger.mock.MockMacroCommand )
1817
public function doSomething
1918
(
@@ -26,7 +25,8 @@ class MockMacroController
2625
a : Array<String>,
2726
@Type( 'Map<String, String>' ) m : Map<Dynamic, Dynamic>,
2827
@Ignore ai : Array<Int>,
29-
d : Date
28+
d : Date,
29+
me : MockEnum
3030
) : Expect<String>;
3131

3232
public function sum( a : Int, b : Int ) : Int

0 commit comments

Comments
 (0)