tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/4969-another-signals-vs-events-for-robotlegs-2Robotlegs: Discussion 2013-10-11T08:52:33Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/284860502013-08-28T17:35:17Z2013-08-28T17:35:18ZAnother Signals vs Events for Robotlegs 2<div><p>Hi,</p>
<p>There are quite a few posts discussing this but not many recent,
and in relation to the latest Robotlegs version. I am starting a
project where I am using RL2 and "currently" Signals.</p>
<p>In RL1 I used to use a nice and handy signalBus that I would
inject wherever I needed a signal. It seemed a bit dirty, but VERY
handy and quick. It seems like I can't use that method with the
latest SignalCommandMap so instead I go the cleaner way and just
inject the signals where required.</p>
<p>Problem is - I find myself injecting signals a lot instead of
injecting a signalBus once in some base mediator :)</p>
<p>So I started to look at how RL2 uses events for mapping and from
the examples it seems less boilerplate code is required. So
although Signals are super cool, it is kind of attracting to use
"out of the box" methods - especially if it requires less code.</p>
<p>So how are you all doing it? Events? Signals? Maybe both? Anyone
figured out how to make that signalBus work ? :)</p>
<p>Best,<br>
Sammi</p></div>Samúel Jónassontag:robotlegs.tenderapp.com,2009-10-18:Comment/284860502013-08-29T08:05:51Z2013-08-29T08:05:51ZAnother Signals vs Events for Robotlegs 2<div><p>Hi Sammi,</p>
<p>I think it is a matter of personal preference, really.</p>
<p>I like Signals a lot, but I prefer Events over Signals in large
projects.<br>
There are a few projects where I used a combination of both, which
also worked fine.</p>
<blockquote>
<p>Anyone figured out how to make that signalBus work ? :)</p>
</blockquote>
<p>Do you have an example of using a "signalBus" with RL1 that you
can share with us? What exactly doesn't work? Maybe you need to
build a SignalBusExtension?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/284860502013-08-29T09:51:45Z2013-08-29T09:51:46ZAnother Signals vs Events for Robotlegs 2<div><p>Yes, from what I have read it seems to be of personal
preference.</p>
<p>What does not work out of the box is to use an instance of a
signal for mapping signals. Mind you that I am no expert in
Robotlegs so maybe there is a way.</p>
<p>This is the API for the signalCommandMap extension. The map
method expects a signal Class.</p>
<p>
robotlegs.bender.extensions.signalCommandMap.api.​ISignalCommandMap.map(signalClass
: Class) : ICommandMapper</p>
<p>In RL1 I used to have a class called SignalBus that had signal
constants like below defined.</p>
<p>public const entryChanged : Signal = new Signal(EntryVO);<br>
public const entryRemoved : Signal = new Signal(Number);<br>
public const removeEntry : Signal = new Signal(Number);</p>
<p>Then I would inject an instance of that class where ever I
needed to use the signals.</p>
<p>[Inject] public var signalBus : SignalBus;</p>
<p>And when mapping them to commands I did this:</p>
<p>signalCommandMap.mapSignal(signalBus.entryChanged,
EntryChangedCommand);</p>
<p>Then when I wanted to listen for a signal I would do:</p>
<p>signalBus.entryChanged.add(onEntryChanged);</p>
<p>So the signal bus was just a way to reduce boilerplate code. I
did not have to create classes for the signals, just add a line to
the SignalBus.</p>
<p>I am sure you are right. If I wanted this "old and handy" way of
doing things in smaller apps I would most likely build a
SignalBusExtension. But since I haven't dug into how to do that I
think I will switch over to using events. Many seem to prefer that
for larger projectes.</p>
<p>A quick Google gave me this project that uses the same kind of
signalBus. <a href=
"https://github.com/eidiot/SlidePlayer/blob/master/src/net/eidiot/slide/signals/SignalBus.as">
https://github.com/eidiot/SlidePlayer/blob/master/src/net/eidiot/sl...</a></p>
<p>Best,<br>
Sammi</p></div>Samúel Jónassontag:robotlegs.tenderapp.com,2009-10-18:Comment/284860502013-08-29T14:12:46Z2013-08-29T14:12:46ZAnother Signals vs Events for Robotlegs 2<div><p>I've tried out the SignalBus you linked to. With just a few
changes SignalExecutorMap works with robotlegs 2, too.</p>
<p>These:</p>
<pre>
<code>signal = injectorForSignalInstance.instantiate(signalClass);
injectorForSignalInstance.mapValue(signalClass, signal);</code>
</pre>
<p>changed to:</p>
<pre>
<code>signal = injectorForSignalInstance.getInstance(signalClass);
injectorForSignalInstance.map(signalClass).toValue(signal);</code>
</pre>
<p>and this:</p>
<pre>
<code>var command:Object = injector.instantiate(commandClass);</code>
</pre>
<p>to</p>
<pre>
<code>var command:Object = injector.getOrCreateNewInstance(commandClass);</code>
</pre>
<p>Concerning the rl2 SignalCommandMapExtension, I suggest
contacting Ken Rogers (pixels4nickels) or creynders. Open an
issue/enhancement here:<br>
<a href=
"https://github.com/robotlegs/robotlegs-extensions-SignalCommandMap">
https://github.com/robotlegs/robotlegs-extensions-SignalCommandMap</a></p>
<p>I'll add Ken and creynders to the watchers list for this thread,
so they'll get notified and maybe they'll respond...</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/284860502013-08-29T14:17:02Z2013-08-29T14:17:03ZAnother Signals vs Events for Robotlegs 2<div><p>Nice Ondina,</p>
<p>Thank you for looking into this. Much appreciated!</p>
<p>Best,<br>
Sammi</p></div>Samúel Jónasson