Skip to content

Commit

Permalink
Pass the instance to onInit callback (#5023)
Browse files Browse the repository at this point in the history
* pass the instance to onInit callback

* add a test for instance passing

* Create sharp-pans-share.md
  • Loading branch information
Feiyang1 authored Jun 15, 2021
1 parent 403ee06 commit 725ab46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sharp-pans-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/component": patch
---

Pass the instance to onInit callback
14 changes: 14 additions & 0 deletions packages/component/src/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ describe('Provider', () => {
expect(callback).to.have.been.calledOnce;
});

it('passes service instance', () => {
const serviceInstance = { test: true };
provider.setComponent(getFakeComponent('test', () => serviceInstance));
const callback = fake();

// initialize the service instance
provider.getImmediate();

provider.onInit(callback);

expect(callback).to.have.been.calledOnce;
expect(callback).to.have.been.calledWith(serviceInstance);
});

it('passes instance identifier', () => {
provider.setComponent(
getFakeComponent(
Expand Down
2 changes: 1 addition & 1 deletion packages/component/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class Provider<T extends Name> {
existingCallbacks.add(callback);
this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);

const existingInstance = this.instances.has(normalizedIdentifier);
const existingInstance = this.instances.get(normalizedIdentifier);
if (existingInstance) {
callback(existingInstance, normalizedIdentifier);
}
Expand Down

0 comments on commit 725ab46

Please sign in to comment.