Class: ValueStream

ValueStream


new ValueStream()

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

ValueStream inherits all functions defined on Stream.

Properties:
Name Type Description
selector String

The selector this subscription was created for

Fires:
  • ValueStream#event:open
  • ValueStream#event:close
  • ValueStream#event:value
  • ValueStream#event:subscribe
  • ValueStream#event:unsubscribe
  • ValueStream#event:error
Examples
// Create a value stream for topic 'foo'
session.addStream('foo', datatype).on('value', function(topic, specification, newValue, oldValue) {
    // Receive updates for the topic 'foo'
});

// Then subscribe to topic 'foo'
session.select('foo');
// Attach multiple listeners for events
session.addStream('foo', 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 stream. No further events will be emitted.

This does not unsubscribe the topic. Other streams may still recieve updates for the same topic selector. To unsubscribe, use Session#unsubscribe

Overrides:

off(event [, listener])

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])

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() { ... }
});