Merge pull request #869 from ovaris/master

Flow type: Modifies db Reference push() to return ThenableReference
This commit is contained in:
Michael Diarmid 2018-07-01 17:36:41 +01:00 committed by GitHub
commit 43615ffcf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -299,15 +299,15 @@ export default class Reference extends ReferenceBase {
* @param onComplete
* @returns {*}
*/
push(value: any, onComplete?: Function): Reference | Promise<void> {
push(value: any, onComplete?: Function): ThenableReference<void> {
if (value === null || value === undefined) {
return new Reference(
return new ThenableReference(
this._database,
`${this.path}/${generatePushID(this._database._serverTimeOffset)}`
);
}
const newRef = new Reference(
const newRef = new ThenableReference(
this._database,
`${this.path}/${generatePushID(this._database._serverTimeOffset)}`
);
@ -892,3 +892,12 @@ export default class Reference extends ReferenceBase {
return SyncTree.removeListenersForRegistrations(registrations);
}
}
// eslint-disable-next-line no-unused-vars
declare class ThenableReference<+R> extends Reference {
then<U>(
onFulfill?: (value: R) => Promise<U> | U,
onReject?: (error: any) => Promise<U> | U
): Promise<U>;
catch<U>(onReject?: (error: any) => Promise<U> | U): Promise<R | U>;
}