Passing null as payload in signal to command

creynders's Avatar


15 Oct, 2010 09:51 AM

I'm getting the 'Injector is missing a rule' error for my command if I try to pass null as a payload in a signal to a command.
Is this impossible to do?
That would be quite a pity, I think...

  1. 1 Posted by Stray on 15 Oct, 2010 10:06 AM

    Stray's Avatar

    I was going to say: Use the null object pattern. This is what it's for - and it's much more secure and descriptive than testing for null which should be a diagnostic/defensive tool and not something you code to.


    If your data type is SomeObject create an extension called NullSomeObject

    pass new NullSomeObject() to your dispatch and then test for this (I'm assuming you're doing some sort of null test further on) instead.

    but... actually your mappings might not work unless you also do some other trickery.

    I'm just doing some tests to verify the behaviour.

  2. 2 Posted by Stray on 15 Oct, 2010 10:10 AM

    Stray's Avatar

    And I meant to say - obviously the injector can't possibly do the type matching for a null object - there's nothing there - hence why it doesn't work. This is one of the reasons that using 'null' in your code isn't the optimum solution.

  3. Support Staff 3 Posted by creynders on 15 Oct, 2010 10:39 AM

    creynders's Avatar

    how 'bout adding a isNull property to my VO?
    Or a isNull parameter to my signal?

    mySignal.dispatch( true, vo ); //sending 'null' object

    I'm thinking about how I could do this using a NullSomeObject that extens SomeObject, but I can't seem to figure out how it could work since subclasses aren't recognized during injection.

    This is one of the reasons that using 'null' in your code isn't the optimum solution.

    What would be an optimum solution?

  4. 4 Posted by Stray on 15 Oct, 2010 10:49 AM

    Stray's Avatar

    I'm just checking out how to implement the NullObject pattern with injection - as it's something that is generally relevant.

    Shaun, Joel - any thoughts?

    I'd be interested to know why the signal is dispatching if the payload is null... or is only some of the payload null?

  5. Support Staff 5 Posted by creynders on 15 Oct, 2010 11:08 AM

    creynders's Avatar

    Only some of the payload was null.

  6. 6 Posted by Stray on 15 Oct, 2010 11:14 AM

    Stray's Avatar

    Hi creynders,

    having looked at the updated source, the NullObject pattern will fit fine into SignalCommandMap.

    The newest version uses the Signal.valueClasses to do the mappings, not the object constructor.

    In this way, subclass mappings work fine. So - you can have Signal/Command that requires Sprite as the first argument, and pass a MovieClip and that will work fine.

    So as long as NullThing extends Thing it will work ok.


    You may wish to grab the source rather than the swc incase the swc is out of date.


  7. Support Staff 7 Posted by creynders on 15 Oct, 2010 11:21 AM

    creynders's Avatar

    wow, that opens up a lot of possibilities...!

  8. 8 Posted by Stray on 15 Oct, 2010 11:34 AM

    Stray's Avatar

    This is only in the SignalCommandMap - but shows another strength of Signals - that you can find out, at runtime, what types are expected to be sent on the Signal and then prepare accordingly!

  9. Support Staff 9 Posted by creynders on 15 Oct, 2010 12:20 PM

    creynders's Avatar

    Just implemented the null object pattern into my current project and it works like a charm.
    Thanks a lot!

  10. 10 Posted by Stray on 15 Oct, 2010 12:32 PM

    Stray's Avatar

    Nice one!

    (Thanks to Joel, Robert et al for making the SignalCommandMap able to do this).


  11. creynders closed this discussion on 24 Oct, 2010 01:03 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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