new Subscription()
Deprecated
As of 6.0, this class is deprecated. Use Subscription#asType instead. In future versions, Session#stream will return a ValueStream.Provides an untyped stream of topic events.
- Deprecated:
-
- Yes
Properties:
Name | Type | Description |
---|---|---|
selector |
String | The selector this subscription was created for |
Fires:
- Subscription#event:open
- Subscription#event:close
- Subscription#event:update
- Subscription#event:subscribe
- Subscription#event:unsubscribe
- Subscription#event:error
Extends
Methods
-
asType(datatype)
-
Produce a ValueStream from this subscription stream, in order to receive values as a particular DataType. The ValueStream will only receive values from topics that are of matching type for the provided data type.
The lifecycle of the produced ValueStream is independent of this subscription. If this subscription was created using Session#stream without a selector (i.e as a fallback stream), the ValueStream will also be registered as a fallback stream.
Parameters:
Name Type Description datatype
DataType The data type to produce a stream for.
Returns:
A new ValueStream for the provided data type
- Type
- ValueStream
Example
// Produce a value stream for receiving JSON values. var datatype = diffusion.datatypes.json(); session.stream('foo').asType(datatype).on('value', function(topic, value) { //... });
-
close()
-
Close the subscription. No further events will be emitted. This operation is purely client-side; the server will still maintain any active subscriptions for this client.
- 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() { ... } });
-
transform(transformer)
-
Deprecated
As of 6.0, this is deprecated. Use Subscription#asType instead.Create a new Subscription instance that is bound with a transformation function.
Parameters:
Name Type Description transformer
function The transformation function to apply to updates
Returns:
The new subscription bound with the transformation
- Type
- Subscription