@@ -36,7 +36,7 @@ export class Database implements FirebaseService {
36
36
INTERNAL : DatabaseInternals ;
37
37
38
38
/** Track if the instance has been used (root or repo accessed) */
39
- private instanceUsed_ : boolean = false ;
39
+ private instanceStarted_ : boolean = false ;
40
40
41
41
/** Backing state for root_ */
42
42
private rootInternal_ : Reference ;
@@ -70,20 +70,19 @@ export class Database implements FirebaseService {
70
70
}
71
71
72
72
private get repo_ ( ) : Repo {
73
- this . instanceUsed_ = true ;
73
+ this . instanceStarted_ = true ;
74
74
return this . repoInternal_ ;
75
75
}
76
76
77
77
private set repo_ ( repo : Repo ) {
78
- if ( repo instanceof Repo ) {
79
- this . root_ = new Reference ( repo , Path . Empty ) ;
80
- }
81
-
82
78
this . repoInternal_ = repo ;
83
79
}
84
80
85
81
get root_ ( ) : Reference {
86
- this . instanceUsed_ = true ;
82
+ if ( ! this . rootInternal_ ) {
83
+ this . rootInternal_ = new Reference ( this . repo_ , Path . Empty ) ;
84
+ }
85
+
87
86
return this . rootInternal_ ;
88
87
}
89
88
@@ -104,19 +103,15 @@ export class Database implements FirebaseService {
104
103
* @param port the emulator port (ex: 8080)
105
104
*/
106
105
useEmulator ( host : string , port : number ) : void {
107
- if ( this . instanceUsed_ ) {
106
+ if ( this . instanceStarted_ ) {
108
107
fatal (
109
108
'Cannot call useEmulator() after instance has already been initialized.'
110
109
) ;
111
110
return ;
112
111
}
113
112
114
- // Get a new Repo which has the emulator settings applied
115
- const manager = RepoManager . getInstance ( ) ;
116
- const oldRepo = this . repo_ ;
117
-
118
- this . repo_ = manager . cloneRepoForEmulator ( oldRepo , host , port ) ;
119
- manager . deleteRepo ( oldRepo ) ;
113
+ // Modify the repo to apply emulator settings
114
+ RepoManager . getInstance ( ) . applyEmulatorSettings ( this . repoInternal_ , host , port ) ;
120
115
}
121
116
122
117
/**
0 commit comments