why deepstreamHub? compare us getting started faq
use cases
products
developers
company
blog contact

The deepstream client instance as well as most objects such as records or lists emit events. The event-emitter API largely follows NodeJS convention:

Methods

on( event,callback )

argument type optional description
event String false An eventname.
callback Function false The function that should be invoked when the event is emitted.

Subscribe to an event.

deepstream.on( 'error', ( error ) => {
  // do something with error
} )

off( event,callback )

argument type optional description
event String true An eventname.
callback Function true The previously-registered function.

Unsubscribes from an event by:

  • removing a specific callback when called with both arguments.
    deepstream.off( 'error', errorCallback )
    
  • removing all listeners for an event when only called with an event.
    deepstream.off( 'error' )
    
  • removing all listeners for all events if called without arguments.
    deepstream.off()
    

once( event,callback )

argument type optional description
event String false An eventname.
callback Function false The function that should be invoked when the event is emitted.

Register a one-time listener for an event. The listener will be removed immediately after its first execution.

deepstream.once( 'error', function( error ) {
  // do something with error
} )

emit( event... )

argument type optional description
event String false An eventname.
arguments Mixed true The function that should be invoked when the event is emitted.

Emits an event.

deepstream.emit( 'error', 'An error of epic proportions occured!' )

listeners( event )

argument type optional description
event String false An eventname.

Returns an array of listeners that are registered for the event.

const listeners = deepstream.listeners() // [ Listener... ]

hasListeners( event )

argument type optional description
event String false An eventname.

Returns true if there are listeners registered for that event.

const hasListeners = deepstream.hasListener('error') // true