Skip to content

Commit 135e57a

Browse files
committed
let factory accept options
1 parent 8ba98cb commit 135e57a

File tree

14 files changed

+43
-26
lines changed

14 files changed

+43
-26
lines changed

packages-exp/analytics-compat/src/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@ declare module '@firebase/component' {
4141
}
4242

4343
const factory: InstanceFactory<'analytics-compat'> = (
44-
container: ComponentContainer,
45-
regionOrCustomDomain?: string
44+
container: ComponentContainer
4645
) => {
4746
// Dependencies
4847
const app = container.getProvider('app-compat').getImmediate();
4948
const analyticsServiceExp = container
5049
.getProvider('analytics-exp')
51-
.getImmediate({
52-
identifier: regionOrCustomDomain
53-
});
50+
.getImmediate();
5451

5552
return new AnalyticsService(app as FirebaseApp, analyticsServiceExp);
5653
};

packages-exp/functions-exp/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const DEFAULT_REGION = 'us-central1';
3030
export function registerFunctions(fetchImpl: typeof fetch): void {
3131
const factory: InstanceFactory<'functions'> = (
3232
container: ComponentContainer,
33-
regionOrCustomDomain?: string
33+
{ instanceIdentifier: regionOrCustomDomain }
3434
) => {
3535
// Dependencies
3636
const app = container.getProvider('app-exp').getImmediate();

packages-exp/remote-config-compat/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import firebase, { _FirebaseNamespace } from '@firebase/app-compat';
1919
import {
2020
Component,
2121
ComponentContainer,
22-
ComponentType
22+
ComponentType,
23+
InstanceFactoryOptions
2324
} from '@firebase/component';
2425
import { RemoteConfigCompatImpl } from './remoteConfig';
2526
import { name as packageName, version } from '../package.json';
@@ -48,7 +49,7 @@ function registerRemoteConfigCompat(
4849

4950
function remoteConfigFactory(
5051
container: ComponentContainer,
51-
namespace?: string
52+
{ instanceIdentifier: namespace }: InstanceFactoryOptions
5253
): RemoteConfigCompatImpl {
5354
const app = container.getProvider('app-compat').getImmediate();
5455
// The following call will always succeed because rc `import {...} from '@firebase/remote-config-exp'`

packages-exp/remote-config-exp/src/register.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
import {
2323
Component,
2424
ComponentType,
25-
ComponentContainer
25+
ComponentContainer,
26+
InstanceFactoryOptions
2627
} from '@firebase/component';
2728
import { Logger, LogLevel as FirebaseLogLevel } from '@firebase/logger';
2829
import { RemoteConfig } from './public_types';
@@ -53,7 +54,7 @@ export function registerRemoteConfig(): void {
5354

5455
function remoteConfigFactory(
5556
container: ComponentContainer,
56-
namespace?: string
57+
{ instanceIdentifier: namespace }: InstanceFactoryOptions
5758
): RemoteConfig {
5859
/* Dependencies */
5960
// getImmediate for FirebaseApp will always succeed

packages/component/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ export {
2323
InstanceFactory,
2424
InstantiationMode,
2525
NameServiceMapping,
26-
Name
26+
Name,
27+
InstanceFactoryOptions
2728
} from './src/types';

packages/component/src/provider.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,9 @@ export class Provider<T extends Name> {
195195
): NameServiceMapping[T] | null {
196196
let instance = this.instances.get(identifier);
197197
if (!instance && this.component) {
198-
instance = this.component.instanceFactory(
199-
this.container,
200-
normalizeIdentifierForFactory(identifier)
201-
) as NameServiceMapping[T];
198+
instance = this.component.instanceFactory(this.container, {
199+
instanceIdentifier: normalizeIdentifierForFactory(identifier)
200+
}) as NameServiceMapping[T];
202201
this.instances.set(identifier, instance);
203202
}
204203

packages/component/src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export const enum ComponentType {
3636
VERSION = 'VERSION'
3737
}
3838

39+
export interface InstanceFactoryOptions {
40+
instanceIdentifier?: string;
41+
options?: Record<string, unknown>;
42+
}
43+
3944
/**
4045
* Factory to create an instance of type T, given a ComponentContainer.
4146
* ComponentContainer is the IOC container that provides {@link Provider}
@@ -46,7 +51,7 @@ export const enum ComponentType {
4651
*/
4752
export type InstanceFactory<T extends Name> = (
4853
container: ComponentContainer,
49-
instanceIdentifier?: string
54+
options: InstanceFactoryOptions
5055
) => NameServiceMapping[T];
5156

5257
export interface Dictionary {

packages/database/exp/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function registerDatabase(): void {
3535
_registerComponent(
3636
new Component(
3737
'database-exp',
38-
(container, url) => {
38+
(container, { instanceIdentifier: url }) => {
3939
const app = container.getProvider('app-exp').getImmediate()!;
4040
const authProvider = container.getProvider('auth-internal');
4141
return new FirebaseDatabase(app, authProvider, url);

packages/database/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function registerDatabase(instance: FirebaseNamespace) {
4444
const namespace = (instance as _FirebaseNamespace).INTERNAL.registerComponent(
4545
new Component(
4646
'database',
47-
(container, url) => {
47+
(container, { instanceIdentifier: url }) => {
4848
/* Dependencies */
4949
// getImmediate for FirebaseApp will always succeed
5050
const app = container.getProvider('app').getImmediate();

packages/firestore/src/exp/database.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ export function initializeFirestore(
128128
);
129129
}
130130

131+
/**
132+
* create a firestore instance with the default settings
133+
*/
131134
const firestore = provider.getImmediate() as FirebaseFirestore;
132135
if (
133136
settings.cacheSizeBytes !== undefined &&
@@ -140,6 +143,9 @@ export function initializeFirestore(
140143
);
141144
}
142145

146+
/**
147+
* update settings with the user supplied values on the firestore instance
148+
*/
143149
firestore._setSettings(settings);
144150
return firestore;
145151
}

packages/functions/src/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { Service } from './api/service';
1919
import {
2020
Component,
2121
ComponentType,
22-
ComponentContainer
22+
ComponentContainer,
23+
InstanceFactoryOptions
2324
} from '@firebase/component';
2425
import { _FirebaseNamespace } from '@firebase/app-types/private';
2526

@@ -39,7 +40,7 @@ export function registerFunctions(
3940

4041
function factory(
4142
container: ComponentContainer,
42-
regionOrCustomDomain?: string
43+
{ instanceIdentifier: regionOrCustomDomain }: InstanceFactoryOptions
4344
): Service {
4445
// Dependencies
4546
const app = container.getProvider('app').getImmediate();

packages/remote-config/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import { name as packageName, version } from './package.json';
3131
import {
3232
Component,
3333
ComponentType,
34-
ComponentContainer
34+
ComponentContainer,
35+
InstanceFactoryOptions
3536
} from '@firebase/component';
3637

3738
// Facilitates debugging by enabling settings changes without rebuilding asset.
@@ -59,7 +60,7 @@ export function registerRemoteConfig(
5960

6061
function remoteConfigFactory(
6162
container: ComponentContainer,
62-
namespace?: string
63+
{ instanceIdentifier: namespace }: InstanceFactoryOptions
6364
): RemoteConfig {
6465
/* Dependencies */
6566
// getImmediate for FirebaseApp will always succeed

packages/storage/compat/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import * as types from '@firebase/storage-types';
2828
import {
2929
Component,
3030
ComponentType,
31-
ComponentContainer
31+
ComponentContainer,
32+
InstanceFactoryOptions
3233
} from '@firebase/component';
3334

3435
import { name, version } from '../package.json';
@@ -40,7 +41,7 @@ const STORAGE_TYPE = 'storage';
4041

4142
function factory(
4243
container: ComponentContainer,
43-
url?: string
44+
{ instanceIdentifier: url }: InstanceFactoryOptions
4445
): types.FirebaseStorage {
4546
// Dependencies
4647
// TODO: This should eventually be 'app-compat'

packages/storage/exp/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import {
3333
Component,
3434
ComponentType,
3535
ComponentContainer,
36-
Provider
36+
Provider,
37+
InstanceFactoryOptions
3738
} from '@firebase/component';
3839

3940
import { name, version } from '../package.json';
@@ -295,7 +296,10 @@ export function getStorage(
295296
return storageInstance;
296297
}
297298

298-
function factory(container: ComponentContainer, url?: string): StorageService {
299+
function factory(
300+
container: ComponentContainer,
301+
{ instanceIdentifier: url }: InstanceFactoryOptions
302+
): StorageService {
299303
const app = container.getProvider('app-exp').getImmediate();
300304
const authProvider = container.getProvider('auth-internal');
301305

0 commit comments

Comments
 (0)