Skip to content

Commit 725ab46

Browse files
authored
Pass the instance to onInit callback (#5023)
* pass the instance to onInit callback * add a test for instance passing * Create sharp-pans-share.md
1 parent 403ee06 commit 725ab46

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.changeset/sharp-pans-share.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/component": patch
3+
---
4+
5+
Pass the instance to onInit callback

packages/component/src/provider.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ describe('Provider', () => {
197197
expect(callback).to.have.been.calledOnce;
198198
});
199199

200+
it('passes service instance', () => {
201+
const serviceInstance = { test: true };
202+
provider.setComponent(getFakeComponent('test', () => serviceInstance));
203+
const callback = fake();
204+
205+
// initialize the service instance
206+
provider.getImmediate();
207+
208+
provider.onInit(callback);
209+
210+
expect(callback).to.have.been.calledOnce;
211+
expect(callback).to.have.been.calledWith(serviceInstance);
212+
});
213+
200214
it('passes instance identifier', () => {
201215
provider.setComponent(
202216
getFakeComponent(

packages/component/src/provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export class Provider<T extends Name> {
272272
existingCallbacks.add(callback);
273273
this.onInitCallbacks.set(normalizedIdentifier, existingCallbacks);
274274

275-
const existingInstance = this.instances.has(normalizedIdentifier);
275+
const existingInstance = this.instances.get(normalizedIdentifier);
276276
if (existingInstance) {
277277
callback(existingInstance, normalizedIdentifier);
278278
}

0 commit comments

Comments
 (0)