I have a sidebar with movie genres and movie titles as content, it initially loads with a hard-coded value, later when user selects another genre from the sidebar, the subject is updatet with .next(genreId), I crated a pairing helper observable from the subject, it keeps track of the selected genres as such [prevValue, currValue] (initiated with [null, 27]. On a subscribe, the initial val prints to the console, but when a user select another genreId, it does not print it. Where did I go wrong?
private genreSelectedSubject = new Subject<number | null>()
genreSelected$ = this.genreSelectedSubject.asObservable()
genreSelectedPairHistory$ = this.genreSelected$.pipe(
startWith(null, 28), // empty value to fill-in the buffer
distinctUntilChanged(),
pairwise(), // pairs into [prevValue, currValue]
shareReplay({ refCount: true, bufferSize: 1}),
)
// used in the view
onGenreSelected(genreId: number | null) {
if (genreId !== null) {
this.genreSelectedSubject.next(genreId)
}
}
then, in ngOnInit (or subscribtion via async pipe)
ngOnInit(): void {
this.genreSelectedPairHistory$.subscribe(val => console.log('SUBSCRIBE', val))
// prints: SUBSCRIBE [null, 28]
}
later, when I select different genre from the view, it does not print