Skip to content

Commit 61b8a48

Browse files
committed
WIP: fixes from @schmidt-sebastian's review
1 parent cf357d0 commit 61b8a48

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

src/database/api/DataSnapshot.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,8 @@ export class DataSnapshot {
139139
return !this.node_.isEmpty();
140140
}
141141

142-
/**
143-
* @return {?string} The key of the location this snapshot's data came from.
144-
*/
145-
getKey(): string | null {
146-
validateArgCount('DataSnapshot.key', 0, 0, arguments.length);
147-
148-
return this.ref_.getKey();
149-
}
150-
151142
get key() {
152-
return this.getKey();
143+
return this.ref_.getKey();
153144
}
154145

155146
/**

src/database/api/Database.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import { Reference } from "./Reference";
66
import { Repo } from "../core/Repo";
77
import { RepoManager } from "../core/RepoManager";
88
import { validateArgCount } from "../../utils/validation";
9+
import { FirebaseApp } from "../../app/firebase_app";
910
import { validateUrl } from "../core/util/validation";
1011

1112
/**
1213
* Class representing a firebase database.
1314
* @implements {firebase.Service}
1415
*/
1516
export class Database {
16-
/** @type {Repo} */
17-
repo_;
18-
/** @type {Firebase} */
19-
root_;
17+
repo_: Repo;
18+
root_: Reference;
2019
INTERNAL;
20+
private __database: Database;
2121

2222
static ServerValue = {
2323
'TIMESTAMP': {
@@ -43,18 +43,24 @@ export class Database {
4343
this.INTERNAL = new DatabaseInternals(this);
4444
}
4545

46-
app: null
46+
get app(): FirebaseApp {
47+
return this.repo_.app;
48+
}
49+
50+
get database(): Database {
51+
return this.__database || (this.__database = new Database(this));
52+
}
4753

4854
/**
4955
* Returns a reference to the root or the path specified in opt_pathString.
50-
* @param {string=} opt_pathString
56+
* @param {string=} pathString
5157
* @return {!Firebase} Firebase reference.
5258
*/
53-
ref(opt_pathString): Reference {
59+
ref(pathString?): Reference {
5460
this.checkDeleted_('ref');
5561
validateArgCount('database.ref', 0, 1, arguments.length);
5662

57-
return opt_pathString !== undefined ? this.root_.child(opt_pathString) : this.root_;
63+
return pathString !== undefined ? this.root_.child(pathString) : this.root_;
5864
}
5965

6066
/**
@@ -85,7 +91,7 @@ export class Database {
8591
* @param {string} apiName
8692
* @private
8793
*/
88-
checkDeleted_(apiName) {
94+
private checkDeleted_(apiName) {
8995
if (this.repo_ === null) {
9096
fatal("Cannot call " + apiName + " on a deleted database.");
9197
}
@@ -105,23 +111,6 @@ export class Database {
105111
}
106112
};
107113

108-
// Note: This is an un-minfied property of the Database only.
109-
Object.defineProperty(Database.prototype, 'app', {
110-
/**
111-
* @this {!Database}
112-
* @return {!firebase.app.App}
113-
*/
114-
get() {
115-
return this.repo_.app;
116-
}
117-
});
118-
119-
Object.defineProperty(Repo.prototype, 'database', {
120-
get() {
121-
return this.__database || (this.__database = new Database(this));
122-
}
123-
});
124-
125114
class DatabaseInternals {
126115
database
127116
/** @param {!Database} database */

0 commit comments

Comments
 (0)