MiniSignal constructor.
Example
let mySignal = new MiniSignal();
let binding = mySignal.add(onSignal);
mySignal.dispatch('foo', 'bar');
mySignal.detach(binding);
Methods
-
add (fn, thisArg)MiniSignalBinding
-
Register a new listener.
Name Type Default Description fn
function Callback function.
thisArg
Mixed null optional The context of the callback function.
Returns:
Type Description MiniSignalBinding The MiniSignalBinding node that was added. -
detach (node)MiniSignal
-
Remove binding object.
Name Type Description node
MiniSignalBinding The binding node that will be removed.
Returns:
Type Description MiniSignal The instance on which this method was called. -
detachAll ()MiniSignal
-
Detach all listeners.
Returns:
Type Description MiniSignal The instance on which this method was called. -
Dispaches a signal to all registered listeners.
Returns:
Type Description Boolean Indication if we've emitted an event. -
handlers (exists)Array.<MiniSignalBinding> | Boolean
-
Return an array of attached MiniSignalBinding.
Name Type Default Description exists
Boolean false optional We only need to know if there are handlers.
Returns:
Type Description Array.<MiniSignalBinding> | Boolean Array of attached MiniSignalBinding or Boolean if called with exists = true -
Return true if node is a MiniSignalBinding attached to this MiniSignal
Name Type Description node
MiniSignalBinding Node to check.
Returns:
Type Description Boolean True if node is attache to mini-signal -
once (fn, thisArg)MiniSignalBinding
-
Register a new listener that will be executed only once.
Name Type Default Description fn
function Callback function.
thisArg
Mixed null optional The context of the callback function.
Returns:
Type Description MiniSignalBinding The MiniSignalBinding node that was added.