Injecting a uint into a signal command
Hi
I am loving Robotlegs and signals - they seem to be a very natural fit. However I have run into an issue whilst trying to inject a uint - the mapping looks like this
`signalCommandMap.mapSignalClass(LoadCollection, LoadCollectionCommand);`
the command looks like this
`package org.fwg.collectionviewer.controller {
import org.fwg.collectionviewer.comms.IGalleryService;
import org.robotlegs.mvcs.Command;
public class LoadCollectionCommand extends Command
{
[Inject]
public var galleryService:IGalleryService;
[Inject]
public var collectionId:uint;
public override function execute():void
{
galleryService.requestCollection(collectionId);
}
}
}`
But when I do something like
loadCollection.dispatch(227)
I get the following error
Error: Injector is missing a rule to handle injection into
target [object LoadCollectionCommand]. Target dependency:
uint
Any clues?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Stray on 21 Mar, 2010 03:41 PM
Hi Conrad,
What does the LoadCollection signal look like?
I'm assuming it does
super(uint) in the constructor?
2 Posted by marteinn on 21 Mar, 2010 04:37 PM
I encountered the same problem just the other day and soon realized that switching from int to Number solved the issue. Its not the perfect solution but it works.
Cheers
/ M
Support Staff 3 Posted by Till Schneidere... on 21 Mar, 2010 06:13 PM
Conrad and marteinn,
I'm not entirely sure, but I think that's caused by a bug in
SwiftSuspenders that misinterprets ints and uints as numbers when
mapping values. This should be resolved in the current beta of
SwiftSuspenders 1.5.
If you want to try using that beta version (which is very stable and
should have production quality IMO), you can do so by downloading it
from the SwiftSuspenders downloads
page and
putting the contained SWC file into your project's libs folder.
Support Staff 4 Posted by Joel Hooks on 21 Mar, 2010 06:14 PM
Hey Till, there is an issue with Vectors too along the same lines...
5 Posted by Conrad Winchest... on 21 Mar, 2010 06:16 PM
Yep - the signal does have super(uint) in it, and switching to Number does inded make it work - will have to look at the source code of SwiftSuspenders as that is where the error occurs.
Support Staff 6 Posted by Till Schneidere... on 21 Mar, 2010 06:55 PM
As I said, the SwiftSuspenders 1.5 shouldn't have that issue as of
beta 4 (I think). Jon Toland made me aware of the issue and kindly
provided a patch that resolved it, too.
Vectors are another issue, unfortunately. While I could add an
exception for them, too, that would make SwiftSuspenders incompatible
with Flash Player 9. Currently, I think there are still too many
projects that don't really require anything only Flash Player 10
provides and should thus target 9.
An option would be to add preprocessing rules to the source code and
provide SWCs for FP 9 and 10. Patches for that are very welcome - I
won't be able to implement that myself for at least the next couple of
weeks.
7 Posted by Stray on 21 Mar, 2010 07:14 PM
On the Vector issue, I'm working around it by using a wrapper class on the occasional Vector. I prefer not to inject the base classes but one of my signal command mappings does need it.
I hadn't really sussed out why it wasn't working - just that it wasn't, and the first work around I tried happened to work so I stuck with it.
8 Posted by Conrad Winchest... on 21 Mar, 2010 07:17 PM
OK,
I built Robot Legs againt the 1.5 beta of Swift suspenders - A lot of tests fail, but the resulting swf is usable (?) and when I run my application I get the same error - probably something fishy going on - am going with Number hack for the moment.
Conrad
9 Posted by Daniel on 30 Apr, 2010 01:11 AM
The problem still exists in 1.5 beta. I'm trying to use a DisplayObject as the payload in my signal and I get the same error. If I change the type to String. Everything works fine and my command gets instantiated and executed.
Support Staff 10 Posted by Till Schneidere... on 30 Apr, 2010 10:33 AM
That sounds like it's a different problem. Maybe you're using
DisplayObject as the type to be injected into your signal when the
actual mapped payload is a Sprite or MovieClip?
Unfortunately, it's not possible to efficiently implement automated DI
for injecting sub-types of the requested type (in this example,
letting Sprite, Shape or MovieClip mappings satisfy a request for
DisplayObject), so you have to match your mappings to your injection
points exactly.
If none of the above fits your problem, maybe you could attach a
reduced test-case exposing your problem to the ticket?
11 Posted by Daniel on 30 Apr, 2010 04:55 PM
I wasn't aware of the limitation with DI. Let me know if I should open a ticket for the following scenario
I'm use the popup manager to display a popup from within a command and want to send the parent displayobject via signal to command. So where I dispatch the signal,
// where I dispatch I have mySignal.dispatch( myComponent as DisplayObject);
// signal command [Inject] public var parent:DisplayObject;
As a workaround, I used the Application object to get the root display object so no longer needed to pass in the parent display object, but I thought this should still work.
Support Staff 12 Posted by Till Schneidere... on 02 May, 2010 04:14 PM
To be honest, I'm not that well acquainted with the signals extension,
so I'm not too sure what's going on behind the scenes between your
"mySignal.dispatch" and the command creation.
Still: If I understand correctly, the SignalCommandMap creates a
temporary injector mapping for all payload items of the signal, so
that these items can be injected into the then created command, right?
If so, there's no need to open a ticket: It's simply not feasible to
create temporary mappings for anything but the concrete type of the
payload. In cases where you're creating the injector mappings
yourself, you can easily map a super type to a sub type value (e.g.
injector.mapValue(DisplayObject, new Sprite())), but in cases where
the system creates the mappings for you, as is the case in the
SignalCommandMap, it can't know which type you want to have mapped, so
it has to use the concrete type. (See
http://github.com/darscan/signals-extensions-CommandSignal/blob/master/src/org/robotlegs/base/SignalCommandMap.as#L93
for how this works).
The only thing you can do in this case (apart from working around the
issue altogether as you did for now) is to change your injection:
[Inject]
public var parent:Sprite;
13 Posted by Conrad Winchest... on 05 Jun, 2010 04:28 PM
Woah! I fixed the uint bug and know what is causing it and it isn't very nice :-( This bug affected ints as well and is caused by what I can only consider to be a bug in the flash player.
It turns out that if you have
var a:uint=0;
OR
var a:int=0;
then a.constructor is Number - this is absolutely wrong :-(
SignalCommandMap then fails and need the following change
Then all is well
14 Posted by Philipp on 05 Jun, 2010 06:21 PM
Hmm, so this seems to be still valid:
http://blog.andre-michelle.com/2007/weird_behavior_of_numbers_in_as3/
15 Posted by Conrad Winchest... on 06 Jun, 2010 08:03 AM
STOP!!! I was wrong, this does not fix the problem. It turns out that the AVM2 treats Numbers, uints and ints in a very strange way and you can never be sure you have what you want. So I have another fix that does seem to work. You need to use the valueClasses array from the Signal rather than getConstructorForObject in order to map the injection. the code looks like this
protected function routeSignalToCommand(signal:ISignal, valueObjects:Array, commandClass:Class, oneshot:Boolean):void
{
This seems to work as you would expect.
I have offered this to Joel as a patch, along with some tests. He might include it in the official release of SignalCommandMap
Support Staff 16 Posted by Joel Hooks on 06 Jun, 2010 08:06 AM
Looks good to me :>
As long as the tests pass I love seeing code getting nuked.
17 Posted by Conrad Winchest... on 07 Jun, 2010 05:32 AM
So, just to confirm, the current version of SignalCommandMap now supports injection of ints and uints into commands.
Stray closed this discussion on 10 Feb, 2011 04:11 PM.