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

Function createListReference

src/compat/database/list/create-reference.ts:13–50  ·  view source on GitHub ↗
(query: DatabaseQuery, afDatabase: AngularFireDatabase, injector?: Injector)

Source from the content-addressed store, hash-verified

11import { stateChanges } from './state-changes';
12
13export function createListReference<T= any>(query: DatabaseQuery, afDatabase: AngularFireDatabase, injector?: Injector): AngularFireList<T> {
14 const outsideAngularScheduler = afDatabase.schedulers.outsideAngular;
15 const refInZone = inject(NgZone).run(() => query.ref);
16 return {
17 query,
18 update: createDataOperationMethod(refInZone, 'update'),
19 set: createDataOperationMethod(refInZone, 'set'),
20 push: (data: T) => refInZone.push(data),
21 remove: createRemoveMethod(refInZone),
22 snapshotChanges(events?: ChildEvent[]) {
23 return snapshotChanges<T>(query, events, outsideAngularScheduler).pipe(pendingUntilEvent(injector));
24 },
25 stateChanges(events?: ChildEvent[]) {
26 return stateChanges<T>(query, events, outsideAngularScheduler).pipe(pendingUntilEvent(injector));
27 },
28 auditTrail(events?: ChildEvent[]) {
29 return auditTrail<T>(query, events, outsideAngularScheduler).pipe(pendingUntilEvent(injector));
30 },
31 valueChanges<K extends string>(events?: ChildEvent[], options?: {idField?: K}): Observable<(T & Record<string, string>)[]> {
32 const snapshotChanges$ = snapshotChanges<T>(query, events, outsideAngularScheduler);
33 return snapshotChanges$.pipe(
34 map(actions => actions.map(a => {
35 if (options && options.idField) {
36 return {
37 ...a.payload.val() as T,
38 ...{
39 [options.idField]: a.key
40 }
41 };
42 } else {
43 return a.payload.val() as T & Record<string, string>
44 }
45 })),
46 pendingUntilEvent(injector)
47 );
48 }
49 };
50}

Callers 1

listMethod · 0.90

Calls 3

createRemoveMethodFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected