Triggering a Robotlegs Command via a Signal

74 views
Skip to first unread message

Joel Hooks

unread,
Jan 16, 2010, 2:32:12 PM1/16/10
to as3-signals
I'm a bit stuck on this bit. I want to use a command, but I can't
grasp how to map a command to a signal. Is that even possible right
now? NativeSignal?

Robert Penner

unread,
Jan 16, 2010, 6:35:08 PM1/16/10
to as3-s...@googlegroups.com
What the command really needs is the value object. Wrapping the VO in
a custom Event is boilerplate required by EventDispatcher.

A Signal is essentially a dispatcher--one that can send your value
object without wrapping it in an Event. So you wouldn't map between
the Signal and the command. You'd map between the VO and the command.

How that mapping is defined is an interesting question. If each VO
class had only one relevant command, you could map VO class to command
class easily. However, if there are multiple commands, how do you
route the VO to the desired one? In Robotlegs' CommandMap, Event.type
is the router. But because Signals are so flexible, they don't impose
a convention like Event.type.

You can still dispatch Event instances through a Signal if you like.
The only issue is that the .target and .currentTarget won't be set;
only EventDispatcher can change those.

I'm glad you brought this up. I don't have answers yet but you've got
me thinking about it. It's probably a puzzle you'll end up solving,
and I'm happy to provide information on how to use Signals.

Robert

Joel Hooks

unread,
Jan 16, 2010, 6:52:51 PM1/16/10
to as3-s...@googlegroups.com
My first inclination is a SignalCommandMap to map typed Signals to
executable commands.

signalCommandMap.mapSignal(MySignal, SomeCommand);

I dig commands in that they are such a nice way to encapsulate
business logic.


On Jan 16, 2010, at 5:35 PM, Robert Penner <in...@robertpenner.com>
wrote:

Robert Penner

unread,
Jan 16, 2010, 7:58:11 PM1/16/10
to as3-s...@googlegroups.com
Ok, I just finished reading through your blog post:

http://joelhooks.com/2010/01/16/robotlegs-image-gallery-example-using-as3-signals-and-the-presentation-model/

What you've done with Signals is really creative and
thought-provoking, akin to Richard Lord's example:

http://www.richardlord.net/blog/flexcaster-smartysignals

In December, I briefly thought, "What about injecting Signals in my
Robotlegs app?" But I dismissed the idea because I was using normal
Signals and I didn't want to create named injections for them. I
didn't think of using Signal subclasses to solve this, which you did.

This month, I've been using a few Signals to communicate between
Mediators and was wondering if I should make a "SignalBus". It could
be merely a place to store Signals that bridge between application
actors.

But what you're doing is storing Signal subclasses in the Robotlegs
Injector. Then you inject them wherever needed. It's like you exploded
the Context EventDispatcher and its shrapnel is embedded all over the
place (in a good way).

Ok, here's something that may help you with mapping Signals to commands:

public interface ISignal
{
/**
* An optional array of classes defining the types of parameters sent
to listeners.
*/
function get valueClasses():Array;


Man, I wish we had generics.

Joel Hooks

unread,
Jan 16, 2010, 8:28:11 PM1/16/10
to as3-s...@googlegroups.com
On Jan 16, 2010, at 6:58 PM, Robert Penner wrote:

> function get valueClasses():Array;

Ya, I am passing in the value classes in the super() of my extensions.

http://github.com/joelhooks/robotlegs-examples-ImageGalleryPM/blob/master/src/org/robotlegs/examples/imagegallery/signals/GalleryImageSelectedSignal.as#L10

It works really well.

I think a SignalCommandMap will be a really simple mechanism. I'm going to flesh it out tomorrow. Good times!

Reply all
Reply to author
Forward
0 new messages