new Channel(targetopt)
- Source:
This constructor function creates a new message channel. You can invoke the constructor without passing any arguments (using the `new` keyword if you want to) and a new channel object is created for you. You can also call `Channel` as a function and pass in an object, that you want to transform into a message channel. A third option would be to pass the constructor a string, which creates a named channel.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
Object |
<optional> |
An object that is to be transormed into an event channel. If no object is given, a new one is being created. |
Members
(inner) events
- Source:
The `events` variable saves the names of registered events and associates those names with arrays of callback functions to be called, when the event is triggered.
Methods
emit(type) → {Object}
- Source:
Calling this method triggers the specified event and will result in all registered callbacks being executed. All arguments that get passed to `emit` after the event name are provided as arguments to each callback function.
You should not rely on the order in which the callbacks are being invoked.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | The name of the event to be triggered. Any additional arguments will be passed to the callback function. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
emitAsync(type) → {Object}
- Source:
This method works like `emit` but guarantees asynchronous execution of all callbacks for this event.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | The name of the event to be triggered. Any additional arguments will be passed to the callback function. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
emitSync(type) → {Object}
- Source:
This method works like `emit` but guarantees synchronous execution of all callbacks for this event.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | The name of the event to be triggered. Any additional arguments will be passed to the callback function. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
isLocked(typeopt) → {Object}
- Source:
Returns whether the channel or a specifc event type on this channel is locked.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
Optional: The name of the event whose status is being requested. If no event type is specified, the whole channel's status will be returned. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
isSilenced(typeopt, funcopt) → {Object}
- Source:
Returns whether the channel or an event type or a specific callback is silenced.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
Optional: The name of the event whose status is being requested. If no event type is specified, the whole channel's status will be returned. |
func |
function |
<optional> |
Optional: The function whose status is being requested. If no function is specified the whole event type's status will be returned. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
lock(typeopt) → {Object}
- Source:
`Lock` prevents new callbacks from being registered. Similar to silencing, you can either lock an entire channel by calling `lock` with no arguments or lock a single event type by providing `lock` with that event's type.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
The name of the event to which no new callbacks shall be registerd. If no event name is specified, the whole channel will be locked. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
off(typeopt, funcopt) → {Object}
- Source:
Removes event listeners. Functions will no longer be invoked when the specified event is triggered. You can pass in the event name and a function reference to remove a specific function. If you just provide the first parameter, all callbacks for the given event type are removed. You can remove all event handlers from all events on this channel, by calling `off` without any arguments.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
The event name of the callbacks to be removed. |
func |
function |
<optional> |
The callback function to be removed. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
on(type, func, asyncopt) → {Object}
- Source:
With this method you can register callbacks to be executed when a certain event is triggered. You have to pass in the event name and the callback function, but you can optionally provide a third argument. This third argument should be an object which is then used as the callback function's `this` (context injection). The fourth parameter of the `on` function is a boolean that gives a preference on whether the callback function shall be executed asynchronously. Note, however, that asynchronous execution is not guarenteed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String | The name of the event is specified by a string. It doesn't matter, whether this event name already exists or not. | |
func |
function | The function to be called, when the event is triggered. | |
async |
boolean |
<optional> |
A preference regarding whether this callback shall the executed asynchronously. (Not a guarantee!) |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
once(type, func, asyncopt) → {Object}
- Source:
This method does the same as `on` but it registers a callback that will only be executed once.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String | The name of the event is specified by a string. It doesn't matter, whether this event name already exists or not. | |
func |
function | The function to be called, when the event is triggered. | |
async |
boolean |
<optional> |
A preference regarding whether this callback shall the executed asynchronously. (Not a guarantee!) |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
reset(typeopt) → {Object}
- Source:
This lets you remove all event listeners from the message channel or from a specified event type.
(Also sets `silenced` and `locked` to `false`).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
Optional: The name of the event whose callbacks shall be removed. If no event type is given, the whole channel will be reset. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
silence(typeopt, funcopt) → {Object}
- Source:
The `silence` method prevents any new messages from being sent over the message channel. Affects the entire channel or specific events or even specific callbacks.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
The name of the event that is meant to be silenced. If no event type is specified, the whole channel will be silenced. |
func |
function |
<optional> |
The function that is no longer to be executed when the event is triggered. If no function is specified, the whole event type will be silenced. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
unlock(typeopt) → {Object}
- Source:
`Unlock` allows callbacks from being added to a channel after it was locked. You can unlock a locked channel or just a single event type by using the optional parameter.
Unlocking a channel that was already unlocked does not throw but instead just does nothing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
The name of the event that shall accept new callbacks again. If no event type is given, the whole channel will be unlocked. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object
unsilence(typeopt, funcopt) → {Object}
- Source:
With this method you can enable message sending after it was disable using `silence`.
If you unsilence a single event, but the entire channel is still silenced, triggering the event will still have no effect.
Unsilencing a channel that was not silenced does not throw but instead just does nothing.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
The name of the event that is meant to be unsilenced. If no event type is given, the whole channel well be unlocked. |
func |
function |
<optional> |
The function that shall be executed again, after being silenced. If no function is given, the whole event type will be unsilenced. |
Returns:
The channel object. Or rather: 'this'. So be careful with rebinding 'this'.
- Type
- Object