Skip to content

Commit 439b93b

Browse files
chore(lint): Clean database list files
1 parent 22c62f6 commit 439b93b

8 files changed

+58
-62
lines changed

src/database/list/audit-trail.spec.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DatabaseReference } from '../interfaces';
22
import { AngularFireModule, FirebaseApp } from '@angular/fire';
33
import { AngularFireDatabase, AngularFireDatabaseModule, auditTrail, ChildEvent, URL } from '../public_api';
4-
import { inject, TestBed } from '@angular/core/testing';
4+
import { TestBed } from '@angular/core/testing';
55
import { COMMON_CONFIG } from '../../test-config';
66
import { skip } from 'rxjs/operators';
77
import 'firebase/database';
@@ -12,10 +12,9 @@ describe('auditTrail', () => {
1212
let db: AngularFireDatabase;
1313
let createRef: (path: string) => DatabaseReference;
1414
let batch = {};
15-
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ( { key: i.toString(), ...item } ));
16-
Object.keys(items).forEach(function(key, i) {
17-
const itemValue = items[key];
18-
batch[i] = itemValue;
15+
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ({ key: i.toString(), ...item }));
16+
Object.keys(items).forEach((key, i) => {
17+
batch[i] = items[key];
1918
});
2019
// make batch immutable to preserve integrity
2120
batch = Object.freeze(batch);
@@ -30,11 +29,10 @@ describe('auditTrail', () => {
3029
{ provide: URL, useValue: 'http://localhost:9000' }
3130
]
3231
});
33-
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {
34-
app = app_;
35-
db = _db;
36-
createRef = (path: string) => db.database.ref(path);
37-
})();
32+
33+
app = TestBed.inject(FirebaseApp);
34+
db = TestBed.inject(AngularFireDatabase);
35+
createRef = (path: string) => db.database.ref(path);
3836
});
3937

4038
afterEach(() => {

src/database/list/changes.spec.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { database } from 'firebase/app';
22
import { AngularFireModule, FirebaseApp } from '@angular/fire';
33
import { AngularFireDatabase, AngularFireDatabaseModule, listChanges, URL } from '../public_api';
4-
import { inject, TestBed } from '@angular/core/testing';
4+
import { TestBed } from '@angular/core/testing';
55
import { COMMON_CONFIG } from '../../test-config';
66
import { skip, take } from 'rxjs/operators';
77
import 'firebase/database';
@@ -12,10 +12,9 @@ describe('listChanges', () => {
1212
let db: AngularFireDatabase;
1313
let ref: (path: string) => database.Reference;
1414
let batch = {};
15-
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ( { key: i.toString(), ...item } ));
16-
Object.keys(items).forEach(function(key, i) {
17-
const itemValue = items[key];
18-
batch[i] = itemValue;
15+
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ({ key: i.toString(), ...item }));
16+
Object.keys(items).forEach((key, i) => {
17+
batch[i] = items[key];
1918
});
2019
// make batch immutable to preserve integrity
2120
batch = Object.freeze(batch);
@@ -30,11 +29,10 @@ describe('listChanges', () => {
3029
{ provide: URL, useValue: 'http://localhost:9000' }
3130
]
3231
});
33-
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {
34-
app = app_;
35-
db = _db;
36-
ref = (path: string) => db.database.ref(path);
37-
})();
32+
33+
app = TestBed.inject(FirebaseApp);
34+
db = TestBed.inject(AngularFireDatabase);
35+
ref = (path: string) => db.database.ref(path);
3836
});
3937

4038
afterEach(() => {
@@ -46,7 +44,7 @@ describe('listChanges', () => {
4644
it('should stream value at first', (done) => {
4745
const someRef = ref(rando());
4846
const obs = listChanges(someRef, ['child_added']);
49-
const sub = obs.pipe(take(1)).subscribe(changes => {
47+
obs.pipe(take(1)).subscribe(changes => {
5048
const data = changes.map(change => change.payload.val());
5149
expect(data).toEqual(items);
5250
}).add(done);
@@ -56,7 +54,7 @@ describe('listChanges', () => {
5654
it('should process a new child_added event', done => {
5755
const aref = ref(rando());
5856
const obs = listChanges(aref, ['child_added']);
59-
const sub = obs.pipe(skip(1), take(1)).subscribe(changes => {
57+
obs.pipe(skip(1), take(1)).subscribe(changes => {
6058
const data = changes.map(change => change.payload.val());
6159
expect(data[3]).toEqual({ name: 'anotha one' });
6260
}).add(done);
@@ -67,7 +65,7 @@ describe('listChanges', () => {
6765
it('should stream in order events', (done) => {
6866
const aref = ref(rando());
6967
const obs = listChanges(aref.orderByChild('name'), ['child_added']);
70-
const sub = obs.pipe(take(1)).subscribe(changes => {
68+
obs.pipe(take(1)).subscribe(changes => {
7169
const names = changes.map(change => change.payload.val().name);
7270
expect(names[0]).toEqual('one');
7371
expect(names[1]).toEqual('two');
@@ -79,7 +77,7 @@ describe('listChanges', () => {
7977
it('should stream in order events w/child_added', (done) => {
8078
const aref = ref(rando());
8179
const obs = listChanges(aref.orderByChild('name'), ['child_added']);
82-
const sub = obs.pipe(skip(1), take(1)).subscribe(changes => {
80+
obs.pipe(skip(1), take(1)).subscribe(changes => {
8381
const names = changes.map(change => change.payload.val().name);
8482
expect(names[0]).toEqual('anotha one');
8583
expect(names[1]).toEqual('one');

src/database/list/changes.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { isNil } from '../utils';
66

77
import { distinctUntilChanged, scan, switchMap } from 'rxjs/operators';
88

9-
export function listChanges<T= any>(ref: DatabaseQuery, events: ChildEvent[], scheduler?: SchedulerLike): Observable<SnapshotAction<T>[]> {
9+
export function listChanges<T = any>(ref: DatabaseQuery, events: ChildEvent[], scheduler?: SchedulerLike): Observable<SnapshotAction<T>[]> {
1010
return fromRef(ref, 'value', 'once', scheduler).pipe(
1111
switchMap(snapshotAction => {
1212
const childEvent$ = [of(snapshotAction)];
@@ -32,7 +32,7 @@ function positionAfter<T>(changes: SnapshotAction<T>[], prevKey?: string) {
3232
return 0;
3333
} else {
3434
const i = positionFor(changes, prevKey);
35-
if ( i === -1) {
35+
if (i === -1) {
3636
return changes.length;
3737
} else {
3838
return i + 1;
@@ -41,15 +41,15 @@ function positionAfter<T>(changes: SnapshotAction<T>[], prevKey?: string) {
4141
}
4242

4343
function buildView(current, action) {
44-
const { payload, type, prevKey, key } = action;
44+
const { payload, prevKey, key } = action;
4545
const currentKeyPosition = positionFor(current, key);
4646
const afterPreviousKeyPosition = positionAfter(current, prevKey);
4747
switch (action.type) {
4848
case 'value':
4949
if (action.payload && action.payload.exists()) {
5050
let prevKey = null;
5151
action.payload.forEach(payload => {
52-
const action = {payload, type: 'value', prevKey, key: payload.key};
52+
const action = { payload, type: 'value', prevKey, key: payload.key };
5353
prevKey = payload.key;
5454
current = [...current, action];
5555
return false;
@@ -60,7 +60,7 @@ function buildView(current, action) {
6060
if (currentKeyPosition > -1) {
6161
// check that the previouskey is what we expect, else reorder
6262
const previous = current[currentKeyPosition - 1];
63-
if ((previous && previous.key || null) != prevKey) {
63+
if ((previous && previous.key || null) !== prevKey) {
6464
current = current.filter(x => x.payload.key !== payload.key);
6565
current.splice(afterPreviousKeyPosition, 0, action);
6666
}

src/database/list/snapshot-changes.spec.ts

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { database } from 'firebase/app';
22
import { AngularFireModule, FirebaseApp } from '@angular/fire';
33
import { AngularFireDatabase, AngularFireDatabaseModule, ChildEvent, snapshotChanges, URL } from '../public_api';
4-
import { inject, TestBed } from '@angular/core/testing';
4+
import { TestBed } from '@angular/core/testing';
55
import { COMMON_CONFIG } from '../../test-config';
66
import { BehaviorSubject } from 'rxjs';
77
import { skip, switchMap, take } from 'rxjs/operators';
@@ -13,10 +13,9 @@ describe('snapshotChanges', () => {
1313
let db: AngularFireDatabase;
1414
let createRef: (path: string) => database.Reference;
1515
let batch = {};
16-
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ( { key: i.toString(), ...item } ));
17-
Object.keys(items).forEach(function(key, i) {
18-
const itemValue = items[key];
19-
batch[i] = itemValue;
16+
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ({ key: i.toString(), ...item }));
17+
Object.keys(items).forEach((key, i) => {
18+
batch[i] = items[key];
2019
});
2120
// make batch immutable to preserve integrity
2221
batch = Object.freeze(batch);
@@ -31,11 +30,10 @@ describe('snapshotChanges', () => {
3130
{ provide: URL, useValue: 'http://localhost:9000' }
3231
]
3332
});
34-
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {
35-
app = app_;
36-
db = _db;
37-
createRef = (path: string) => db.database.ref(path);
38-
})();
33+
34+
app = TestBed.inject(FirebaseApp);
35+
db = TestBed.inject(AngularFireDatabase);
36+
createRef = (path: string) => db.database.ref(path);
3937
});
4038

4139
afterEach(() => {
@@ -55,27 +53,29 @@ describe('snapshotChanges', () => {
5553
it('should listen to all events by default', (done) => {
5654
const { snapChanges, ref } = prepareSnapshotChanges();
5755
snapChanges.pipe(take(1)).subscribe(actions => {
58-
const data = actions.map(a => a.payload!.val());
56+
const data = actions.map(a => a.payload.val());
5957
expect(data).toEqual(items);
6058
}).add(done);
6159
ref.set(batch);
6260
});
6361

6462
it('should handle multiple subscriptions (hot)', (done) => {
6563
const { snapChanges, ref } = prepareSnapshotChanges();
66-
const sub = snapChanges.subscribe(() => {}).add(done);
64+
const sub = snapChanges.subscribe(() => {
65+
}).add(done);
6766
snapChanges.pipe(take(1)).subscribe(actions => {
68-
const data = actions.map(a => a.payload!.val());
67+
const data = actions.map(a => a.payload.val());
6968
expect(data).toEqual(items);
7069
}).add(sub);
7170
ref.set(batch);
7271
});
7372

7473
it('should handle multiple subscriptions (warm)', done => {
7574
const { snapChanges, ref } = prepareSnapshotChanges();
76-
snapChanges.pipe(take(1)).subscribe(() => {}).add(() => {
75+
snapChanges.pipe(take(1)).subscribe(() => {
76+
}).add(() => {
7777
snapChanges.pipe(take(1)).subscribe(actions => {
78-
const data = actions.map(a => a.payload!.val());
78+
const data = actions.map(a => a.payload.val());
7979
expect(data).toEqual(items);
8080
}).add(done);
8181
});
@@ -85,7 +85,7 @@ describe('snapshotChanges', () => {
8585
it('should listen to only child_added events', (done) => {
8686
const { snapChanges, ref } = prepareSnapshotChanges({ events: ['child_added'], skipnumber: 0 });
8787
snapChanges.pipe(take(1)).subscribe(actions => {
88-
const data = actions.map(a => a.payload!.val());
88+
const data = actions.map(a => a.payload.val());
8989
expect(data).toEqual(items);
9090
}).add(done);
9191
ref.set(batch);
@@ -118,10 +118,8 @@ describe('snapshotChanges', () => {
118118
});
119119

120120
it('should handle dynamic queries that return empty sets', done => {
121-
const ITEMS = 10;
122121
let count = 0;
123-
const firstIndex = 0;
124-
const namefilter$ = new BehaviorSubject<number|null>(null);
122+
const namefilter$ = new BehaviorSubject<number | null>(null);
125123
const aref = createRef(rando());
126124
aref.set(batch);
127125
namefilter$.pipe(switchMap(name => {

src/database/list/snapshot-changes.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { listChanges } from './changes';
33
import { ChildEvent, DatabaseQuery, SnapshotAction } from '../interfaces';
44
import { validateEventsArray } from './utils';
55

6-
export function snapshotChanges<T>(query: DatabaseQuery, events?: ChildEvent[], scheduler?: SchedulerLike): Observable<SnapshotAction<T>[]> {
6+
export function snapshotChanges<T>(
7+
query: DatabaseQuery,
8+
events?: ChildEvent[],
9+
scheduler?: SchedulerLike
10+
): Observable<SnapshotAction<T>[]> {
711
events = validateEventsArray(events);
8-
return listChanges<T>(query, events!, scheduler);
12+
return listChanges<T>(query, events, scheduler);
913
}

src/database/list/state-changes.spec.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { database } from 'firebase/app';
22
import { AngularFireModule, FirebaseApp } from '@angular/fire';
33
import { AngularFireDatabase, AngularFireDatabaseModule, ChildEvent, stateChanges, URL } from '../public_api';
4-
import { inject, TestBed } from '@angular/core/testing';
4+
import { TestBed } from '@angular/core/testing';
55
import { COMMON_CONFIG } from '../../test-config';
66
import { skip } from 'rxjs/operators';
77
import 'firebase/database';
@@ -12,10 +12,9 @@ describe('stateChanges', () => {
1212
let db: AngularFireDatabase;
1313
let createRef: (path: string) => database.Reference;
1414
let batch = {};
15-
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ( { key: i.toString(), ...item } ));
16-
Object.keys(items).forEach(function(key, i) {
17-
const itemValue = items[key];
18-
batch[i] = itemValue;
15+
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ({ key: i.toString(), ...item }));
16+
Object.keys(items).forEach((key, i) => {
17+
batch[i] = items[key];
1918
});
2019
// make batch immutable to preserve integrity
2120
batch = Object.freeze(batch);
@@ -30,11 +29,10 @@ describe('stateChanges', () => {
3029
{ provide: URL, useValue: 'http://localhost:9000' }
3130
]
3231
});
33-
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {
34-
app = app_;
35-
db = _db;
36-
createRef = (path: string) => db.database.ref(path);
37-
})();
32+
33+
app = TestBed.inject(FirebaseApp);
34+
db = TestBed.inject(AngularFireDatabase);
35+
createRef = (path: string) => db.database.ref(path);
3836
});
3937

4038
afterEach(() => {

src/database/list/state-changes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { validateEventsArray } from './utils';
44
import { merge, SchedulerLike } from 'rxjs';
55

66
export function stateChanges<T>(query: DatabaseQuery, events?: ChildEvent[], scheduler?: SchedulerLike) {
7-
events = validateEventsArray(events)!;
7+
events = validateEventsArray(events);
88
const childEvent$ = events.map(event => fromRef<T>(query, event, 'on', scheduler));
99
return merge(...childEvent$);
1010
}

src/database/list/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isNil } from '../utils';
22

33
export function validateEventsArray(events?: any[]) {
4-
if (isNil(events) || events!.length === 0) {
4+
if (isNil(events) || events.length === 0) {
55
events = ['child_added', 'child_removed', 'child_changed', 'child_moved'];
66
}
77
return events;

0 commit comments

Comments
 (0)