Skip to content

Commit

Permalink
feat(functions): Support region configuration via FunctionsRegionToken
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels committed Oct 19, 2018
1 parent cfb92e5 commit 8901617
Show file tree
Hide file tree
Showing 4 changed files with 969 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/firebase.app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class FirebaseApp implements app.App {
storage: (storageBucket?: string) => FirebaseStorage;
delete: () => Promise<void>;
firestore: () => FirebaseFirestore;
functions: () => FirebaseFunctions;
functions: (region?: string) => FirebaseFunctions;
}

export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig) {
Expand Down
9 changes: 7 additions & 2 deletions src/functions/functions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReflectiveInjector, Provider } from '@angular/core';
import { TestBed, inject } from '@angular/core/testing';
import { FirebaseApp, FirebaseOptionsToken, AngularFireModule, FirebaseNameOrConfigToken } from '@angular/fire';
import { AngularFireFunctions, AngularFireFunctionsModule } from '@angular/fire/functions';
import { AngularFireFunctions, AngularFireFunctionsModule, FunctionsRegionToken } from '@angular/fire/functions';
import { COMMON_CONFIG } from './test-config';

describe('AngularFireFunctions', () => {
Expand Down Expand Up @@ -50,7 +50,8 @@ describe('AngularFireFunctions with different app', () => {
],
providers: [
{ provide: FirebaseNameOrConfigToken, useValue: FIREBASE_APP_NAME_TOO },
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG }
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG },
{ provide: FunctionsRegionToken, useValue: 'asia-northeast1' },
]
});
inject([FirebaseApp, AngularFireFunctions], (app_: FirebaseApp, _fns: AngularFireFunctions) => {
Expand All @@ -70,6 +71,10 @@ describe('AngularFireFunctions with different app', () => {
expect(afFns instanceof AngularFireFunctions).toEqual(true);
});

it('should have the Firebase Functions instance', () => {
expect(afFns.functions).toBeDefined();
});

});

});
11 changes: 6 additions & 5 deletions src/functions/functions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID } from '@angular/core';
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID, InjectionToken } from '@angular/core';
import { Observable, from } from 'rxjs';
import { map } from 'rxjs/operators';

import { FirebaseOptions, FirebaseAppConfig } from '@angular/fire';

import { FirebaseFunctions, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from '@angular/fire';

export const FunctionsRegionToken = new InjectionToken<string>('angularfire2.functions.region');

@Injectable()
export class AngularFireFunctions {

Expand All @@ -20,13 +20,14 @@ export class AngularFireFunctions {
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|undefined,
@Inject(PLATFORM_ID) platformId: Object,
zone: NgZone
zone: NgZone,
@Optional() @Inject(FunctionsRegionToken) region:string|undefined
) {
this.scheduler = new FirebaseZoneScheduler(zone, platformId);

this.functions = zone.runOutsideAngular(() => {
const app = _firebaseAppFactory(options, nameOrConfig);
return app.functions();
return app.functions(region);
});

}
Expand Down
Loading

0 comments on commit 8901617

Please sign in to comment.