API-Version: 1.9

Signal

A Signal can be used to connect to certain browser events. For a list of available signals see signals. Signals are directly emitted on signals, this class is just a convience class to handle signals.

new Signal(name, callback) → {Signal}

Constructs a new Signal

Parameters:
Name Type Argument Description
name String

The event to connect to

callback Function <optional>

Callback that will be called when the signal is emitted. If omitted a callback must be passed to connect.

Source:
Returns:

A new Signal

Type
Signal
Example
 
function navigationCallback(wv, frame, request, response) 
{
     ...
}

// Create a new signal
var a = new Signal("navigation", navigationCallback);
var b = new Signal("navigation");

// The following patterns are equivalent
a.connect();

b.connect(navigationCallback);

// using the static method
var c = Signal.connect("navigation", navigationCallback);

// set the signal callback directly on signals 
// you won't get the constructed signal then
signals.onNavigation = navigationCallback;

Members

callback :Function

The callback that will be called when the signal is emitted, the context of the signal will be the signal itself (i.e. this refers to the connected Signal).

Source:
Example
 
function a() {
     io.print("Calling from a");
     this.callback = b;
}
function b() { 
     io.print("Calling from b");
     this.callback = a;
}
var s = new Signal("createTab", a).connect();

<readonly> connected :Boolean

Whether the signal is connected

Source:

<readonly> id :String

The id of the signal

Source:

<readonly> name :String

The name of the event

Source:

predicate :Function

A predicate function, the signal is only emitted if the predicate function returns true. The predicate function is called with the same arguments as the callback function

Since:
  • 1.6
Source:

Methods

<static> connect(name, callback, predicate) → {Signal}

Connects to an event

Parameters:
Name Type Argument Description
name String

The signal to connect to

callback Function

Callback that will be called when the signal is emitted.

predicate Function <optional>

A predicate function, see predicate

Source:
Returns:

A new Signal

Type
Signal
Example
function onCloseTab()
{
     ...
}
var s = Signal.connect("closeTab", onCloseTab);
// equivalent to 
var s = new Signal("closeTab", onCloseTab);
s.connect();

<static> connectAll(signals, callback)

Connect to more than one signal at once

Parameters:
Name Type Argument Description
signals Array

Array of signals

callback Function <optional>

Callbackfunction to connect to

Source:
Example
function onNavigation(wv, frame, request) 
{
     ...
}
function onNavigation2(wv, frame, request) 
{
     ...
}
var a = new Signal("navigation", onNavigation).connect();
var b = new Signal("navigation", onNavigation).connect();

// disconnect from all signals
var signals = Signal.disconnectAll(onNavigation);

// reconnect to all signals
Signal.connectAll(signals);

// Reconnect to all signals with a new callback
Signal.connectAll([a, b], onNavigation2);

<static> connectWebView(signal, callback)

Connects all webviews to a GObject signal.

Parameters:
Name Type Description
signal String

The signal name

callback GObject~connectCallback

A callback function the will be called when the signal is emitted, the arguments of the callback correspond to the GObject callback

Source:
Example
 
Signal.connectWebView("hovering-over-link", function(title, uri) {
     io.write("/tmp/hovered_sites", "a", uri + " " + title);
});

<static> disconnect(object) → {Signal}

Disconnects from an event.

Parameters:
Name Type Description
object Signal | Callback

Either a Signal or the callback of a signal If a callback is passed to this function and the same callback is connected multiple times only the first matching callback will be disconnected, to disconnect all matching callbacks call use Signal.disconnectAll

Source:
Returns:

The disconnected Signal

Type
Signal
Example
function callback(wv) 
{
     ...
}
var s = new Signal("loadStatus").connect(callback);

// Disconnect from the first matching callback
Signal.disconnect(callback);

Signal.disconnect(s);
// or equivalently
s.disconnect();

<static> disconnectAll(callback) → {Array}

Disconnect from all signals with matching callback function

Parameters:
Name Type Description
callback Function

A callback function

Source:
Returns:

Array of signals that were disconnected

Type
Array
Example
function onNavigation(wv, frame, request) 
{
     ...
}
var a = new Signal("navigation", onNavigation).connect();
var b = new Signal("navigation", onNavigation).connect();

Signals.disconnectAll(onNavigation);

<static> emit(signal, args) → {Boolean}

Emits a signal, can be used to implement custom signals.

Parameters:
Name Type Description
signal String

The signal name

args varargs

Arguments passed to the callback function of Signal.connect

Source:
Returns:

The overall return value of all callback function, if one callback function returns true the overall return value will be true

Type
Boolean

<static> once(name, callback, predicate) → {Signal}

Connects to a signal once. After the signal has been emitted once the callback function will not be called any longer.

Parameters:
Name Type Argument Description
name String

The signal to connect to

callback Function

Callback that will be called when the signal is emitted.

predicate Function <optional>

Predicate function, if defined the signal is only emitted and disconnected if the predicate function returns true.

Since:
  • 1.6
Source:
Returns:

A new Signal, calling connect on the returned signal will only connect once again.

Type
Signal

connect(callback, callback) → {Signal}

Connect this signal to the event

Parameters:
Name Type Argument Description
callback Function <optional>

The callback function to call, if no callback was passed to the constructor callback is mandatory.

callback Function <optional>

A predicate function, see predicate

Source:
Returns:

self

Type
Signal
Example
 
function a() {
     ...
}
function b() {
     ...
}
var signal = new Signal("navigation", a);
// connect to a
signal.connect();
// connect to b
signal.connect(b);

disconnect() → {Signal}

Disconnect this signal from the event, if disconnected the callback will no longer be called, to reconnect call signal.connect()

Source:
Returns:

self

Type
Signal
Example
var i = 0;
var signal = new Signal("navigation", function(wv, frame, request) {
     i++;
     if (i == 3)
         this.disconnect();
});

toggle() → {Boolean}

Toggles a signal, if it is connected it will be disconnected and vice versa

Source:
Returns:

true if the signal was connected, false otherwise

Type
Boolean