RGJS6 Firebase Database module.
Methods
-
<static> off(path, eventType [, args])
-
Firebase database off().
Parameters:
Name Type Argument Description pathstring The path of the database ref.
eventTypestring Event type, for example: value, child_changed, child_added, etc.
argsargs <optional>
An object containing arguments.
Example
// Results in `ref('/path/to/data').off('child_added')` rgjs.firebase.db.off('/path/to/data', 'child_added'); -
<static> on(path, eventType [, args] [, cb] [, cberr])
-
Firebase database on().
Can be aborted usingargs.opts.abortOn*.Parameters:
Name Type Argument Description pathstring The path of the database ref.
eventTypestring Event type, for example: value, child_changed, child_added, etc.
argsargs <optional>
An object containing arguments.
cbfunction <optional>
The callback.
cberrfunction <optional>
The error callback.
Example
// Results in `ref('/path/to/data').on('child_added', cb)` rgjs.firebase.db.on('/path/to/data', 'child_added', null, cb); -
<static> once(path, eventType [, args])
-
Firebase database once().
Can be aborted usingargs.opts.abortOn*.Parameters:
Name Type Argument Description pathstring The path of the database ref.
eventTypestring Event type, for example: value, child_changed, child_added, etc.
argsargs <optional>
An object containing arguments.
Returns:
A promise with the snapshot.
- Type
- promise
Example
// Results in `ref('/path/to/data').once('value').then( ... )` rgjs.firebase.db.once('/path/to/data', 'value'); -
<static> ref(path [, args] [, eventType])
-
Firebase database ref(). Can abort
once()andon()usingargs.opts.abortOn*.Parameters:
Name Type Argument Description pathstring The path of the database ref.
argsargs <optional>
An object containing arguments.
eventTypestring <optional>
Event type, for example: value, child_changed, child_added, etc.
Returns:
The reference.
- Type
- object
Example
// Results in `ref('/path/to/data')` rgjs.firebase.db.on('/path/to/data') -
<static> setDefaultDatabase(db)
-
Set default database.
Parameters:
Name Type Description dbobject A firebase database object.
Example
const db = firebase_app.database(); rgjs.firebase.db.setDefaultDatabase(db);
Type Definitions
-
args
-
Generic arguments for rgjs.firebase.db functions.
Type:
- object
Properties:
Name Type Argument Default Description idstring Optional. Used to keep track of references. Defaults to a unique value. If a reference exists with given id and
opts.abortOnIdis true,ref[opts.id].off(eventType)is called, which effectively abortsonce(),on(), etc calls.queriesarray <optional>
Optional. An array containing queries. Syntax for query:
['FUNCTION', ...arguments]. See example below.cbfunction <optional>
Optional. Callback, called on success with argument
firebase.database.DataSnapshot.cberrfunction <optional>
Optional. Error callback, called when an error occurs with argument Error.
dbdatabase <optional>
Optional if
setDefaultDatabase()is used. The Firebase database object to use.debugboolean <optional>
Optional. Turns on debug console logging.
optsobject <optional>
{} Options.
Properties
Name Type Argument Default Description abortOnAllboolean <optional>
false Call
ref(path).off(|eventType)if the id or path match.abortOnIdboolean <optional>
true Call
ref(path).off()if the id matches. Note that the id option DOES NOT pass eventName!abortOnAllboolean <optional>
false Call
ref(path).off(eventType)if the path matches. Note that the path option passes eventName!Examples
// Example: Abort on id ref.on('/data', 'child_added', {id: 'get-/data'}); // Does NOT call `off()` on `ref('/data')` because `opts.abortOnId = false`: ref.on('/data', 'child_changed', {id: 'get-/data', opts: {abortOnId: false}}); // Does call `off()` on all ref('/data') that match the id 'get-/data': ref.once('/data', 'value', {id: 'get-/data'});// Example: Abort on path ref.on('/data', 'child_added'); // Does NOT call `off()` on `ref('/data')` because `opts.abortOnPath = false`: // You will have two `on()` listeners now for `ref('/data')`! ref.on('/data', 'child_added'); // Does call `off('child_added')` on all ref('/data'): ref.on('/data', 'child_added', {opts: {abortOnPath: true}});// Example: Abort caveats #1 - Abort on path ref.on('/data', 'child_added'); // Calls `off('value')` on all ref('/data'): // This will NOT cancel 'child_added'! ref.once('/data', 'value', {opts: {abortOnPath: true}});// Example: Abort caveats #2 - Abort on path, id ref.on('/data', 'child_added', {id: 'get-/data'}); // Calls `off('value')` on all ref('/data'), then calls `off()` on all ref('/data') that match the id 'get-/data': // This WILL cancel 'child_added' because id is provided, matches and `abortOnId = true` by default! ref.once('/data', 'value', {id: 'get-/data', opts: {abortOnPath: true}});// Example: Queries // Will apply `ref('/data').startAt('rgjs@rejh.nl', 'email').limitToFirst(1).once('value')`. ref.once('/data', 'value', {queries: [['startAt', 'rgjs@rejh.nl', 'email'], ['limitToFirst', 1]]}).then( ... )