Skip to content

Revert "Fix the type annotations in the RTDB Query.on/off/once API." #1723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/database-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ export interface Query {
eventType?: EventType,
callback?: (a: DataSnapshot, b?: string | null) => any,
context?: Object | null
): void;
): any;
on(
eventType: EventType,
callback: (a: DataSnapshot, b?: string | null) => any,
cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
callback: (a: DataSnapshot | null, b?: string) => any,
cancelCallbackOrContext?: Object | null,
context?: Object | null
): (a: DataSnapshot, b?: string | null) => any;
): (a: DataSnapshot | null, b?: string) => any;
once(
eventType: EventType,
successCallback?: (a: DataSnapshot, b?: string | null) => any,
failureCallbackOrContext?: ((a: Error) => void) | Object | null,
successCallback?: (a: DataSnapshot, b?: string) => any,
failureCallbackOrContext?: Object | null,
context?: Object | null
): Promise<DataSnapshot>;
orderByChild(path: string): Query;
Expand Down
3 changes: 0 additions & 3 deletions packages/database/CHANGELOG.md

This file was deleted.

24 changes: 10 additions & 14 deletions packages/database/src/api/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { DataSnapshot } from './DataSnapshot';
let __referenceConstructor: new (repo: Repo, path: Path) => Query;

export interface SnapshotCallback {
(a: DataSnapshot, b?: string | null): any;
(a: DataSnapshot, b?: string): any;
}

/**
Expand Down Expand Up @@ -198,8 +198,8 @@ export class Query {
on(
eventType: string,
callback: SnapshotCallback,
cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
context?: Object | null
cancelCallbackOrContext?: ((a: Error) => any) | Object,
context?: Object
): SnapshotCallback {
validateArgCount('Query.on', 2, 4, arguments.length);
validateEventType('Query.on', 1, eventType, false);
Expand Down Expand Up @@ -264,11 +264,7 @@ export class Query {
* @param {(function(!DataSnapshot, ?string=))=} callback
* @param {Object=} context
*/
off(
eventType?: string,
callback?: SnapshotCallback,
context?: Object | null
): void {
off(eventType?: string, callback?: SnapshotCallback, context?: Object) {
validateArgCount('Query.off', 0, 3, arguments.length);
validateEventType('Query.off', 1, eventType, true);
validateCallback('Query.off', 2, callback, true);
Expand Down Expand Up @@ -297,23 +293,23 @@ export class Query {
* Attaches a listener, waits for the first event, and then removes the listener
* @param {!string} eventType
* @param {!function(!DataSnapshot, string=)} userCallback
* @param failureCallbackOrContext
* @param cancelOrContext
* @param context
* @return {!firebase.Promise}
*/
once(
eventType: string,
userCallback?: SnapshotCallback,
failureCallbackOrContext?: ((a: Error) => void) | Object | null,
context?: Object | null
cancelOrContext?: ((a: Error) => void) | Object,
context?: Object
): Promise<DataSnapshot> {
validateArgCount('Query.once', 1, 4, arguments.length);
validateEventType('Query.once', 1, eventType, false);
validateCallback('Query.once', 2, userCallback, true);

const ret = Query.getCancelAndContextArgs_(
'Query.once',
failureCallbackOrContext,
cancelOrContext,
context
);

Expand Down Expand Up @@ -635,8 +631,8 @@ export class Query {
*/
private static getCancelAndContextArgs_(
fnName: string,
cancelOrContext?: ((a: Error) => void) | Object | null,
context?: Object | null
cancelOrContext?: ((a: Error) => void) | Object,
context?: Object
): { cancel: ((a: Error) => void) | null; context: Object | null } {
const ret: {
cancel: ((a: Error) => void) | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/core/view/Change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Change {
public snapshotNode: Node,
public childName?: string,
public oldSnap?: Node,
public prevName?: string | null
public prevName?: string
) {}

/**
Expand Down
26 changes: 11 additions & 15 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4388,8 +4388,8 @@ declare namespace firebase.database {
* must also be called on any child listeners to remove the callback.
*
* If a callback is not specified, all callbacks for the specified eventType
* will be removed. Similarly, if no eventType is specified, all callbacks
* for the `Reference` will be removed.
* will be removed. Similarly, if no eventType or callback is specified, all
* callbacks for the `Reference` will be removed.
*
* @example
* ```javascript
Expand All @@ -4414,17 +4414,16 @@ declare namespace firebase.database {
* ```
*
* @param eventType One of the following strings: "value",
* "child_added", "child_changed", "child_removed", or "child_moved." If
* omitted, all callbacks for the `Reference` will be removed.
* @param callback The callback function that was passed to `on()` or
* `undefined` to remove all callbacks.
* "child_added", "child_changed", "child_removed", or "child_moved."
* @param callback The
* callback function that was passed to `on()`.
* @param context The context that was passed to `on()`.
*/
off(
eventType?: EventType,
callback?: (a: firebase.database.DataSnapshot, b?: string | null) => any,
context?: Object | null
): void;
): any;

/**
* Listens for data changes at a particular location.
Expand Down Expand Up @@ -4540,10 +4539,10 @@ declare namespace firebase.database {
*/
on(
eventType: EventType,
callback: (a: firebase.database.DataSnapshot, b?: string | null) => any,
callback: (a: firebase.database.DataSnapshot | null, b?: string) => any,
cancelCallbackOrContext?: Object | null,
context?: Object | null
): (a: firebase.database.DataSnapshot | null, b?: string | null) => any;
): (a: firebase.database.DataSnapshot | null, b?: string) => any;

/**
* Listens for exactly one event of the specified event type, and then stops
Expand Down Expand Up @@ -4580,13 +4579,10 @@ declare namespace firebase.database {
*/
once(
eventType: EventType,
successCallback?: (
a: firebase.database.DataSnapshot,
b?: string | null
) => any,
failureCallbackOrContext?: ((a: Error) => void) | Object | null,
successCallback?: (a: firebase.database.DataSnapshot, b?: string) => any,
failureCallbackOrContext?: Object | null,
context?: Object | null
): Promise<firebase.database.DataSnapshot>;
): Promise<DataSnapshot>;
/**
* Generates a new `Query` object ordered by the specified child key.
*
Expand Down