Skip to content

Commit b6bfae0

Browse files
Revert "Fix the type annotations in the RTDB Query.on/off/once API. (#1204)" (#1723)
This reverts commit e50b070.
1 parent e50b070 commit b6bfae0

File tree

5 files changed

+28
-39
lines changed

5 files changed

+28
-39
lines changed

packages/database-types/index.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ export interface Query {
7171
eventType?: EventType,
7272
callback?: (a: DataSnapshot, b?: string | null) => any,
7373
context?: Object | null
74-
): void;
74+
): any;
7575
on(
7676
eventType: EventType,
77-
callback: (a: DataSnapshot, b?: string | null) => any,
78-
cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
77+
callback: (a: DataSnapshot | null, b?: string) => any,
78+
cancelCallbackOrContext?: Object | null,
7979
context?: Object | null
80-
): (a: DataSnapshot, b?: string | null) => any;
80+
): (a: DataSnapshot | null, b?: string) => any;
8181
once(
8282
eventType: EventType,
83-
successCallback?: (a: DataSnapshot, b?: string | null) => any,
84-
failureCallbackOrContext?: ((a: Error) => void) | Object | null,
83+
successCallback?: (a: DataSnapshot, b?: string) => any,
84+
failureCallbackOrContext?: Object | null,
8585
context?: Object | null
8686
): Promise<DataSnapshot>;
8787
orderByChild(path: string): Query;

packages/database/CHANGELOG.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/database/src/api/Query.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { DataSnapshot } from './DataSnapshot';
4949
let __referenceConstructor: new (repo: Repo, path: Path) => Query;
5050

5151
export interface SnapshotCallback {
52-
(a: DataSnapshot, b?: string | null): any;
52+
(a: DataSnapshot, b?: string): any;
5353
}
5454

5555
/**
@@ -198,8 +198,8 @@ export class Query {
198198
on(
199199
eventType: string,
200200
callback: SnapshotCallback,
201-
cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
202-
context?: Object | null
201+
cancelCallbackOrContext?: ((a: Error) => any) | Object,
202+
context?: Object
203203
): SnapshotCallback {
204204
validateArgCount('Query.on', 2, 4, arguments.length);
205205
validateEventType('Query.on', 1, eventType, false);
@@ -264,11 +264,7 @@ export class Query {
264264
* @param {(function(!DataSnapshot, ?string=))=} callback
265265
* @param {Object=} context
266266
*/
267-
off(
268-
eventType?: string,
269-
callback?: SnapshotCallback,
270-
context?: Object | null
271-
): void {
267+
off(eventType?: string, callback?: SnapshotCallback, context?: Object) {
272268
validateArgCount('Query.off', 0, 3, arguments.length);
273269
validateEventType('Query.off', 1, eventType, true);
274270
validateCallback('Query.off', 2, callback, true);
@@ -297,23 +293,23 @@ export class Query {
297293
* Attaches a listener, waits for the first event, and then removes the listener
298294
* @param {!string} eventType
299295
* @param {!function(!DataSnapshot, string=)} userCallback
300-
* @param failureCallbackOrContext
296+
* @param cancelOrContext
301297
* @param context
302298
* @return {!firebase.Promise}
303299
*/
304300
once(
305301
eventType: string,
306302
userCallback?: SnapshotCallback,
307-
failureCallbackOrContext?: ((a: Error) => void) | Object | null,
308-
context?: Object | null
303+
cancelOrContext?: ((a: Error) => void) | Object,
304+
context?: Object
309305
): Promise<DataSnapshot> {
310306
validateArgCount('Query.once', 1, 4, arguments.length);
311307
validateEventType('Query.once', 1, eventType, false);
312308
validateCallback('Query.once', 2, userCallback, true);
313309

314310
const ret = Query.getCancelAndContextArgs_(
315311
'Query.once',
316-
failureCallbackOrContext,
312+
cancelOrContext,
317313
context
318314
);
319315

@@ -635,8 +631,8 @@ export class Query {
635631
*/
636632
private static getCancelAndContextArgs_(
637633
fnName: string,
638-
cancelOrContext?: ((a: Error) => void) | Object | null,
639-
context?: Object | null
634+
cancelOrContext?: ((a: Error) => void) | Object,
635+
context?: Object
640636
): { cancel: ((a: Error) => void) | null; context: Object | null } {
641637
const ret: {
642638
cancel: ((a: Error) => void) | null;

packages/database/src/core/view/Change.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class Change {
3232
public snapshotNode: Node,
3333
public childName?: string,
3434
public oldSnap?: Node,
35-
public prevName?: string | null
35+
public prevName?: string
3636
) {}
3737

3838
/**

packages/firebase/index.d.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,8 +4388,8 @@ declare namespace firebase.database {
43884388
* must also be called on any child listeners to remove the callback.
43894389
*
43904390
* If a callback is not specified, all callbacks for the specified eventType
4391-
* will be removed. Similarly, if no eventType is specified, all callbacks
4392-
* for the `Reference` will be removed.
4391+
* will be removed. Similarly, if no eventType or callback is specified, all
4392+
* callbacks for the `Reference` will be removed.
43934393
*
43944394
* @example
43954395
* ```javascript
@@ -4414,17 +4414,16 @@ declare namespace firebase.database {
44144414
* ```
44154415
*
44164416
* @param eventType One of the following strings: "value",
4417-
* "child_added", "child_changed", "child_removed", or "child_moved." If
4418-
* omitted, all callbacks for the `Reference` will be removed.
4419-
* @param callback The callback function that was passed to `on()` or
4420-
* `undefined` to remove all callbacks.
4417+
* "child_added", "child_changed", "child_removed", or "child_moved."
4418+
* @param callback The
4419+
* callback function that was passed to `on()`.
44214420
* @param context The context that was passed to `on()`.
44224421
*/
44234422
off(
44244423
eventType?: EventType,
44254424
callback?: (a: firebase.database.DataSnapshot, b?: string | null) => any,
44264425
context?: Object | null
4427-
): void;
4426+
): any;
44284427

44294428
/**
44304429
* Listens for data changes at a particular location.
@@ -4540,10 +4539,10 @@ declare namespace firebase.database {
45404539
*/
45414540
on(
45424541
eventType: EventType,
4543-
callback: (a: firebase.database.DataSnapshot, b?: string | null) => any,
4542+
callback: (a: firebase.database.DataSnapshot | null, b?: string) => any,
45444543
cancelCallbackOrContext?: Object | null,
45454544
context?: Object | null
4546-
): (a: firebase.database.DataSnapshot | null, b?: string | null) => any;
4545+
): (a: firebase.database.DataSnapshot | null, b?: string) => any;
45474546

45484547
/**
45494548
* Listens for exactly one event of the specified event type, and then stops
@@ -4580,13 +4579,10 @@ declare namespace firebase.database {
45804579
*/
45814580
once(
45824581
eventType: EventType,
4583-
successCallback?: (
4584-
a: firebase.database.DataSnapshot,
4585-
b?: string | null
4586-
) => any,
4587-
failureCallbackOrContext?: ((a: Error) => void) | Object | null,
4582+
successCallback?: (a: firebase.database.DataSnapshot, b?: string) => any,
4583+
failureCallbackOrContext?: Object | null,
45884584
context?: Object | null
4589-
): Promise<firebase.database.DataSnapshot>;
4585+
): Promise<DataSnapshot>;
45904586
/**
45914587
* Generates a new `Query` object ordered by the specified child key.
45924588
*

0 commit comments

Comments
 (0)