Skip to content

Commit

Permalink
fix(app): fix issue where instanceIdentifier wasn't being passed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jshcrowthe committed May 25, 2017
1 parent 3e211b3 commit ba477fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app/firebase_app.ts
Expand Up @@ -303,7 +303,7 @@ class FirebaseAppImpl implements FirebaseApp {
}

if (!this.services_[name][instanceIdentifier]) {
let service = this.firebase_.INTERNAL.factories[name](this, this.extendApp.bind(this));
let service = this.firebase_.INTERNAL.factories[name](this, this.extendApp.bind(this), instanceIdentifier);
this.services_[name][instanceIdentifier] = service;
}

Expand Down
15 changes: 10 additions & 5 deletions tests/app/unit/firebase_app.test.ts
Expand Up @@ -232,7 +232,10 @@ describe("Firebase App Class", () => {
// Register Multi Instance Service
firebase.INTERNAL.registerService(
'multiInstance',
app => new TestService(app),
(...args) => {
const [app,,instanceIdentifier] = args;
return new TestService(app, instanceIdentifier);
},
null,
null,
true
Expand All @@ -249,6 +252,7 @@ describe("Firebase App Class", () => {
assert.strictEqual(service2, (firebase.app() as any).multiInstance(serviceIdentifier));

// Ensure that the two services **are not equal**
assert.notStrictEqual(service.instanceIdentifier, service2.instanceIdentifier);
assert.notStrictEqual(service, service2);
assert.notStrictEqual((firebase.app() as any).multiInstance(), (firebase.app() as any).multiInstance(serviceIdentifier));
});
Expand All @@ -257,7 +261,10 @@ describe("Firebase App Class", () => {
// Register Multi Instance Service
firebase.INTERNAL.registerService(
'singleInstance',
app => new TestService(app),
(...args) => {
const [app,,instanceIdentifier] = args;
return new TestService(app, instanceIdentifier)
},
null,
null,
false // <-- multi instance flag
Expand Down Expand Up @@ -286,9 +293,7 @@ describe("Firebase App Class", () => {
});

class TestService implements FirebaseService {
constructor(private app_: FirebaseApp) {
// empty
}
constructor(private app_: FirebaseApp, public instanceIdentifier?: string) {}

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

0 comments on commit ba477fa

Please sign in to comment.