Skip to content

Commit 086df99

Browse files
committed
[AUTOMATED]: Prettier Code Styling
1 parent 8c172b8 commit 086df99

File tree

3 files changed

+40
-44
lines changed

3 files changed

+40
-44
lines changed

packages/component/src/provider.test.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ describe('Provider', () => {
4949
});
5050

5151
it('returns null if the service is not available with optional flag', () => {
52-
expect(provider.getImmediate({ optional: true })).to.equal(
53-
null
54-
);
52+
expect(provider.getImmediate({ optional: true })).to.equal(null);
5553
});
5654

5755
it('returns the service instance synchronously', () => {
@@ -69,8 +67,12 @@ describe('Provider', () => {
6967
it('ignores parameter identifier and return the default service', () => {
7068
provider.setComponent(getFakeComponent('test', () => ({ test: true })));
7169
const defaultService = provider.getImmediate();
72-
expect(provider.getImmediate({identifier: 'spider1'})).to.equal(defaultService);
73-
expect(provider.getImmediate({identifier: 'spider2'})).to.equal(defaultService);
70+
expect(provider.getImmediate({ identifier: 'spider1' })).to.equal(
71+
defaultService
72+
);
73+
expect(provider.getImmediate({ identifier: 'spider2' })).to.equal(
74+
defaultService
75+
);
7476
});
7577
});
7678

@@ -187,22 +189,24 @@ describe('Provider', () => {
187189
describe('Provider (multipleInstances = true)', () => {
188190
describe('getImmediate(identifier)', () => {
189191
it('throws if the service is not available', () => {
190-
expect(provider.getImmediate.bind(provider, {identifier: 'guardian'})).to.throw();
192+
expect(
193+
provider.getImmediate.bind(provider, { identifier: 'guardian' })
194+
).to.throw();
191195
});
192196

193197
it('returns null if the service is not available with optional flag', () => {
194-
expect(provider.getImmediate({ identifier: 'guardian', optional: true })).to.equal(
195-
null
196-
);
198+
expect(
199+
provider.getImmediate({ identifier: 'guardian', optional: true })
200+
).to.equal(null);
197201
});
198202

199203
it('returns different service instances for different identifiers synchronously', () => {
200204
provider.setComponent(
201205
getFakeComponent('test', () => ({ test: true }), true)
202206
);
203207
const defaultService = provider.getImmediate();
204-
const service1 = provider.getImmediate({identifier: 'guardian'});
205-
const service2 = provider.getImmediate({identifier: 'servant'});
208+
const service1 = provider.getImmediate({ identifier: 'guardian' });
209+
const service2 = provider.getImmediate({ identifier: 'servant' });
206210

207211
expect(defaultService).to.deep.equal({ test: true });
208212
expect(service1).to.deep.equal({ test: true });
@@ -296,8 +300,8 @@ describe('Provider', () => {
296300
provider.setComponent(getFakeComponent('test', getService, true));
297301

298302
// create 2 service instances with different names
299-
provider.getImmediate({identifier: 'instance1'});
300-
provider.getImmediate({identifier: 'instance2'});
303+
provider.getImmediate({ identifier: 'instance1' });
304+
provider.getImmediate({ identifier: 'instance2' });
301305

302306
// eslint-disable-next-line @typescript-eslint/no-floating-promises
303307
provider.delete();
@@ -313,7 +317,7 @@ describe('Provider', () => {
313317
provider.setComponent(getFakeComponent('test', () => ({}), true));
314318
// create serviec instances with different identifiers
315319
const defaultInstance = provider.getImmediate();
316-
const instance1 = provider.getImmediate({identifier: 'instance1'});
320+
const instance1 = provider.getImmediate({ identifier: 'instance1' });
317321

318322
expect((provider as any).instances.size).to.equal(2);
319323

@@ -327,7 +331,7 @@ describe('Provider', () => {
327331
// remove the named instance from cache and create a new instance with the same identifier
328332
provider.clearInstance('instance1');
329333
expect((provider as any).instances.size).to.equal(1);
330-
const newInstance1 = provider.getImmediate({identifier: 'instance1'});
334+
const newInstance1 = provider.getImmediate({ identifier: 'instance1' });
331335
expect(newInstance1).to.not.eq(instance1);
332336
expect((provider as any).instances.size).to.equal(2);
333337
});

packages/component/src/provider.ts

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export class Provider<T = unknown> {
3232
constructor(
3333
private readonly name: string,
3434
private readonly container: ComponentContainer
35-
) { }
35+
) {}
3636

3737
/**
38-
* @param identifier A provider can provide mulitple instances of a service
38+
* @param identifier A provider can provide mulitple instances of a service
3939
* if this.component.multipleInstances is true.
4040
*/
4141
get(identifier: string = DEFAULT_ENTRY_NAME): Promise<T> {
@@ -55,33 +55,25 @@ export class Provider<T = unknown> {
5555
return this.instancesDeferred.get(normalizedIdentifier)!.promise;
5656
}
5757

58-
/**
59-
*
60-
* @param options.identifier A provider can provide mulitple instances of a service
58+
/**
59+
*
60+
* @param options.identifier A provider can provide mulitple instances of a service
6161
* if this.component.multipleInstances is true.
62-
* @param options.optional If optional is false or not provided, the method throws an error when
63-
* the service is not immediately available.
64-
* If optional is true, the method returns null if the service is not immediately available.
65-
*/
66-
getImmediate(
67-
options: {
68-
identifier?: string
69-
optional: true
70-
}
71-
): T | null;
72-
getImmediate(
73-
options?: {
74-
identifier?: string,
75-
optional?: false
76-
}): T;
77-
getImmediate(
78-
options?: {
79-
identifier?: string,
80-
optional?: boolean
81-
}
82-
): T | null {
83-
84-
const { identifier, optional } = { identifier: DEFAULT_ENTRY_NAME, optional: false, ...options };
62+
* @param options.optional If optional is false or not provided, the method throws an error when
63+
* the service is not immediately available.
64+
* If optional is true, the method returns null if the service is not immediately available.
65+
*/
66+
getImmediate(options: { identifier?: string; optional: true }): T | null;
67+
getImmediate(options?: { identifier?: string; optional?: false }): T;
68+
getImmediate(options?: {
69+
identifier?: string;
70+
optional?: boolean;
71+
}): T | null {
72+
const { identifier, optional } = {
73+
identifier: DEFAULT_ENTRY_NAME,
74+
optional: false,
75+
...options
76+
};
8577
// if multipleInstances is not supported, use the default name
8678
const normalizedIdentifier = this.normalizeInstanceIdentifier(identifier);
8779

packages/component/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ export type InstanceFactory<T = unknown> = (
5050

5151
export interface Dictionary {
5252
[key: string]: unknown;
53-
};
53+
}

0 commit comments

Comments
 (0)