js: change db error to match firebase web sdk error

This commit is contained in:
Salakar
2017-03-08 13:21:21 +00:00
parent 51c63b2f3e
commit 2d1015d205
3 changed files with 21 additions and 6 deletions

View File

@@ -77,12 +77,12 @@ export default class Reference extends ReferenceBase {
*/
push(value: any, onComplete: Function) {
if (value === null || value === undefined) {
const _path = this.path + '/' + generatePushID(this.db.serverTimeOffset);
return new Reference(this.db, _path);
return new Reference(this.db, `${this.path}/${generatePushID(this.db.serverTimeOffset)}`);
}
const path = this._dbPath();
const _value = this._serializeAnyType(value);
return promisify('push', FirebaseDatabase)(path, _value)
.then(({ ref }) => {
const newRef = new Reference(this.db, ref);
@@ -102,7 +102,7 @@ export default class Reference extends ReferenceBase {
* @param context TODO
* @returns {*}
*/
on(eventType: string, successCallback: () => any, failureCallback: () => any, context) {
on(eventType: string, successCallback: () => any, failureCallback: () => any) {
if (!isFunction(successCallback)) throw new Error('The specified callback must be a function');
if (failureCallback && !isFunction(failureCallback)) throw new Error('The specified error callback must be a function');
const path = this._dbPath();
@@ -280,14 +280,27 @@ export default class Reference extends ReferenceBase {
return newRef;
}
/**
*
* @returns {Disconnect}
*/
onDisconnect() {
return new Disconnect(this.path);
}
/**
* Get a specified child
* @param path
* @returns {Reference}
*/
child(path: string) {
return new Reference(this.db, this.path + '/' + path);
return new Reference(this.db, `${this.path}/${path}`);
}
/**
* Return the ref as a path string
* @returns {string}
*/
toString(): string {
return this._dbPath();
}