Skip to content

Commit 5462c36

Browse files
chore(lint): Clean angularfire2.ts
1 parent 4d8707d commit 5462c36

File tree

2 files changed

+52
-35
lines changed

2 files changed

+52
-35
lines changed

src/core/angularfire2.spec.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { inject, TestBed } from '@angular/core/testing';
1+
import { TestBed } from '@angular/core/testing';
22
import { CompilerFactory, NgModule, NgZone, PlatformRef } from '@angular/core';
33
import { AngularFireModule, FirebaseApp } from './public_api';
4-
import { Observable, of, Subject, Subscription } from 'rxjs';
4+
import { Observable, of, Subject } from 'rxjs';
55
import { COMMON_CONFIG } from '../test-config';
66
import { BrowserModule } from '@angular/platform-browser';
77
import { database } from 'firebase/app';
@@ -12,7 +12,6 @@ import { TestScheduler } from 'rxjs/testing';
1212
import { rando } from '../firestore/utils.spec';
1313

1414
describe('angularfire', () => {
15-
let subscription: Subscription;
1615
let app: FirebaseApp;
1716
let rootRef: database.Reference;
1817
let questionsRef: database.Reference;
@@ -28,21 +27,15 @@ describe('angularfire', () => {
2827
imports: [AngularFireModule.initializeApp(COMMON_CONFIG, appName)]
2928
});
3029

31-
inject([FirebaseApp, PlatformRef], (_app: FirebaseApp, _platform: PlatformRef) => {
32-
app = _app;
33-
rootRef = app.database!().ref();
34-
questionsRef = rootRef.child('questions');
35-
listOfQuestionsRef = rootRef.child('list-of-questions');
36-
defaultPlatform = _platform;
37-
})();
38-
30+
app = TestBed.inject(FirebaseApp);
31+
defaultPlatform = TestBed.inject(PlatformRef);
32+
rootRef = app.database().ref();
33+
questionsRef = rootRef.child('questions');
34+
listOfQuestionsRef = rootRef.child('list-of-questions');
3935
});
4036

4137
afterEach(() => {
4238
rootRef.remove();
43-
if (subscription && !subscription.closed) {
44-
subscription.unsubscribe();
45-
}
4639
app.delete();
4740
});
4841

@@ -64,7 +57,7 @@ describe('angularfire', () => {
6457
});
6558

6659
it('should execute nested scheduled work inside the specified zone', done => {
67-
const testScheduler = new TestScheduler(null!);
60+
const testScheduler = new TestScheduler(null);
6861
testScheduler.run(helpers => {
6962
const outsideAngularScheduler = new ɵZoneScheduler(Zone.current, testScheduler);
7063

@@ -162,7 +155,7 @@ describe('angularfire', () => {
162155
);
163156

164157
it('should block until first emission', done => {
165-
const testScheduler = new TestScheduler(null!);
158+
const testScheduler = new TestScheduler(null);
166159
testScheduler.run(helpers => {
167160
const outsideZone = Zone.current;
168161
// tslint:disable-next-line:no-string-literal
@@ -176,14 +169,18 @@ describe('angularfire', () => {
176169
runTask: insideZone.run.bind(insideZone)
177170
} as NgZone,
178171
outsideAngular: new ɵZoneScheduler(outsideZone, testScheduler),
179-
insideAngular: new ɵZoneScheduler(insideZone, testScheduler),
172+
insideAngular: new ɵZoneScheduler(insideZone, testScheduler)
180173
};
181174
const keepUnstableOp = ɵkeepUnstableUntilFirstFactory(trackingSchedulers, ɵPLATFORM_SERVER_ID);
182175

183176
const s = new Subject();
184177
s.pipe(
185-
keepUnstableOp,
186-
).subscribe(() => { }, err => { fail(err); }, () => { });
178+
keepUnstableOp
179+
).subscribe(() => {
180+
}, err => {
181+
fail(err);
182+
}, () => {
183+
});
187184

188185
// Flush to ensure all async scheduled functions are run
189186
helpers.flush();
@@ -224,23 +221,25 @@ describe('angularfire', () => {
224221
imports: [
225222
AngularFireModule.initializeApp(COMMON_CONFIG, appName),
226223
BrowserModule
227-
]})
224+
]
225+
})
228226
class MyModule {
229-
ngDoBootstrap() {}
227+
ngDoBootstrap() {
228+
}
230229
}
231230

232231
const compilerFactory: CompilerFactory =
233-
defaultPlatform.injector.get(CompilerFactory, null);
232+
defaultPlatform.injector.get(CompilerFactory, null);
234233
const moduleFactory = compilerFactory.createCompiler().compileModuleSync(MyModule);
235234

236235
defaultPlatform.bootstrapModuleFactory(moduleFactory)
237236
.then(moduleRef => {
238237
const ref = moduleRef.injector.get(FirebaseApp);
239238
expect(ref.name).toEqual(app.name);
240239
}).then(done, e => {
241-
fail(e);
242-
done();
243-
});
240+
fail(e);
241+
done();
242+
});
244243
});
245244

246245
}

src/core/angularfire2.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { NgZone } from '@angular/core';
22
import { asyncScheduler, Observable, Operator, queueScheduler, SchedulerAction, SchedulerLike, Subscriber, Subscription, TeardownLogic } from 'rxjs';
33
import { observeOn, subscribeOn, tap } from 'rxjs/operators';
44

5-
function noop() { }
5+
function noop() {
6+
}
67

78
/**
89
* Schedules tasks so that they are invoked inside the Zone that is passed in the constructor.
910
*/
11+
// tslint:disable-next-line:class-name
1012
export class ɵZoneScheduler implements SchedulerLike {
11-
constructor(private zone: any, private delegate: any = queueScheduler) { }
13+
constructor(private zone: any, private delegate: any = queueScheduler) {
14+
}
1215

1316
now() {
1417
return this.delegate.now();
@@ -31,17 +34,19 @@ export class ɵZoneScheduler implements SchedulerLike {
3134
}
3235
}
3336

37+
// tslint:disable-next-line:class-name
3438
export class ɵBlockUntilFirstOperator<T> implements Operator<T, T> {
3539
private task: MacroTask | null = null;
3640

37-
constructor(private zone: any) { }
41+
constructor(private zone: any) {
42+
}
3843

3944
call(subscriber: Subscriber<T>, source: Observable<T>): TeardownLogic {
4045
const unscheduleTask = this.unscheduleTask.bind(this);
4146
this.task = this.zone.run(() => Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop));
4247

4348
return source.pipe(
44-
tap(unscheduleTask, unscheduleTask, unscheduleTask)
49+
tap({ next: unscheduleTask, complete: unscheduleTask, error: unscheduleTask })
4550
).subscribe(subscriber).add(unscheduleTask);
4651
}
4752

@@ -57,6 +62,7 @@ export class ɵBlockUntilFirstOperator<T> implements Operator<T, T> {
5762
}
5863
}
5964

65+
// tslint:disable-next-line:class-name
6066
export class ɵAngularFireSchedulers {
6167
public readonly outsideAngular: ɵZoneScheduler;
6268
public readonly insideAngular: ɵZoneScheduler;
@@ -75,6 +81,7 @@ export class ɵAngularFireSchedulers {
7581
*/
7682
export function ɵkeepUnstableUntilFirstFactory(
7783
schedulers: ɵAngularFireSchedulers,
84+
// tslint:disable-next-line:ban-types
7885
platformId: Object
7986
) {
8087
return function keepUnstableUntilFirst<T>(obs$: Observable<T>): Observable<T> {
@@ -93,14 +100,20 @@ export function ɵkeepUnstableUntilFirstFactory(
93100
};
94101
}
95102

103+
// tslint:disable:ban-types
96104
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
97-
type PromiseReturningFunctionPropertyNames<T> = { [K in FunctionPropertyNames<T>]: ReturnType<T[K]> extends Promise<any> ? K : never }[FunctionPropertyNames<T>];
98-
type NonPromiseReturningFunctionPropertyNames<T> = { [K in FunctionPropertyNames<T>]: ReturnType<T[K]> extends Promise<any> ? never : K }[FunctionPropertyNames<T>];
105+
type PromiseReturningFunctionPropertyNames<T> = {
106+
[K in FunctionPropertyNames<T>]: ReturnType<T[K]> extends Promise<any> ? K : never
107+
}[FunctionPropertyNames<T>];
108+
type NonPromiseReturningFunctionPropertyNames<T> = {
109+
[K in FunctionPropertyNames<T>]: ReturnType<T[K]> extends Promise<any> ? never : K
110+
}[FunctionPropertyNames<T>];
99111
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
112+
// tslint:enable:ban-types
100113

101114
export type ɵPromiseProxy<T> = { [K in NonFunctionPropertyNames<T>]: Promise<T[K]> } &
102115
{ [K in NonPromiseReturningFunctionPropertyNames<T>]: (...args: Parameters<T[K]>) => Promise<ReturnType<T[K]>> } &
103-
{ [K in PromiseReturningFunctionPropertyNames<T> ]: (...args: Parameters<T[K]>) => ReturnType<T[K]> };
116+
{ [K in PromiseReturningFunctionPropertyNames<T>]: (...args: Parameters<T[K]>) => ReturnType<T[K]> };
104117

105118

106119
// DEBUG quick debugger function for inline logging that typescript doesn't complain about
@@ -118,12 +131,17 @@ const noopFunctions = ['ngOnDestroy'];
118131
export const ɵlazySDKProxy = (klass: any, observable: Observable<any>, zone: NgZone) => {
119132
return new Proxy(klass, {
120133
get: (_, name: string) => zone.runOutsideAngular(() => {
121-
if (klass[name]) { return klass[name]; }
122-
if (noopFunctions.includes(name)) { return () => {}; }
134+
if (klass[name]) {
135+
return klass[name];
136+
}
137+
if (noopFunctions.includes(name)) {
138+
return () => {
139+
};
140+
}
123141
const promise = observable.toPromise().then(mod => {
124142
const ret = mod && mod[name];
125143
// TODO move to proper type guards
126-
if (typeof ret == 'function') {
144+
if (typeof ret === 'function') {
127145
return ret.bind(mod);
128146
} else if (ret && ret.then) {
129147
return ret.then((res: any) => zone.run(() => res));

0 commit comments

Comments
 (0)