Skip to content

Commit 8c29c3c

Browse files
committed
Address PR comments
1 parent 6b465a9 commit 8c29c3c

File tree

15 files changed

+61
-68
lines changed

15 files changed

+61
-68
lines changed

packages/app/src/firebaseApp.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ export class FirebaseAppImpl implements FirebaseApp {
114114
}
115115

116116
return Promise.all(
117-
services.map(service => {
118-
return service.INTERNAL
119-
? service.INTERNAL.delete()
120-
: Promise.resolve();
121-
})
117+
services
118+
.filter(service => 'INTERNAL' in service)
119+
.map(service => {
120+
return service.INTERNAL!.delete()
121+
})
122122
);
123123
})
124124
.then(

packages/logger/test/logger.test.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,27 @@ import { debug } from 'util';
2424
describe('@firebase/logger', () => {
2525
const message = 'Hello there!';
2626
let client: Logger;
27-
const spies: { [key: string]: SinonSpy | null } = {
28-
logSpy: null,
29-
infoSpy: null,
30-
warnSpy: null,
31-
errorSpy: null
32-
};
27+
let spies: { [key: string]: SinonSpy };
3328
/**
3429
* Before each test, instantiate a new instance of Logger and establish spies
3530
* on all of the console methods so we can assert against them as needed
3631
*/
3732
beforeEach(() => {
3833
client = new Logger('@firebase/test-logger');
3934

40-
spies.logSpy = Spy(console, 'log');
41-
spies.infoSpy = Spy(console, 'info');
42-
spies.warnSpy = Spy(console, 'warn');
43-
spies.errorSpy = Spy(console, 'error');
35+
spies = {
36+
logSpy: Spy(console, 'log'),
37+
infoSpy: Spy(console, 'info'),
38+
warnSpy: Spy(console, 'warn'),
39+
errorSpy: Spy(console, 'error')
40+
}
4441
});
4542

4643
afterEach(() => {
47-
spies.logSpy && spies.logSpy.restore();
48-
spies.infoSpy && spies.infoSpy.restore();
49-
spies.warnSpy && spies.warnSpy.restore();
50-
spies.errorSpy && spies.errorSpy.restore();
44+
spies.logSpy.restore();
45+
spies.infoSpy.restore();
46+
spies.warnSpy.restore();
47+
spies.errorSpy.restore();
5148
});
5249

5350
function testLog(message, channel, shouldLog) {

packages/rxfire/database/list/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ export function list(
4242
query: database.Query,
4343
events?: ListenEvent[]
4444
): Observable<QueryChange[]> {
45-
const eventsToList = validateEventsArray(events);
45+
const eventsList = validateEventsArray(events);
4646
return fromOnce(query).pipe(
4747
switchMap(change => {
4848
const childEvent$ = [of(change)];
49-
eventsToList.forEach(event => childEvent$.push(fromRef(query, event)));
49+
for (const event of eventsList) {
50+
childEvent$.push(fromRef(query, event));
51+
}
5052
return merge(...childEvent$).pipe(scan(buildView, []));
5153
}),
5254
distinctUntilChanged()

packages/rxfire/database/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { ListenEvent } from './interfaces';
1919

20-
export function isNil(obj: any): boolean {
20+
export function isNil(obj: any): obj is null | undefined {
2121
return obj === undefined || obj === null;
2222
}
2323

@@ -27,14 +27,13 @@ export function isNil(obj: any): boolean {
2727
* @param events
2828
*/
2929
export function validateEventsArray(events?: ListenEvent[]): ListenEvent[] {
30-
let validatedEvents: ListenEvent[] = [];
3130
if (isNil(events) || events!.length === 0) {
32-
validatedEvents = [
31+
events = [
3332
ListenEvent.added,
3433
ListenEvent.removed,
3534
ListenEvent.changed,
3635
ListenEvent.moved
3736
];
3837
}
39-
return validatedEvents;
38+
return events;
4039
}

packages/rxfire/test/database.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ let batch = (items: any[]) => {
4141
};
4242

4343
describe('RxFire Database', () => {
44-
let app: app.App | null = null;
45-
let database: database.Database | null = null;
44+
let app: app.App;
45+
let database: database.Database;
4646
let ref = (path: string) => {
4747
app!.database().goOffline();
4848
return app!.database().ref(path);
@@ -85,7 +85,7 @@ describe('RxFire Database', () => {
8585
});
8686

8787
afterEach((done: MochaDone) => {
88-
app && app.delete().then(() => done());
88+
app.delete().then(() => done());
8989
});
9090

9191
describe('fromRef', () => {
@@ -396,7 +396,7 @@ describe('RxFire Database', () => {
396396
expect(data.length).to.eql(items.length - 1);
397397
})
398398
.add(done);
399-
app && app.database().goOnline();
399+
app.database().goOnline();
400400
aref.set(itemsObj).then(() => {
401401
aref.child(items[0].key).remove();
402402
});
@@ -419,7 +419,7 @@ describe('RxFire Database', () => {
419419
expect(data[1].name).to.eql('lol');
420420
})
421421
.add(done);
422-
app && app.database().goOnline();
422+
app.database().goOnline();
423423
aref.set(itemsObj).then(() => {
424424
aref.child(items[1].key).update({ name: 'lol' });
425425
});
@@ -444,7 +444,7 @@ describe('RxFire Database', () => {
444444
expect(data[data.length - 1]).to.eql(items[0]);
445445
})
446446
.add(done);
447-
app && app.database().goOnline();
447+
app.database().goOnline();
448448
aref.set(itemsObj).then(() => {
449449
aref.child(items[0].key).setPriority('a', () => {});
450450
});
@@ -542,7 +542,7 @@ describe('RxFire Database', () => {
542542
expect(data).to.eql(copy);
543543
})
544544
.add(done);
545-
app && app.database().goOnline();
545+
app.database().goOnline();
546546
ref.set(itemsObj).then(() => {
547547
ref.child(items[0].key).update({ name });
548548
});

packages/rxfire/test/firestore.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const seedTest = firestore => {
6767
};
6868

6969
describe('RxFire Firestore', () => {
70-
let app: app.App | null = null;
71-
let firestore: firestore.Firestore | null = null;
70+
let app: app.App;
71+
let firestore: firestore.Firestore;
7272

7373
/**
7474
* Each test runs inside it's own app instance and the app
@@ -88,7 +88,7 @@ describe('RxFire Firestore', () => {
8888
});
8989

9090
afterEach((done: MochaDone) => {
91-
app && app.delete().then(() => done());
91+
app.delete().then(() => done());
9292
});
9393

9494
describe('collection', () => {

packages/storage/src/implementation/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function getMappings(): Mappings {
7070
if (mappings_) {
7171
return mappings_;
7272
}
73-
let mappings: Array<Mapping> = [];
73+
const mappings: Mapping[] = [];
7474
mappings.push(new Mapping('bucket'));
7575
mappings.push(new Mapping('generation'));
7676
mappings.push(new Mapping('metageneration'));

packages/storage/src/implementation/observer.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type CompleteFn = () => void;
2323
type Unsubscribe = () => void;
2424

2525
type Subscribe<T> = (
26-
next: NextFn<T> | { [name: string]: string | null } | null | undefined,
27-
error: ErrorFn | null | undefined,
28-
complete: CompleteFn | null | undefined
26+
next?: NextFn<T> | { [name: string]: string | null } | null,
27+
error?: ErrorFn | null,
28+
complete?: CompleteFn | null
2929
) => Unsubscribe;
3030

3131
export { NextFn, ErrorFn, CompleteFn, Unsubscribe, Subscribe };
@@ -34,17 +34,16 @@ export { NextFn, ErrorFn, CompleteFn, Unsubscribe, Subscribe };
3434
* @struct
3535
*/
3636
export class Observer<T> {
37-
next: NextFn<T> | null;
38-
error: ErrorFn | null | undefined;
39-
complete: CompleteFn | null;
37+
next?: NextFn<T> | null;
38+
error?: ErrorFn | null;
39+
complete?: CompleteFn | null;
4040

4141
constructor(
42-
nextOrObserver:
42+
nextOrObserver?:
4343
| NextFn<T>
4444
| { [name: string]: string | null }
45-
| null
46-
| undefined,
47-
opt_error?: ErrorFn | null | undefined,
45+
| null,
46+
opt_error?: ErrorFn | null,
4847
opt_complete?: CompleteFn | null
4948
) {
5049
let asFunctions =

packages/storage/src/implementation/requests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export function multipartUpload(
271271
if (body === null) {
272272
throw errorsExports.cannotSliceBlob();
273273
}
274-
let urlParams: UrlParams = { name: metadata['fullPath'] || '' };
274+
let urlParams: UrlParams = { name: metadata['fullPath']! };
275275
let url = UrlUtils.makeUrl(urlPart);
276276
let method = 'POST';
277277
let timeout = authWrapper.maxUploadRetryTime();

packages/storage/src/reference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class Reference {
175175
let data = fbsString.dataFromString(format, string);
176176
let metadata = object.clone<Metadata>(opt_metadata);
177177
if (!type.isDef(metadata['contentType']) && type.isDef(data.contentType)) {
178-
metadata['contentType'] = data.contentType || undefined;
178+
metadata['contentType'] = data.contentType!;
179179
}
180180
return new UploadTask(
181181
this,

packages/storage/src/task.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,12 @@ export class UploadTask {
455455
*/
456456
on(
457457
type: TaskEvent,
458-
nextOrObserver:
458+
nextOrObserver?:
459459
| NextFn<UploadTaskSnapshot>
460460
| { [name: string]: any }
461-
| null
462-
| undefined = undefined,
463-
error: ErrorFn | null | undefined = undefined,
464-
completed: CompleteFn | null | undefined = undefined
461+
| null,
462+
error?: ErrorFn | null,
463+
completed?: CompleteFn | null
465464
): Unsubscribe | Subscribe<UploadTaskSnapshot> {
466465
function typeValidator(_p: any) {
467466
if (type !== TaskEvent.STATE_CHANGED) {
@@ -509,10 +508,9 @@ export class UploadTask {
509508
nextOrObserver:
510509
| NextFn<UploadTaskSnapshot>
511510
| { [name: string]: string | null }
512-
| null
513-
| undefined,
514-
error?: ErrorFn | null | undefined,
515-
opt_complete?: CompleteFn | null | undefined
511+
| null,
512+
error?: ErrorFn | null,
513+
opt_complete?: CompleteFn | null
516514
) {
517515
if (specs !== null) {
518516
fbsArgs.validate('on', specs, arguments);
@@ -627,12 +625,12 @@ export class UploadTask {
627625
switch (externalState) {
628626
case TaskState.RUNNING:
629627
case TaskState.PAUSED:
630-
if (observer.next !== null) {
628+
if (observer.next) {
631629
fbsAsync(observer.next.bind(observer, this.snapshot))();
632630
}
633631
break;
634632
case TaskState.SUCCESS:
635-
if (observer.complete !== null) {
633+
if (observer.complete) {
636634
fbsAsync(observer.complete.bind(observer))();
637635
}
638636
break;

packages/storage/test/blob.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,17 @@ describe('Firebase Storage > Blob', () => {
4141

4242
it('Slicing works', () => {
4343
const blob = new FbsBlob(new Uint8Array([1, 2, 3, 4, 5, 6, 7]));
44-
const sliced = blob.slice(1, 5);
45-
assert.isNotNull(sliced);
44+
const sliced = blob.slice(1, 5)!;
4645
testShared.assertUint8ArrayEquals(
47-
sliced!.uploadData() as Uint8Array,
46+
sliced.uploadData() as Uint8Array,
4847
new Uint8Array([2, 3, 4, 5])
4948
);
5049
});
5150
it('Blobs are merged with strings correctly', () => {
5251
const blob = new FbsBlob(new Uint8Array([1, 2, 3, 4]));
53-
const merged = FbsBlob.getBlob('what', blob, '\ud83d\ude0a ');
54-
assert.isNotNull(merged);
52+
const merged = FbsBlob.getBlob('what', blob, '\ud83d\ude0a ')!;
5553
testShared.assertUint8ArrayEquals(
56-
merged!.uploadData() as Uint8Array,
54+
merged.uploadData() as Uint8Array,
5755
new Uint8Array([
5856
0x77,
5957
0x68,

packages/storage/test/requests.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ describe('Firebase Storage > Requests', () => {
298298
[locationNormal, locationNormalNoObjUrl],
299299
[locationEscapes, locationEscapesNoObjUrl]
300300
];
301-
const promises: Promise<void>[] = [];
301+
const promises: Array<Promise<void>> = [];
302302
for (let i = 0; i < maps.length; i++) {
303303
const location = maps[i][0] as Location;
304304
const url = maps[i][1] as string;

packages/util/src/crypt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const stringToByteArray = function(str) {
5454
*/
5555
const byteArrayToString = function(bytes) {
5656
// TODO(user): Use native implementations if/when available
57-
var out: Array<string> = [],
57+
var out: string[] = [],
5858
pos = 0,
5959
c = 0;
6060
while (pos < bytes.length) {

packages/util/test/errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('FirebaseError', () => {
9595
const e = ERROR_FACTORY.create('generic-error');
9696
assert.isDefined(e.stack);
9797
// Multi-line match trick - .* does not match \n
98-
assert.match(e.stack as string, /FirebaseError[\s\S]/);
98+
assert.match(e.stack!, /FirebaseError[\s\S]/);
9999
});
100100

101101
it('has function names in stack trace in correct order', () => {

0 commit comments

Comments
 (0)