Skip to content

Commit a402902

Browse files
Simplify DatabaseInternal
1 parent 7ad7827 commit a402902

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

packages/database/src/api/Database.ts

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ import { FirebaseDatabase } from '@firebase/database-types';
3333
* @implements {FirebaseService}
3434
*/
3535
export class Database implements FirebaseService {
36-
INTERNAL: DatabaseInternals;
37-
3836
/** Track if the instance has been used (root or repo accessed) */
3937
private instanceStarted_: boolean = false;
4038

4139
/** Backing state for root_ */
42-
private rootInternal_: Reference;
40+
private rootInternal_?: Reference;
4341

4442
static readonly ServerValue = {
4543
TIMESTAMP: {
@@ -64,20 +62,22 @@ export class Database implements FirebaseService {
6462
"Don't call new Database() directly - please use firebase.database()."
6563
);
6664
}
67-
68-
this.repo_ = repoInternal_;
69-
this.INTERNAL = new DatabaseInternals(this);
7065
}
7166

67+
INTERNAL = {
68+
delete: async () => {
69+
this.checkDeleted_('delete');
70+
RepoManager.getInstance().deleteRepo(this.repo_);
71+
this.repoInternal_ = null;
72+
this.rootInternal_ = null;
73+
}
74+
};
75+
7276
private get repo_(): Repo {
7377
this.instanceStarted_ = true;
7478
return this.repoInternal_;
7579
}
7680

77-
private set repo_(repo: Repo) {
78-
this.repoInternal_ = repo;
79-
}
80-
8181
get root_(): Reference {
8282
if (!this.rootInternal_) {
8383
this.rootInternal_ = new Reference(this.repo_, Path.Empty);
@@ -86,10 +86,6 @@ export class Database implements FirebaseService {
8686
return this.rootInternal_;
8787
}
8888

89-
set root_(root: Reference) {
90-
this.rootInternal_ = root;
91-
}
92-
9389
get app(): FirebaseApp {
9490
return this.repo_.app;
9591
}
@@ -111,7 +107,11 @@ export class Database implements FirebaseService {
111107
}
112108

113109
// Modify the repo to apply emulator settings
114-
RepoManager.getInstance().applyEmulatorSettings(this.repoInternal_, host, port);
110+
RepoManager.getInstance().applyEmulatorSettings(
111+
this.repoInternal_,
112+
host,
113+
port
114+
);
115115
}
116116

117117
/**
@@ -190,22 +190,3 @@ export class Database implements FirebaseService {
190190
this.repo_.resume();
191191
}
192192
}
193-
194-
export class DatabaseInternals {
195-
/** @param {!Database} database */
196-
constructor(public database: Database) {}
197-
198-
/** @return {Promise<void>} */
199-
async delete(): Promise<void> {
200-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
201-
(this.database as any).checkDeleted_('delete');
202-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
203-
RepoManager.getInstance().deleteRepo((this.database as any).repo_ as Repo);
204-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
205-
(this.database as any).repo_ = null;
206-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
207-
(this.database as any).root_ = null;
208-
this.database.INTERNAL = null;
209-
this.database = null;
210-
}
211-
}

0 commit comments

Comments
 (0)