[js][database] fix OnDisconnect incorrectly being constructed + added misc typings

This commit is contained in:
Salakar 2017-09-07 16:36:47 +01:00
parent 3f9cd5435e
commit 557face5eb
3 changed files with 18 additions and 16 deletions

View File

@ -105,4 +105,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
[version]
^0.40.0
^0.46.0

View File

@ -14,10 +14,12 @@ export default class Disconnect {
/**
*
* @param path Reference Path
* @param ref
*/
constructor(path: string) {
this.path = path;
constructor(ref: Reference) {
this.ref = ref;
this.path = ref.path;
this._database = ref._database;
}
/**
@ -25,8 +27,8 @@ export default class Disconnect {
* @param value
* @returns {*}
*/
set(value: string | Object) {
return this.database._native.onDisconnectSet(this.path, { type: typeOf(value), value });
set(value: string | Object): Promise<void> {
return this._database._native.onDisconnectSet(this.path, { type: typeOf(value), value });
}
/**
@ -34,23 +36,23 @@ export default class Disconnect {
* @param values
* @returns {*}
*/
update(values: Object) {
return this.database._native.onDisconnectUpdate(this.path, values);
update(values: Object): Promise<void> {
return this._database._native.onDisconnectUpdate(this.path, values);
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect#remove
* @returns {*}
*/
remove() {
return this.database._native.onDisconnectRemove(this.path);
remove(): Promise<void> {
return this._database._native.onDisconnectRemove(this.path);
}
/**
* @url https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect#cancel
* @returns {*}
*/
cancel() {
return this.database._native.onDisconnectCancel(this.path);
cancel(): Promise<void> {
return this._database._native.onDisconnectCancel(this.path);
}
}

View File

@ -248,7 +248,7 @@ export default class Reference extends ReferenceBase {
* @param onComplete
* @returns {*}
*/
push(value: any, onComplete?: Function) {
push(value: any, onComplete?: Function): Reference | Promise {
if (value === null || value === undefined) {
return new Reference(this._database, `${this.path}/${generatePushID(this._database.serverTimeOffset)}`);
}
@ -403,8 +403,8 @@ export default class Reference extends ReferenceBase {
*
* @returns {Disconnect}
*/
onDisconnect() {
return new Disconnect(this.path);
onDisconnect(): Disconnect {
return new Disconnect(this);
}
/**
@ -415,7 +415,7 @@ export default class Reference extends ReferenceBase {
* Reference
* {@link https://firebase.google.com/docs/reference/js/firebase.database.Reference#child}
*/
child(path: string) {
child(path: string): Reference {
return new Reference(this._database, `${this.path}/${path}`);
}