react-native-firebase/lib/modules/database/OnDisconnect.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

/**
* @flow
* OnDisconnect representation wrapper
*/
import { typeOf } from '../../utils';
import { getNativeModule } from '../../utils/native';
import type Database from './';
import type Reference from './Reference';
2017-02-14 15:57:08 +00:00
/**
* @url https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect
* @class OmDisconnect
2017-02-14 15:57:08 +00:00
*/
export default class OnDisconnect {
_database: Database;
2017-02-14 15:57:08 +00:00
ref: Reference;
2017-04-04 16:58:20 +00:00
path: string;
2017-02-14 15:57:08 +00:00
/**
*
* @param ref
2017-02-14 15:57:08 +00:00
*/
constructor(ref: Reference) {
this.ref = ref;
this.path = ref.path;
this._database = ref._database;
2017-02-14 15:57:08 +00:00
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect#set
* @param value
* @returns {*}
*/
set(value: string | Object): Promise<void> {
2018-01-25 18:25:39 +00:00
return getNativeModule(this._database).onDisconnectSet(this.path, {
type: typeOf(value),
value,
});
2017-02-14 15:57:08 +00:00
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect#update
* @param values
* @returns {*}
*/
update(values: Object): Promise<void> {
2018-01-25 18:25:39 +00:00
return getNativeModule(this._database).onDisconnectUpdate(
this.path,
values
);
2017-02-14 15:57:08 +00:00
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect#remove
* @returns {*}
*/
remove(): Promise<void> {
return getNativeModule(this._database).onDisconnectRemove(this.path);
2017-02-14 15:57:08 +00:00
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect#cancel
* @returns {*}
*/
cancel(): Promise<void> {
return getNativeModule(this._database).onDisconnectCancel(this.path);
2017-02-14 15:57:08 +00:00
}
}