StrangeIoC  0.6.0
The IoC/Binding Framework for Unity3D and C#
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public Member Functions | Events | List of all members
strange.extensions.signal.impl.Signal Class Reference

Base concrete form for a Signal with no parameters. More...

Inheritance diagram for strange.extensions.signal.impl.Signal:
strange.extensions.signal.impl.BaseSignal strange.extensions.signal.api.IBaseSignal

Public Member Functions

void AddListener (Action callback)
 
void AddOnce (Action callback)
 
void RemoveListener (Action callback)
 
override List< Type > GetTypes ()
 
void Dispatch ()
 
- Public Member Functions inherited from strange.extensions.signal.impl.BaseSignal
void Dispatch (object[] args)
 
void AddListener (Action< IBaseSignal, object[]> callback)
 
void AddOnce (Action< IBaseSignal, object[]> callback)
 
void RemoveListener (Action< IBaseSignal, object[]> callback)
 
- Public Member Functions inherited from strange.extensions.signal.api.IBaseSignal
void Dispatch (object[] args)
 Instruct a Signal to call on all its registered listeners.
 
void AddListener (Action< IBaseSignal, object[]> callback)
 Attach a callback to this Signal The callback parameters must match the Types and order which were originally assigned to the Signal on its creation.
 
void AddOnce (Action< IBaseSignal, object[]> callback)
 Attach a callback to this Signal for the duration of exactly one Dispatch The callback parameters must match the Types and order which were originally assigned to the Signal on its creation, and the callback will be removed immediately after the Signal dispatches.
 
void RemoveListener (Action< IBaseSignal, object[]> callback)
 Remove a callback from this Signal.
 
List< Type > GetTypes ()
 Returns a List<System.Type> representing the Types bindable to this Signal.
 

Events

Action Listener = delegate { }
 
Action OnceListener = delegate { }
 
- Events inherited from strange.extensions.signal.impl.BaseSignal
Action< IBaseSignal, object[]> BaseListener = delegate { }
 The delegate for repeating listeners.
 
Action< IBaseSignal, object[]> OnceBaseListener = delegate { }
 The delegate for one-off listeners.
 

Detailed Description

Base concrete form for a Signal with no parameters.

This is actually a series of classes defining the Base concrete form for all Signals.

Signals are a type-safe approach to communication that essentially replace the standard EventDispatcher model. Signals can be injected/mapped just like any other object – as Singletons, as instances, or as values. Signals can even be mapped across Contexts to provide an effective and type-safe way of communicating between the parts of your application.

Signals in Strange use the Action Class as the underlying mechanism for type safety. Unity's C# implementation currently allows up to FOUR parameters in an Action, therefore SIGNALS ARE LIMITED TO FOUR PARAMETERS. If you require more than four, consider creating a value object to hold additional values.

Examples:

BASIC SIGNAL CREATION/DISPATCH Create a new signal Signal signalWithNoParameters = new Signal(); Add a listener signalWithNoParameters.AddListener(callbackWithNoParameters); This would throw a compile-time error signalWithNoParameters.AddListener(callbackWithOneParameter); Dispatch signalWithNoParameters.Dispatch(); Remove the listener signalWithNoParameters.RemoveListener(callbackWithNoParameters);

SIGNAL WITH PARAMETERS Create a new signal with two parameters Signal<int, string> signal = new Signal<int, string>(); Add a listener signal.AddListener(callbackWithParamsIntAndString); Add a listener for the duration of precisely one Dispatch signal.AddOnce(anotherCallbackWithParamsIntAndString); These all throw compile-time errors signal.AddListener(callbackWithParamsStringAndInt); signal.AddListener(callbackWithOneParameter); signal.AddListener(callbackWithNoParameters); Dispatch signal.Dispatch(42, "zaphod"); Remove the first listener. The listener added by AddOnce has been automatically removed. signal.RemoveListener(callbackWithParamsIntAndString);

See Also
strange.extensions.signal.api.IBaseSignal
strange.extensions.signal.impl.BasrSignal

The documentation for this class was generated from the following file: