Overview
Signals are highly scalable and lightweight alternative to Events.
msignal.Signal
is a type safe port of Robert Penner’s AS3 Signals leveraging Haxe generics.
Benefits:
- Avoids costly native event bubbling on different platforms (e.g. HTML DOM events) that impact performance
- Type safe signature for dispatching and observer handlers
- Typing excluded from output (lighter, cleaner code without compromising integrity)
You can download some examples of msignal usage here.
Importing
All required classes can be imported through msignal.Signal
import msignal
Basic usage
var signal = new Signal0();signaltrace("signal dispatched!"); })signal
Extending
class MySignal extends Signal2<String, Int>{ public function new() { super(); }}
Typed parameters
var signal = new Signal1<String>();signal // error: Int -> Void should be String -> Voidsignal// error Bool should be String
Numbers of parameters:
var signal0 = new Signal0();var signal1 = new Signal1<String>();var signal2 = new Signal2<String, String>();
Slots:
var signal = new Signal0();var slot = signalslot= false;signal // slot will not dispatch
Slot parameters:
var signal2 = new Signal2<String, String>();var slot = signals2){ trace+ " " + s2); });slot= "Goodbye";signal"Mr Bond"); // traces: Goodbye Mr Bond