Class: TypedSubscription

TypedSubscription

new TypedSubscription()

Provides a stream of topic events, specific to the topic selector that this TypedSubscription was created for, with topic values provided as instances of the associated DataType.

TypedSubscription inherits all functions defined on Stream.

Properties:
Name Type Description
selector String The selector this subscription was created for
Fires:
Examples
// Create a typed subscription
session.subscribe('foo').asType(datatype).on('open', function(subscription) {
    // Get subscription instance
});
// Subscribe to a single topic and receive values
session.subscribe('foo').asType(datatype).on('value', function(topic, specification, newValue, oldValue) {
     // Receive updates for the topic 'foo'
});
// Attach multiple listeners for events
session.subscribe('foo').asType(datatype).on({
    subscribe : function(topic, specification) {
        // Subscribed to a particular topic
    },
    unsubscribe : function(topic, specification, reason) {
        // Unsubscribed from a particular topic
    },
    value : function(topic, specification, newValue, oldValue) {
        // Value from a topic
    }
});

Extends

Methods

close()

Close the subscription. No further events will be emitted.

off(event, listener) → {Stream}

Remove a listener from a specified event.
Parameters:
Name Type Argument Description
event String The event to remove listeners from
listener function <optional>
The listener to remove. All listeners for the event are removed if this is not specified
Inherited From:
Returns:
This stream.
Type
Stream
Examples
// Bind a single listener to the 'foo' event and then deregister it
var listener = function() {};
stream.on('foo', listener);
stream.off('foo', listener);
// Bind a listener to the 'foo' event and deregister all listeners
var listener = function() {};
stream.on('foo', listener);
stream.off('foo');

on(events, listener) → {Stream}

Register listeners against events.

A single listener may be bound to an event by passing the event name and listener function.

Multiple listeners may be bound by passing in an object, mapping event names to listener functions.

Parameters:
Name Type Argument Description
events String | Object The event name or object mapping event names to listeners
listener function <optional>
The listener to bind to the event, if passed as string.
Inherited From:
Returns:
This stream.
Type
Stream
Examples
// Bind a single listener to the 'foo' event
stream.on('foo', function(arg1, arg2) {
    console.log("Called for 'foo' event", arg1, arg2);
});
// Bind multiple listeners
stream.on({
    foo : function() { ... },
    bar : function() { ... },
    baz : function() { ... }
});

Events

close

Emitted when the subscription has been closed using TypedSubscription#close.

error

Emitted when an error occurs in the Stream or in any of its listeners. No further events will be emitted after this.
Properties:
Name Type Description
error Error the error that occurred
Inherited From:

open

Emitted when the subscription is initially opened, passing a reference to the subscription itself. This will only be fired once.

subscribe

Emitted when a topic that is selected by this TypedSubscription's topic selector is subscribed to by this session. Once subscribed, value update events may be received for this topic<. The specification is a TopicSpecification instance that contains details about the topic.
Properties:
Name Type Description
topic String the topic to which the subscription applies
specification TopicSpecification instance that contains details about the topic

unsubscribe

Emitted when a topic that was previously subscribed, has been unsubscribed. No further update events will be received from this topic until subscribed again. Unsubscriptions may occur due to the topic being removed, or through calling Session#unsubscribe - an object containing the reason is provided.
Properties:
Name Type Description
topic String the topic to which the unsubscription applies
specification TopicSpecification instance that contains details about the topic
reason String the reason for the unsubscription

value

Emitted when an update has been received for a topic's value. Values will be provided as instances appropriate for the associated DataType this subscription was created for. Both the previous value and the new value are provided.
Properties:
Name Type Description
topic String the topic to which the update applies
specification TopicSpecification instance that contains details about the topic
newValue object the new value of the topic
oldValue object the old value of the topic