-
Notifications
You must be signed in to change notification settings - Fork 7
Realtime
Jayesh Choudhary edited this page Jan 7, 2020
·
7 revisions
- LiveQuery
-
Class representing the LiveQuery Interface.
- 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
Class representing the LiveQuery Interface.
Kind: global class
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()
Prepares the find query
Kind: instance method of LiveQuery
Param | Type | Description |
---|---|---|
...conditions | Object |
The condition logic. |
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 |
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 |
Callback for error while subscribing
Kind: global function
Param | Type | Description |
---|---|---|
err | string |
Error during the liveSubscribe |
The function to unsubscribe the subscription
Kind: global function