Skip to content

Realtime

Jayesh Choudhary edited this page Jan 7, 2020 · 7 revisions

Classes

LiveQuery

Class representing the LiveQuery Interface.

Functions

OnSnapshot(docs, type, find, changedDoc)

Callback for realtime updates to the subscribed data

OnError(err)

Callback for error while subscribing

Unsubscribe()

The function to unsubscribe the subscription

LiveQuery

Class representing the LiveQuery Interface.

Kind: global class

new LiveQuery(appId, db, collection, client, store)

Create an instance of the LiveQuery Interface.

Param Type
appId string
db string
collection string
client WebSocketClient
store Object

Example

import { API, cond, or, and } from 'space-api';
const api = new API('my-project');

// Create database instance
const db = api.DB("mongo");

const onSnapshot  = (docs, type, find, changedDoc) => {
   console.log(docs, type, find, changedDoc)
 }

 const onError = (err) => {
   console.log('Live query error', err)
 }

 let subscription = db.liveQuery('posts').where({}).subscribe(onSnapshot, onError) 

 subscription.unsubscribe()

liveQuery.where(...conditions)

Prepares the find query

Kind: instance method of LiveQuery

Param Type Description
...conditions Object The condition logic.

liveQuery.options(opts)

Sets the options for the live query

Kind: instance method of LiveQuery

Param Type Description
opts Object The options. (Of the form { changesOnly: true

liveQuery.subscribe(onSnapshot, onError) ⇒ Unsubscribe

Subscribes for real time updates

Kind: instance method of LiveQuery
Returns: Unsubscribe - Returns a unsubscribe function

Param Type Description
onSnapshot OnSnapshot OnSnapshot callback
onError OnError OnError callback

OnSnapshot(docs, type, find, changedDoc)

Callback for realtime updates to the subscribed data

Kind: global function

Param Type Description
docs Array The updated docs
type string The type of operation performed
find Object The object containing those fields of the concerned doc that form it's unique identity (i.e the primary field or the fields in a unique index)
changedDoc Object The doc that changed

OnError(err)

Callback for error while subscribing

Kind: global function

Param Type Description
err string Error during the liveSubscribe

Unsubscribe()

The function to unsubscribe the subscription

Kind: global function