Skip to content

Commit 1318921

Browse files
chore(lint): Clean the rest of database files
1 parent 439b93b commit 1318921

File tree

5 files changed

+62
-47
lines changed

5 files changed

+62
-47
lines changed

src/database/database.spec.ts

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { AngularFireModule, FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseApp } from '@angular/fire';
22
import { AngularFireDatabase, AngularFireDatabaseModule, URL } from './public_api';
3-
import { inject, TestBed } from '@angular/core/testing';
3+
import { TestBed } from '@angular/core/testing';
44
import { COMMON_CONFIG } from '../test-config';
55
import { NgZone } from '@angular/core';
66
import 'firebase/database';
77
import { rando } from '../firestore/utils.spec';
8-
import { Test } from 'tslint';
98

109
describe('AngularFireDatabase', () => {
1110
let app: FirebaseApp;
@@ -21,7 +20,7 @@ describe('AngularFireDatabase', () => {
2120
AngularFireDatabaseModule
2221
],
2322
providers: [
24-
{ provide: URL, useValue: 'http://localhost:9000'}
23+
{ provide: URL, useValue: 'http://localhost:9000' }
2524
]
2625
});
2726

@@ -80,10 +79,9 @@ describe('AngularFireDatabase w/options', () => {
8079
{ provide: URL, useValue: url }
8180
]
8281
});
83-
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {
84-
app = app_;
85-
db = _db;
86-
})();
82+
83+
app = TestBed.inject(FirebaseApp);
84+
db = TestBed.inject(AngularFireDatabase);
8785
});
8886

8987
afterEach(() => {
@@ -104,20 +102,20 @@ describe('AngularFireDatabase w/options', () => {
104102
expect(db.database.app.name).toEqual(firebaseAppName);
105103
});
106104

107-
/* INVESTIGATE database(url) does not seem to be working
105+
/* INVESTIGATE database(url) does not seem to be working
108106
109-
it('database be pointing to the provided DB instance', () => {
110-
expect(db.database.ref().toString()).toEqual(url);
111-
});
107+
it('database be pointing to the provided DB instance', () => {
108+
expect(db.database.ref().toString()).toEqual(url);
109+
});
112110
113-
it('list should be using the provided DB instance', () => {
114-
expect(db.list(query).query.toString()).toEqual(`${url}/${query}`);
115-
});
111+
it('list should be using the provided DB instance', () => {
112+
expect(db.list(query).query.toString()).toEqual(`${url}/${query}`);
113+
});
116114
117-
it('object should be using the provided DB instance', () => {
118-
expect(db.object(query).query.toString()).toEqual(`${url}/${query}`);
119-
});
120-
*/
115+
it('object should be using the provided DB instance', () => {
116+
expect(db.object(query).query.toString()).toEqual(`${url}/${query}`);
117+
});
118+
*/
121119
});
122120

123121
});

src/database/database.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export class AngularFireDatabase {
2121

2222
constructor(
2323
@Inject(FIREBASE_OPTIONS) options: FirebaseOptions,
24-
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string|FirebaseAppConfig|null|undefined,
25-
@Optional() @Inject(URL) databaseURL: string|null,
24+
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string | FirebaseAppConfig | null | undefined,
25+
@Optional() @Inject(URL) databaseURL: string | null,
2626
// tslint:disable-next-line:ban-types
2727
@Inject(PLATFORM_ID) platformId: Object,
2828
zone: NgZone
@@ -45,7 +45,7 @@ export class AngularFireDatabase {
4545
return createListReference<T>(query, this);
4646
}
4747

48-
object<T>(pathOrRef: PathReference): AngularFireObject<T> {
48+
object<T>(pathOrRef: PathReference): AngularFireObject<T> {
4949
const ref = getRef(this.database, pathOrRef);
5050
return createObjectReference<T>(ref, this);
5151
}

src/database/object/create-reference.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function createObjectReference<T= any>(query: DatabaseQuery, afDatabase:
88
query,
99
snapshotChanges<T>() {
1010
return createObjectSnapshotChanges<T>(query, afDatabase.schedulers.outsideAngular)().pipe(
11-
afDatabase.keepUnstableUntilFirst!
11+
afDatabase.keepUnstableUntilFirst
1212
);
1313
},
1414
update(data: Partial<T>) { return query.ref.update(data as any) as Promise<void>; },

src/database/observable/fromRef.spec.ts

+26-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DatabaseReference } from '../interfaces';
22
import { AngularFireModule, FirebaseApp, ɵZoneScheduler } from '@angular/fire';
33
import { AngularFireDatabase, AngularFireDatabaseModule, fromRef } 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 { take } from 'rxjs/operators';
77
import { TestScheduler } from 'rxjs/testing';
@@ -13,7 +13,7 @@ describe('fromRef', () => {
1313
let ref: (path: string) => DatabaseReference;
1414
let batch = {};
1515
const items = [{ name: 'one' }, { name: 'two' }, { name: 'three' }].map(item => ({ key: rando(), ...item }));
16-
Object.keys(items).forEach(function(key) {
16+
Object.keys(items).forEach((key) => {
1717
const itemValue = items[key];
1818
batch[itemValue.key] = itemValue;
1919
});
@@ -27,14 +27,13 @@ describe('fromRef', () => {
2727
AngularFireDatabaseModule
2828
],
2929
providers: [
30-
{ provide: URL, useValue: 'http://localhost:9000'}
30+
{ provide: URL, useValue: 'http://localhost:9000' }
3131
]
3232
});
33-
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, db_: AngularFireDatabase) => {
34-
app = app_;
35-
db = db_;
36-
ref = (path: string) => db.database.ref(path);
37-
})();
33+
34+
app = TestBed.inject(FirebaseApp);
35+
db = TestBed.inject(AngularFireDatabase);
36+
ref = (path: string) => db.database.ref(path);
3837
});
3938

4039
afterEach(() => {
@@ -47,7 +46,7 @@ describe('fromRef', () => {
4746
const obs = fromRef(itemRef, 'value');
4847
let count = 0;
4948
expect(count).toEqual(0);
50-
const sub = obs.subscribe(change => {
49+
const sub = obs.subscribe(() => {
5150
count = count + 1;
5251
expect(count).toEqual(1);
5352
sub.unsubscribe();
@@ -90,8 +89,8 @@ describe('fromRef', () => {
9089

9190
// Error
9291
const errorObservable = fromRef({
93-
once: (event, snap, err) => err()
94-
} as any,
92+
once: (event, snap, err) => err()
93+
} as any,
9594
'value',
9695
'once',
9796
testScheduler
@@ -120,7 +119,8 @@ describe('fromRef', () => {
120119
scheduler
121120
);
122121
completeObservable.subscribe(
123-
() => { },
122+
() => {
123+
},
124124
() => fail('Should not error'),
125125
() => expect(Zone.current.name).toEqual('ExpectedZone')
126126
);
@@ -133,7 +133,7 @@ describe('fromRef', () => {
133133
const itemRef = ref(rando());
134134
itemRef.set({});
135135
const obs = fromRef(itemRef, 'value');
136-
const sub = obs.pipe(take(1)).subscribe(change => {
136+
obs.pipe(take(1)).subscribe(change => {
137137
expect(change.payload.exists()).toEqual(false);
138138
expect(change.payload.val()).toEqual(null);
139139
}).add(done);
@@ -143,15 +143,17 @@ describe('fromRef', () => {
143143
const itemRef = ref(rando());
144144
itemRef.set(batch);
145145
const obs = fromRef(itemRef, 'value', 'once');
146-
obs.subscribe(change => { }, () => { }, done);
146+
obs.subscribe(() => {
147+
}, () => {
148+
}, done);
147149
});
148150

149151
it('it should listen and then unsubscribe', (done) => {
150152
const itemRef = ref(rando());
151153
itemRef.set(batch);
152154
const obs = fromRef(itemRef, 'value');
153155
let count = 0;
154-
const sub = obs.subscribe(change => {
156+
const sub = obs.subscribe(() => {
155157
count = count + 1;
156158
// hard coding count to one will fail if the unsub
157159
// doesn't actually unsub
@@ -173,7 +175,7 @@ describe('fromRef', () => {
173175
count = count + 1;
174176
const { type, payload } = change;
175177
expect(type).toEqual('child_added');
176-
expect(payload.val()).toEqual(batch[payload.key!]);
178+
expect(payload.val()).toEqual(batch[payload.key]);
177179
if (count === items.length) {
178180
done();
179181
sub.unsubscribe();
@@ -230,7 +232,8 @@ describe('fromRef', () => {
230232
sub.unsubscribe();
231233
done();
232234
});
233-
itemRef.child(key).setPriority(-100, () => { });
235+
itemRef.child(key).setPriority(-100, () => {
236+
});
234237
});
235238

236239
it('should stream back a value event', (done: any) => {
@@ -252,9 +255,12 @@ describe('fromRef', () => {
252255
itemRef.set(batch);
253256
const query = itemRef.orderByChild('name').equalTo(items[0].name);
254257
const obs = fromRef(query, 'value');
255-
const sub = obs.subscribe(change => {
256-
let child;
257-
change.payload.forEach(snap => { child = snap.val(); return true; });
258+
obs.subscribe(change => {
259+
let child = null;
260+
change.payload.forEach(snap => {
261+
child = snap.val();
262+
return true;
263+
});
258264
expect(child).toEqual(items[0]);
259265
done();
260266
});

src/database/observable/fromRef.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@ interface SnapshotPrevKey<T> {
1111
* Create an observable from a Database Reference or Database Query.
1212
* @param ref Database Reference
1313
* @param event Listen event type ('value', 'added', 'changed', 'removed', 'moved')
14+
* @param listenType 'on' or 'once'
15+
* @param scheduler - Rxjs scheduler
1416
*/
15-
export function fromRef<T>(ref: DatabaseQuery, event: ListenEvent, listenType = 'on', scheduler: SchedulerLike = asyncScheduler): Observable<AngularFireAction<DatabaseSnapshot<T>>> {
17+
export function fromRef<T>(ref: DatabaseQuery,
18+
event: ListenEvent,
19+
listenType = 'on',
20+
scheduler: SchedulerLike = asyncScheduler
21+
): Observable<AngularFireAction<DatabaseSnapshot<T>>> {
1622
return new Observable<SnapshotPrevKey<T>>(subscriber => {
1723
let fn: any | null = null;
1824
fn = ref[listenType](event, (snapshot, prevKey) => {
1925
scheduler.schedule(() => {
2026
subscriber.next({ snapshot, prevKey });
2127
});
22-
if (listenType == 'once') {
28+
if (listenType === 'once') {
2329
scheduler.schedule(() => subscriber.complete());
2430
}
2531
}, err => {
2632
scheduler.schedule(() => subscriber.error(err));
2733
});
2834

29-
if (listenType == 'on') {
35+
if (listenType === 'on') {
3036
return {
3137
unsubscribe() {
3238
if (fn != null) {
@@ -35,13 +41,18 @@ export function fromRef<T>(ref: DatabaseQuery, event: ListenEvent, listenType =
3541
}
3642
};
3743
} else {
38-
return { unsubscribe() { } };
44+
return {
45+
unsubscribe() {
46+
}
47+
};
3948
}
4049
}).pipe(
4150
map(payload => {
4251
const { snapshot, prevKey } = payload;
4352
let key: string | null = null;
44-
if (snapshot.exists()) { key = snapshot.key; }
53+
if (snapshot.exists()) {
54+
key = snapshot.key;
55+
}
4556
return { type: event, payload: snapshot, prevKey, key };
4657
}),
4758
share()

0 commit comments

Comments
 (0)