optimize read calls
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {Observable} from 'rxjs';
|
||||
import {DbService} from '../../../services/db.service';
|
||||
import {Show} from './show';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {map, shareReplay} from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ShowDataService {
|
||||
public list$ = new BehaviorSubject<Show[]>([]);
|
||||
private collection = 'shows';
|
||||
public list$: Observable<Show[]> = this.dbService.col$<Show>(this.collection).pipe(
|
||||
// server-side ordering cuts client work and keeps stable order across subscribers
|
||||
map(shows => [...shows].sort((a, b) => a.date.toMillis() - b.date.toMillis())),
|
||||
shareReplay({
|
||||
bufferSize: 1,
|
||||
refCount: true,
|
||||
})
|
||||
);
|
||||
|
||||
public constructor(private dbService: DbService) {
|
||||
this.dbService.col$<Show>(this.collection).subscribe(_ => this.list$.next(_));
|
||||
}
|
||||
public constructor(private dbService: DbService) {}
|
||||
|
||||
public listRaw$ = () => this.dbService.col$<Show>(this.collection);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user