new View()
An aggregate view of topics and their values, reflected as a single structure that is updated in real time.
Because Views are bound to a particular topic selector, it is possible for the structure to change as topics are added or removed that match the selector.
Fires:
- event:update
Examples
var view = session.view('?foo//'); var data = view.get(); // Log the current value of the topic 'foo' console.log(data.foo); // Log the current value of the topic 'foo/bar/baz' console.log(data.foo.bar.baz);
var view = session.view('?foo//'); view.on('update', function(data) { // Log the current state of the view console.log(data); });
Extends
Methods
-
close()
-
Close the stream. This will emit a 'close' event to any assigned listeners. No further events will be emitted.
- Inherited From:
-
get()
-
Returns a read-only version of the the view's current state. This will reflect modifications caused by any future updates.
Returns:
The view state
- Type
- Object
-
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() { ... } });