|
1 | 1 | import { DatabaseQuery, AngularFireList, ChildEvent } from '../interfaces';
|
2 | 2 | import { snapshotChanges } from './snapshot-changes';
|
3 |
| -import { createStateChanges } from './state-changes'; |
4 |
| -import { createAuditTrail } from './audit-trail'; |
| 3 | +import { stateChanges } from './state-changes'; |
| 4 | +import { auditTrail } from './audit-trail'; |
5 | 5 | import { createDataOperationMethod } from './data-operation';
|
6 | 6 | import { createRemoveMethod } from './remove';
|
7 | 7 | import { AngularFireDatabase } from '../database';
|
8 | 8 | import { map } from 'rxjs/operators';
|
9 | 9 |
|
10 |
| -export function createListReference<T>(query: DatabaseQuery, afDatabase: AngularFireDatabase): AngularFireList<T> { |
| 10 | +export function createListReference<T=any>(query: DatabaseQuery, afDatabase: AngularFireDatabase): AngularFireList<T> { |
11 | 11 | return {
|
12 | 12 | query,
|
13 | 13 | update: createDataOperationMethod<Partial<T>>(query.ref, 'update'),
|
14 | 14 | set: createDataOperationMethod<T>(query.ref, 'set'),
|
15 | 15 | push: (data: T) => query.ref.push(data),
|
16 | 16 | remove: createRemoveMethod(query.ref),
|
17 | 17 | snapshotChanges(events?: ChildEvent[]) {
|
18 |
| - const snapshotChanges$ = snapshotChanges(query, events); |
| 18 | + const snapshotChanges$ = snapshotChanges<T>(query, events); |
19 | 19 | return afDatabase.scheduler.keepUnstableUntilFirst(
|
20 | 20 | afDatabase.scheduler.runOutsideAngular(
|
21 | 21 | snapshotChanges$
|
22 | 22 | )
|
23 | 23 | );
|
24 | 24 | },
|
25 |
| - stateChanges: createStateChanges(query, afDatabase), |
26 |
| - auditTrail: createAuditTrail(query, afDatabase), |
27 |
| - valueChanges<T>(events?: ChildEvent[]) { |
28 |
| - const snapshotChanges$ = snapshotChanges(query, events); |
| 25 | + stateChanges(events?: ChildEvent[]) { |
| 26 | + const stateChanges$ = stateChanges<T>(query, events); |
| 27 | + return afDatabase.scheduler.keepUnstableUntilFirst( |
| 28 | + afDatabase.scheduler.runOutsideAngular( |
| 29 | + stateChanges$ |
| 30 | + ) |
| 31 | + ); |
| 32 | + }, |
| 33 | + auditTrail(events?: ChildEvent[]) { |
| 34 | + const auditTrail$ = auditTrail<T>(query, events) |
| 35 | + return afDatabase.scheduler.keepUnstableUntilFirst( |
| 36 | + afDatabase.scheduler.runOutsideAngular( |
| 37 | + auditTrail$ |
| 38 | + ) |
| 39 | + ); |
| 40 | + }, |
| 41 | + valueChanges(events?: ChildEvent[]) { |
| 42 | + const snapshotChanges$ = snapshotChanges<T>(query, events); |
29 | 43 | return afDatabase.scheduler.keepUnstableUntilFirst(
|
30 | 44 | afDatabase.scheduler.runOutsideAngular(
|
31 | 45 | snapshotChanges$
|
32 | 46 | )
|
33 | 47 | ).pipe(
|
34 |
| - map(actions => actions.map(a => a.payload.val())) |
| 48 | + map(actions => actions.map(a => a.payload.val() as T)) |
35 | 49 | );
|
36 | 50 | }
|
37 | 51 | }
|
|
0 commit comments