Skip to content

Commit 7921520

Browse files
chore(lint): Misc fixes
1 parent 6246b16 commit 7921520

File tree

7 files changed

+133
-101
lines changed

7 files changed

+133
-101
lines changed

src/auth/auth.spec.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,35 +76,43 @@ describe('AngularFireAuth', () => {
7676
let count = 0;
7777

7878
// Check that the first value is null and second is the auth user
79-
const subs = afAuth.authState.subscribe(user => {
80-
if (count === 0) {
81-
expect(user).toBe(null);
82-
count = count + 1;
83-
mockAuthState.next(firebaseUser);
84-
} else {
85-
expect(user).toEqual(firebaseUser);
86-
subs.unsubscribe();
87-
done();
88-
}
89-
}, done, done.fail);
79+
const subs = afAuth.authState.subscribe({
80+
next: (user => {
81+
if (count === 0) {
82+
expect(user).toBe(null);
83+
count = count + 1;
84+
mockAuthState.next(firebaseUser);
85+
} else {
86+
expect(user).toEqual(firebaseUser);
87+
subs.unsubscribe();
88+
done();
89+
}
90+
}),
91+
error: done,
92+
complete: done.fail
93+
});
9094
mockAuthState.next(null);
9195
});
9296

9397
it('should emit auth updates through idToken', (done: any) => {
9498
let count = 0;
9599

96100
// Check that the first value is null and second is the auth user
97-
const subs = afAuth.idToken.subscribe(user => {
98-
if (count === 0) {
99-
expect(user).toBe(null);
100-
count = count + 1;
101-
mockAuthState.next(firebaseUser);
102-
} else {
103-
expect(user as any).toEqual(firebaseUser);
104-
subs.unsubscribe();
105-
done();
106-
}
107-
}, done, done.fail);
101+
const subs = afAuth.idToken.subscribe({
102+
next: user => {
103+
if (count === 0) {
104+
expect(user).toBe(null);
105+
count = count + 1;
106+
mockAuthState.next(firebaseUser);
107+
} else {
108+
expect(user as any).toEqual(firebaseUser);
109+
subs.unsubscribe();
110+
done();
111+
}
112+
},
113+
error: done,
114+
complete: done.fail
115+
});
108116
mockAuthState.next(null);
109117
});
110118

src/auth/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class AngularFireAuth {
4646
constructor(
4747
@Inject(FIREBASE_OPTIONS) options: FirebaseOptions,
4848
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string|FirebaseAppConfig|null|undefined,
49+
// tslint:disable-next-line:ban-types
4950
@Inject(PLATFORM_ID) platformId: Object,
5051
zone: NgZone
5152
) {

src/core/firebase.app.module.ts

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,74 @@ import * as firebase from 'firebase/app';
33
import { analytics, app, auth, database, firestore, functions, messaging, performance, remoteConfig, storage } from 'firebase/app';
44

55
// INVESTIGATE Public types don't expose FirebaseOptions or FirebaseAppConfig, is this the case anylonger?
6-
export interface FirebaseOptions {[key: string]: any; }
7-
export interface FirebaseAppConfig {[key: string]: any; }
6+
export interface FirebaseOptions {
7+
[key: string]: any;
8+
}
9+
10+
export interface FirebaseAppConfig {
11+
[key: string]: any;
12+
}
813

914
export const FIREBASE_OPTIONS = new InjectionToken<FirebaseOptions>('angularfire2.app.options');
10-
export const FIREBASE_APP_NAME = new InjectionToken<string|FirebaseAppConfig|undefined>('angularfire2.app.nameOrConfig');
15+
export const FIREBASE_APP_NAME = new InjectionToken<string | FirebaseAppConfig | undefined>('angularfire2.app.nameOrConfig');
1116

1217
// Have to implement as we need to return a class from the provider, we should consider exporting
1318
// this in the firebase/app types as this is our highest risk of breaks
1419
export class FirebaseApp implements Partial<app.App> {
15-
name: string;
16-
options: {};
17-
analytics: () => analytics.Analytics;
18-
auth: () => auth.Auth;
19-
database: (databaseURL?: string) => database.Database;
20-
messaging: () => messaging.Messaging;
21-
performance: () => performance.Performance;
22-
storage: (storageBucket?: string) => storage.Storage;
23-
delete: () => Promise<void>;
24-
firestore: () => firestore.Firestore;
25-
functions: (region?: string) => functions.Functions;
26-
remoteConfig: () => remoteConfig.RemoteConfig;
20+
name: string;
21+
options: {};
22+
analytics: () => analytics.Analytics;
23+
auth: () => auth.Auth;
24+
database: (databaseURL?: string) => database.Database;
25+
messaging: () => messaging.Messaging;
26+
performance: () => performance.Performance;
27+
storage: (storageBucket?: string) => storage.Storage;
28+
delete: () => Promise<void>;
29+
firestore: () => firestore.Firestore;
30+
functions: (region?: string) => functions.Functions;
31+
remoteConfig: () => remoteConfig.RemoteConfig;
2732
}
2833

2934
export const VERSION = new Version('ANGULARFIRE2_VERSION');
3035

31-
export function ɵfirebaseAppFactory(options: FirebaseOptions, zone: NgZone, nameOrConfig?: string|FirebaseAppConfig|null) {
32-
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
33-
const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
34-
config.name = config.name || name;
35-
// Added any due to some inconsistency between @firebase/app and firebase types
36-
const existingApp = firebase.apps.filter(app => app && app.name === config.name)[0] as any;
37-
// We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
38-
// Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206
39-
return (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config as any))) as FirebaseApp;
36+
export function ɵfirebaseAppFactory(options: FirebaseOptions, zone: NgZone, nameOrConfig?: string | FirebaseAppConfig | null) {
37+
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
38+
const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
39+
config.name = config.name || name;
40+
// Added any due to some inconsistency between @firebase/app and firebase types
41+
const existingApp = firebase.apps.filter(app => app && app.name === config.name)[0] as any;
42+
// We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
43+
// Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206
44+
return (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config as any))) as FirebaseApp;
4045
}
4146

4247
const FirebaseAppProvider = {
43-
provide: FirebaseApp,
44-
useFactory: ɵfirebaseAppFactory,
45-
deps: [
46-
FIREBASE_OPTIONS,
47-
NgZone,
48-
[new Optional(), FIREBASE_APP_NAME]
49-
]
48+
provide: FirebaseApp,
49+
useFactory: ɵfirebaseAppFactory,
50+
deps: [
51+
FIREBASE_OPTIONS,
52+
NgZone,
53+
[new Optional(), FIREBASE_APP_NAME]
54+
]
5055
};
5156

5257
@NgModule({
53-
providers: [ FirebaseAppProvider ],
58+
providers: [FirebaseAppProvider]
5459
})
5560
export class AngularFireModule {
56-
static initializeApp(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig) {
57-
return {
58-
ngModule: AngularFireModule,
59-
providers: [
60-
{ provide: FIREBASE_OPTIONS, useValue: options },
61-
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }
62-
]
63-
};
64-
}
65-
constructor(@Inject(PLATFORM_ID) platformId: Object ) {
66-
firebase.registerVersion('angularfire', VERSION.full, platformId.toString());
67-
firebase.registerVersion('angular', NG_VERSION.full);
68-
}
61+
static initializeApp(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig) {
62+
return {
63+
ngModule: AngularFireModule,
64+
providers: [
65+
{ provide: FIREBASE_OPTIONS, useValue: options },
66+
{ provide: FIREBASE_APP_NAME, useValue: nameOrConfig }
67+
]
68+
};
69+
}
70+
71+
// tslint:disable-next-line:ban-types
72+
constructor(@Inject(PLATFORM_ID) platformId: Object) {
73+
firebase.registerVersion('angularfire', VERSION.full, platformId.toString());
74+
firebase.registerVersion('angular', NG_VERSION.full);
75+
}
6976
}

src/firestore/observable/fromRef.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function _fromRef<T, R>(ref: Reference<T>, scheduler: SchedulerLike = asyncSched
1313
unsubscribe = ref.onSnapshot(subscriber);
1414
}
1515

16-
return function() {
16+
return () => {
1717
if (unsubscribe != null) {
1818
unsubscribe();
1919
}

src/functions/functions.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
import { Inject, Injectable, InjectionToken, NgZone, Optional } from '@angular/core';
22
import { from, Observable, of } from 'rxjs';
33
import { map, observeOn, shareReplay, switchMap, tap } from 'rxjs/operators';
4-
import { FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseAppConfig, FirebaseOptions, ɵAngularFireSchedulers, ɵfirebaseAppFactory, ɵlazySDKProxy, ɵPromiseProxy } from '@angular/fire';
4+
import {
5+
FIREBASE_APP_NAME,
6+
FIREBASE_OPTIONS,
7+
FirebaseAppConfig,
8+
FirebaseOptions,
9+
ɵAngularFireSchedulers,
10+
ɵfirebaseAppFactory,
11+
ɵlazySDKProxy,
12+
ɵPromiseProxy
13+
} from '@angular/fire';
514
import { functions } from 'firebase/app';
615

716
export const ORIGIN = new InjectionToken<string>('angularfire2.functions.origin');
817
export const REGION = new InjectionToken<string>('angularfire2.functions.region');
918

1019
// override httpsCallable for compatibility with 5.x
11-
export interface AngularFireFunctions extends Omit<ɵPromiseProxy<functions.Functions>, 'httpsCallable'> { }
20+
export interface AngularFireFunctions extends Omit<ɵPromiseProxy<functions.Functions>, 'httpsCallable'> {
21+
}
1222

1323
@Injectable({
1424
providedIn: 'any'
1525
})
1626
export class AngularFireFunctions {
1727

18-
public readonly httpsCallable: <T= any, R= any>(name: string) => (data: T) => Observable<R>;
28+
public readonly httpsCallable: <T = any, R = any>(name: string) => (data: T) => Observable<R>;
1929

2030
constructor(
2131
@Inject(FIREBASE_OPTIONS) options: FirebaseOptions,
22-
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string|FirebaseAppConfig|null|undefined,
32+
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string | FirebaseAppConfig | null | undefined,
2333
zone: NgZone,
24-
@Optional() @Inject(REGION) region: string|null,
25-
@Optional() @Inject(ORIGIN) origin: string|null
34+
@Optional() @Inject(REGION) region: string | null,
35+
@Optional() @Inject(ORIGIN) origin: string | null
2636
) {
2737
const schedulers = new ɵAngularFireSchedulers(zone);
2838

@@ -32,12 +42,14 @@ export class AngularFireFunctions {
3242
map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)),
3343
map(app => app.functions(region || undefined)),
3444
tap(functions => {
35-
if (origin) { functions.useFunctionsEmulator(origin); }
45+
if (origin) {
46+
functions.useFunctionsEmulator(origin);
47+
}
3648
}),
37-
shareReplay({ bufferSize: 1, refCount: false }),
49+
shareReplay({ bufferSize: 1, refCount: false })
3850
);
3951

40-
this.httpsCallable = <T= any, R= any>(name: string) =>
52+
this.httpsCallable = <T = any, R = any>(name: string) =>
4153
(data: T) => from(functions).pipe(
4254
observeOn(schedulers.outsideAngular),
4355
switchMap(functions => functions.httpsCallable(name)(data)),

src/remote-config/remote-config.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export const DEFAULTS = new InjectionToken<ConfigTemplate>('angularfire2.remoteC
1515
export interface AngularFireRemoteConfig extends ɵPromiseProxy<remoteConfig.RemoteConfig> {
1616
}
1717

18+
const AS_TO_FN = { strings: 'asString', numbers: 'asNumber', booleans: 'asBoolean' };
19+
const STATIC_VALUES = { numbers: 0, booleans: false, strings: undefined };
20+
1821
// TODO look into the types here, I don't like the anys
1922
const proxyAll = (observable: Observable<Parameter[]>, as: 'numbers' | 'booleans' | 'strings') => new Proxy(
2023
observable.pipe(mapToObject(as as any)), {
@@ -66,6 +69,30 @@ export const filterRemote = () => filterTest(p => p.getSource() === 'remote');
6669
// filterFresh allows the developer to effectively set up a maximum cache time
6770
export const filterFresh = (howRecentInMillis: number) => filterTest(p => p.fetchTimeMillis + howRecentInMillis >= new Date().getTime());
6871

72+
73+
// I ditched loading the defaults into RC and a simple map for scan since we already have our own defaults implementation.
74+
// The idea here being that if they have a default that never loads from the server, they will be able to tell via fetchTimeMillis
75+
// on the Parameter. Also if it doesn't come from the server it won't emit again in .changes, due to the distinctUntilChanged,
76+
// which we can simplify to === rather than deep comparison
77+
const scanToParametersArray = (
78+
remoteConfig: Observable<remoteConfig.RemoteConfig | undefined>
79+
): OperatorFunction<{ [key: string]: remoteConfig.Value }, Parameter[]> => pipe(
80+
withLatestFrom(remoteConfig),
81+
scan((existing, [all, rc]) => {
82+
// SEMVER use "new Set" to unique once we're only targeting es6
83+
// at the scale we expect remote config to be at, we probably won't see a performance hit from this unoptimized uniqueness
84+
// implementation.
85+
// const allKeys = [...new Set([...existing.map(p => p.key), ...Object.keys(all)])];
86+
const allKeys = [...existing.map(p => p.key), ...Object.keys(all)].filter((v, i, a) => a.indexOf(v) === i);
87+
return allKeys.map(key => {
88+
const updatedValue = all[key];
89+
return updatedValue ? new Parameter(key, rc ? rc.fetchTimeMillis : -1, updatedValue.getSource(), updatedValue.asString())
90+
: existing.find(p => p.key === key);
91+
});
92+
}, [] as Array<Parameter>)
93+
);
94+
95+
6996
@Injectable({
7097
providedIn: 'any'
7198
})
@@ -162,28 +189,6 @@ export class AngularFireRemoteConfig {
162189

163190
}
164191

165-
// I ditched loading the defaults into RC and a simple map for scan since we already have our own defaults implementation.
166-
// The idea here being that if they have a default that never loads from the server, they will be able to tell via fetchTimeMillis
167-
// on the Parameter. Also if it doesn't come from the server it won't emit again in .changes, due to the distinctUntilChanged,
168-
// which we can simplify to === rather than deep comparison
169-
const scanToParametersArray = (
170-
remoteConfig: Observable<remoteConfig.RemoteConfig | undefined>
171-
): OperatorFunction<{ [key: string]: remoteConfig.Value }, Parameter[]> => pipe(
172-
withLatestFrom(remoteConfig),
173-
scan((existing, [all, rc]) => {
174-
// SEMVER use "new Set" to unique once we're only targeting es6
175-
// at the scale we expect remote config to be at, we probably won't see a performance hit from this unoptimized uniqueness
176-
// implementation.
177-
// const allKeys = [...new Set([...existing.map(p => p.key), ...Object.keys(all)])];
178-
const allKeys = [...existing.map(p => p.key), ...Object.keys(all)].filter((v, i, a) => a.indexOf(v) === i);
179-
return allKeys.map(key => {
180-
const updatedValue = all[key];
181-
return updatedValue ? new Parameter(key, rc ? rc.fetchTimeMillis : -1, updatedValue.getSource(), updatedValue.asString())
182-
: existing.find(p => p.key === key);
183-
});
184-
}, [] as Array<Parameter>)
185-
);
186-
187192

188193
export const budget = <T>(interval: number): MonoTypeOperatorFunction<T> => (source: Observable<T>) => new Observable<T>(observer => {
189194
let timedOut = false;
@@ -226,8 +231,6 @@ const typedMethod = (it: any) => {
226231
}
227232
};
228233

229-
const AS_TO_FN = { strings: 'asString', numbers: 'asNumber', booleans: 'asBoolean' };
230-
const STATIC_VALUES = { numbers: 0, booleans: false, strings: undefined };
231234

232235
export function scanToObject(): OperatorFunction<Parameter, { [key: string]: string | undefined }>;
233236
export function scanToObject(to: 'numbers'): OperatorFunction<Parameter, { [key: string]: number | undefined }>;

src/schematics/ng-add-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function generateFirebaseRc(
7676

7777
export function safeReadJSON(path: string, tree: Tree) {
7878
try {
79+
// tslint:disable-next-line:no-non-null-assertion
7980
return JSON.parse(tree.read(path)!.toString());
8081
} catch (e) {
8182
throw new SchematicsException(`Error when parsing ${path}: ${e.message}`);

0 commit comments

Comments
 (0)