Navigation Menu

Skip to content

pederan/Robotlegs-signals-signalMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SignalMap

Just an idea that I wanted to try out after reading a discussion between @jhooks, @matanube and @mark_star about whether or not to use a signal bus in Robotlegs. Wanted to make a create a helper class for quicker adding and mapping new signals to the application. It should be noted that subclassing or using a signal bus is perfectly fine, but that I wanted make a more automatic way to achieve the same thing.

Rationale

When using as3 signals in Robotlegs you can either subclass the Signal class and map, or use a signal bus. One of the disadvantage of subclassing the Signal class for all your custom signals is that you may need to manually create and map many classes. On the other hand, using a signalbus, breaks the idea of dependency injection where you only should provide your application tiers with what they need. As @jhooks states: “monolithic controllers tend to break SRP and are generally prone to abuse exposing too much to too many actors.”

The SignalMap provides a central that creates and maps the signals for you.

Usage

Create a new instance of SignalMap in your main context or your command setup class (map it if you need to access the signal map in other application tiers)

var signalMap:ISignalMap = new SignalMap(injector);
injector.mapValue(ISignalMap, signalMap); //map if you need to access it later for creating more signals

Start creating your signals using the signalMap (you can pass as many parameters as you need). The signals get mapped in the SignalMap.

var signal:Signal = signalMap.createSignal(nameOfSignal:String, parameters);

You can also create and map signals to trigger commands using the SignalCommandMap

var actionSignal:Signal = signalMap.createSignal("actionSignal");
signalCommandMap.mapSignal(actionSignal, ActionCommand);

Then to trigger the command you can dispatch the signal:

actionSignal.dispatch();

In your mediator, command or actor inject the signal you need by using the named injection option. The name needs to be the same as used when creating the signal.

[Inject(name="nameOfSignal")]
public var signalName:Signal;

Then dispatch the signal somewhere in your code

signalName.dispatch(signalParameters)

See the example files for a working example.

Just to note: The creation and injection of the SignalMap class should probably be baked into the framework so that you don’t have to initialize and map it. Wanted to test before doing more work.

Feedback welcomed.

About

Create and map new signals on the fly

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published