Skip to content

Commit 4d8707d

Browse files
chore(lint): Clean analytics + auth guard
1 parent 8ec82a3 commit 4d8707d

File tree

4 files changed

+50
-47
lines changed

4 files changed

+50
-47
lines changed

src/analytics/analytics.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class AngularFireAnalyticsModule {
1212
@Optional() userTracking: UserTrackingService
1313
) {
1414
// calling anything on analytics will eagerly load the SDK
15+
// tslint:disable-next-line:no-unused-expression
1516
analytics.app;
1617
}
1718
}

src/analytics/analytics.service.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ const SCREEN_INSTANCE_DELIMITER = '#';
2929

3030
const ANNOTATIONS = '__annotations__';
3131

32+
33+
// this is an INT64 in iOS/Android but use INT32 cause javascript
34+
let nextScreenInstanceID = Math.floor(Math.random() * (2 ** 32 - 1)) - 2 ** 31;
35+
36+
const knownScreenInstanceIDs: { [key: string]: number } = {};
37+
38+
const getScreenInstanceID = (params: { [key: string]: any }) => {
39+
// unique the screen class against the outlet name
40+
const screenInstanceKey = [
41+
params[SCREEN_CLASS_KEY],
42+
params[OUTLET_KEY]
43+
].join(SCREEN_INSTANCE_DELIMITER);
44+
if (knownScreenInstanceIDs.hasOwnProperty(screenInstanceKey)) {
45+
return knownScreenInstanceIDs[screenInstanceKey];
46+
} else {
47+
const ret = nextScreenInstanceID++;
48+
knownScreenInstanceIDs[screenInstanceKey] = ret;
49+
return ret;
50+
}
51+
};
52+
3253
@Injectable({
3354
providedIn: 'any'
3455
})
@@ -195,23 +216,3 @@ export class UserTrackingService implements OnDestroy {
195216
}
196217
}
197218
}
198-
199-
// this is an INT64 in iOS/Android but use INT32 cause javascript
200-
let nextScreenInstanceID = Math.floor(Math.random() * (2 ** 32 - 1)) - 2 ** 31;
201-
202-
const knownScreenInstanceIDs: { [key: string]: number } = {};
203-
204-
const getScreenInstanceID = (params: { [key: string]: any }) => {
205-
// unique the screen class against the outlet name
206-
const screenInstanceKey = [
207-
params[SCREEN_CLASS_KEY],
208-
params[OUTLET_KEY]
209-
].join(SCREEN_INSTANCE_DELIMITER);
210-
if (knownScreenInstanceIDs.hasOwnProperty(screenInstanceKey)) {
211-
return knownScreenInstanceIDs[screenInstanceKey];
212-
} else {
213-
const ret = nextScreenInstanceID++;
214-
knownScreenInstanceIDs[screenInstanceKey] = ret;
215-
return ret;
216-
}
217-
};

src/auth-guard/auth-guard.spec.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inject, TestBed } from '@angular/core/testing';
1+
import { TestBed } from '@angular/core/testing';
22
import { AngularFireModule, FirebaseApp } from '@angular/fire';
33
import { COMMON_CONFIG } from '../test-config';
44
import { AngularFireAuthGuard, AngularFireAuthGuardModule } from './public_api';
@@ -7,33 +7,32 @@ import { APP_BASE_HREF } from '@angular/common';
77
import { rando } from '../firestore/utils.spec';
88

99
describe('AngularFireAuthGuard', () => {
10-
let app: FirebaseApp;
11-
let router: Router;
10+
let app: FirebaseApp;
11+
let router: Router;
1212

13-
beforeEach(() => {
14-
TestBed.configureTestingModule({
15-
imports: [
16-
AngularFireModule.initializeApp(COMMON_CONFIG, rando()),
17-
AngularFireAuthGuardModule,
18-
RouterModule.forRoot([
19-
{ path: 'a', redirectTo: '/', canActivate: [AngularFireAuthGuard] }
20-
])
21-
],
22-
providers: [
23-
{ provide: APP_BASE_HREF, useValue: 'http://localhost:4200/' }
24-
]
25-
});
26-
inject([FirebaseApp, Router], (app_: FirebaseApp, router_: Router) => {
27-
app = app_;
28-
router = router_;
29-
})();
13+
beforeEach(() => {
14+
TestBed.configureTestingModule({
15+
imports: [
16+
AngularFireModule.initializeApp(COMMON_CONFIG, rando()),
17+
AngularFireAuthGuardModule,
18+
RouterModule.forRoot([
19+
{ path: 'a', redirectTo: '/', canActivate: [AngularFireAuthGuard] }
20+
])
21+
],
22+
providers: [
23+
{ provide: APP_BASE_HREF, useValue: 'http://localhost:4200/' }
24+
]
3025
});
3126

32-
afterEach(done => {
33-
app.delete().then(done, done);
34-
});
27+
app = TestBed.inject(FirebaseApp);
28+
router = TestBed.inject(Router);
29+
});
3530

36-
it('should be injectable', () => {
37-
expect(router).toBeTruthy();
38-
});
31+
afterEach(done => {
32+
app.delete().then(done, done);
33+
});
34+
35+
it('should be injectable', () => {
36+
expect(router).toBeTruthy();
37+
});
3938
});

src/auth-guard/auth-guard.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseAppConfig, FirebaseOptions
88
export type AuthPipeGenerator = (next: ActivatedRouteSnapshot, state: RouterStateSnapshot) => AuthPipe;
99
export type AuthPipe = UnaryFunction<Observable<User|null>, Observable<boolean|any[]>>;
1010

11+
export const loggedIn: AuthPipe = map(user => !!user);
12+
1113
@Injectable({
1214
providedIn: 'any'
1315
})
@@ -50,7 +52,7 @@ export const canActivate = (pipe: AuthPipeGenerator) => ({
5052
canActivate: [ AngularFireAuthGuard ], data: { authGuardPipe: pipe }
5153
});
5254

53-
export const loggedIn: AuthPipe = map(user => !!user);
55+
5456
export const isNotAnonymous: AuthPipe = map(user => !!user && !user.isAnonymous);
5557
export const idTokenResult = switchMap((user: User|null) => user ? user.getIdTokenResult() : of(null));
5658
export const emailVerified: AuthPipe = map(user => !!user && user.emailVerified);

0 commit comments

Comments
 (0)