MCPcopy
hub / github.com/angular/angularfire / fromRef

Function fromRef

src/compat/database/observable/fromRef.ts:17–61  ·  view source on GitHub ↗
(ref: DatabaseQuery,
                           event: ListenEvent,
                           listenType = 'on',
                           scheduler: SchedulerLike = asyncScheduler
)

Source from the content-addressed store, hash-verified

15 * @param scheduler - Rxjs scheduler
16 */
17export function fromRef<T>(ref: DatabaseQuery,
18 event: ListenEvent,
19 listenType = 'on',
20 scheduler: SchedulerLike = asyncScheduler
21): Observable<AngularFireAction<DatabaseSnapshot<T>>> {
22 return new Observable<SnapshotPrevKey<T>>(subscriber => {
23 let fn: any = null;
24 fn = ref[listenType](event, (snapshot, prevKey) => {
25 scheduler.schedule(() => {
26 subscriber.next({ snapshot, prevKey });
27 });
28 if (listenType === 'once') {
29 scheduler.schedule(() => subscriber.complete());
30 }
31 }, err => {
32 scheduler.schedule(() => subscriber.error(err));
33 });
34
35 if (listenType === 'on') {
36 return {
37 unsubscribe() {
38 if (fn != null) {
39 ref.off(event, fn);
40 }
41 }
42 };
43 } else {
44 return {
45 // eslint-disable-next-line @typescript-eslint/no-empty-function
46 unsubscribe() {
47 }
48 };
49 }
50 }).pipe(
51 map(payload => {
52 const { snapshot, prevKey } = payload;
53 let key: string | null = null;
54 if (snapshot.exists()) {
55 key = snapshot.key;
56 }
57 return { type: event, payload: snapshot, prevKey, key };
58 }),
59 share()
60 );
61}

Callers 5

listChangesFunction · 0.90
loadedDataFunction · 0.90
stateChangesFunction · 0.90
fromRef.spec.tsFile · 0.90

Calls 2

scheduleMethod · 0.80
existsMethod · 0.65

Tested by

no test coverage detected