Skip to content

Commit ba477fa

Browse files
committed
fix(app): fix issue where instanceIdentifier wasn't being passed
Fixed an issue where instance identifiers weren't being passed to their creation factories. Added some tests to validate that we don't accidentally remove that in the future.
1 parent 3e211b3 commit ba477fa

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/app/firebase_app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class FirebaseAppImpl implements FirebaseApp {
303303
}
304304

305305
if (!this.services_[name][instanceIdentifier]) {
306-
let service = this.firebase_.INTERNAL.factories[name](this, this.extendApp.bind(this));
306+
let service = this.firebase_.INTERNAL.factories[name](this, this.extendApp.bind(this), instanceIdentifier);
307307
this.services_[name][instanceIdentifier] = service;
308308
}
309309

tests/app/unit/firebase_app.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ describe("Firebase App Class", () => {
232232
// Register Multi Instance Service
233233
firebase.INTERNAL.registerService(
234234
'multiInstance',
235-
app => new TestService(app),
235+
(...args) => {
236+
const [app,,instanceIdentifier] = args;
237+
return new TestService(app, instanceIdentifier);
238+
},
236239
null,
237240
null,
238241
true
@@ -249,6 +252,7 @@ describe("Firebase App Class", () => {
249252
assert.strictEqual(service2, (firebase.app() as any).multiInstance(serviceIdentifier));
250253

251254
// Ensure that the two services **are not equal**
255+
assert.notStrictEqual(service.instanceIdentifier, service2.instanceIdentifier);
252256
assert.notStrictEqual(service, service2);
253257
assert.notStrictEqual((firebase.app() as any).multiInstance(), (firebase.app() as any).multiInstance(serviceIdentifier));
254258
});
@@ -257,7 +261,10 @@ describe("Firebase App Class", () => {
257261
// Register Multi Instance Service
258262
firebase.INTERNAL.registerService(
259263
'singleInstance',
260-
app => new TestService(app),
264+
(...args) => {
265+
const [app,,instanceIdentifier] = args;
266+
return new TestService(app, instanceIdentifier)
267+
},
261268
null,
262269
null,
263270
false // <-- multi instance flag
@@ -286,9 +293,7 @@ describe("Firebase App Class", () => {
286293
});
287294

288295
class TestService implements FirebaseService {
289-
constructor(private app_: FirebaseApp) {
290-
// empty
291-
}
296+
constructor(private app_: FirebaseApp, public instanceIdentifier?: string) {}
292297

293298
// TODO(koss): Shouldn't this just be an added method on
294299
// the service instance?

0 commit comments

Comments
 (0)