Skip to content

Commit 56bbdee

Browse files
committed
address comments
1 parent af4fdc4 commit 56bbdee

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

packages/component/src/component.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import { InstantiationMode, InstanceFactory, ComponentType } from './types';
17+
import { InstantiationMode, InstanceFactory, ComponentType, Dictionary } from './types';
1818

1919
export class Component<T = unknown> {
20-
multipleInstances: boolean = false;
20+
multipleInstances = false;
2121
/**
2222
* Properties to be added to the service namespace
2323
*/
24-
serviceProps: { [key: string]: unknown } = {};
24+
serviceProps: Dictionary = {};
2525

26-
instantiationMode: InstantiationMode = InstantiationMode.LAZY;
26+
instantiationMode = InstantiationMode.LAZY;
2727

2828
/**
2929
*
@@ -32,9 +32,9 @@ export class Component<T = unknown> {
3232
* @param type whehter the service provided by the component is public or private
3333
*/
3434
constructor(
35-
public readonly name: string,
36-
public readonly instanceFactory: InstanceFactory<T>,
37-
public readonly type: ComponentType
35+
readonly name: string,
36+
readonly instanceFactory: InstanceFactory<T>,
37+
readonly type: ComponentType
3838
) {}
3939

4040
setInstantiationMode(mode: InstantiationMode): this {
@@ -47,7 +47,7 @@ export class Component<T = unknown> {
4747
return this;
4848
}
4949

50-
setServiceProps(props: { [key: string]: unknown }): this {
50+
setServiceProps(props: Dictionary): this {
5151
this.serviceProps = props;
5252
return this;
5353
}

packages/component/src/component_container.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Component Container', () => {
3838
const provider1 = container.getProvider('ship');
3939
const provider2 = container.getProvider('ship');
4040

41-
expect(provider1).to.eq(provider2);
41+
expect(provider1).to.equal(provider2);
4242
});
4343

4444
it('calls setComponent() on provider with the same name when registering a component', () => {

packages/component/src/component_container.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ import { Provider } from './provider';
1919
import { Component } from './component';
2020

2121
export class ComponentContainer {
22-
private providers = new Map<string, Provider>();
22+
private readonly providers = new Map<string, Provider>();
2323

24-
constructor(private name: string) {}
24+
constructor(private readonly name: string) {}
2525

2626
/**
2727
*
2828
* @param component Component being added
2929
* @param overwrite When a component with the same name has already been registered,
30-
* if overwrite is true: overwrite the existing component with the new component and create a new provider with the new component
31-
* if overwrite is false: throw an expection
30+
* if overwrite is true: overwrite the existing component with the new component and create a new
31+
* provider with the new component. It can be useful in tests where you want to use different mocks
32+
* for different tests.
33+
* if overwrite is false: throw an exception
3234
*/
3335
addComponent(component: Component, overwrite = false): void {
3436
let provider = this.getProvider(component.name);
@@ -62,6 +64,6 @@ export class ComponentContainer {
6264
}
6365

6466
getProviders(): Provider[] {
65-
return Array.from(this.providers, entry => entry[1]);
67+
return Array.from(this.providers.values());
6668
}
6769
}

packages/component/src/provider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ describe('Provider', () => {
302302
// eslint-disable-next-line @typescript-eslint/no-floating-promises
303303
provider.delete();
304304

305-
expect(deleteFakes.length).to.eq(2);
305+
expect(deleteFakes.length).to.equal(2);
306306
for (const f of deleteFakes) {
307307
expect(f).to.have.been.called;
308308
}

packages/component/src/provider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import { Component } from './component';
2626
*/
2727
export class Provider<T = unknown> {
2828
private component: Component<T> | null = null;
29-
private instances: Map<string, T> = new Map();
30-
private instancesDeferred: Map<string, Deferred<T>> = new Map();
29+
private readonly instances: Map<string, T> = new Map();
30+
private readonly instancesDeferred: Map<string, Deferred<T>> = new Map();
3131

32-
constructor(private name: string, private container: ComponentContainer) {}
32+
constructor(private readonly name: string, private readonly container: ComponentContainer) {}
3333

3434
get(identifier: string = DEFAULT_ENTRY_NAME): Promise<T> {
3535
// if multipleInstances is not supported, use the default name
@@ -114,10 +114,10 @@ export class Provider<T = unknown> {
114114

115115
// app.delete() will call this method on every provider to delete the services
116116
// TODO: should we mark the provider as deleted?
117-
delete(): Promise<unknown[]> {
117+
async delete(): Promise<void> {
118118
const services = Array.from(this.instances.values());
119119

120-
return Promise.all(
120+
await Promise.all(
121121
services
122122
.filter(service => 'INTERNAL' in service)
123123
// eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/component/src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const enum InstantiationMode {
3030
* PRIVATE: A private component provides a set of private APIs that are used internally by other
3131
* Firebase SDKs. No serivce namespace is created in `firebase` namespace and customers have no way to get them.
3232
*/
33-
export enum ComponentType {
33+
export const enum ComponentType {
3434
PUBLIC = 'PUBLIC',
3535
PRIVATE = 'PRIVARE'
3636
}
@@ -47,3 +47,7 @@ export type InstanceFactory<T = unknown> = (
4747
container: ComponentContainer,
4848
instanceIdentifier?: string
4949
) => T;
50+
51+
export type Dictionary = {
52+
[key: string]: unknown
53+
};

0 commit comments

Comments
 (0)