K
K
Konstantin2020-11-20 22:36:41
Angular
Konstantin, 2020-11-20 22:36:41

Why is the internal observer called?

There is such a stream of clicks:

this.createReestrClick
            .pipe(
                switchMap(() => this.documentsRepository.selectedDocumentsFilesIds$),
                tap((ids) => console.log(ids)),
            )
            .subscribe();


In its turn
this.documentsRepository.selectedDocumentsFilesIds$
also broadcasts a stream.

Why even despite the fact that the button is not clicked is an internal stream
switchMap(() => this.documentsRepository.selectedDocumentsFilesIds$),
emitt values?

How to achieve that the stream works only on click - as it is now:
public createReestr() {
        this.createReestrClick.next();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin, 2020-11-21
@Junart1

Worked thanks to take(1):

this.createReestrClick
            .pipe(mergeMap(() => this.documentsRepository.selectedDocumentsFilesIds$.pipe(take(1))))
            .subscribe((r) => {
                console.log(r);
            });

Although I don't fully understand why it works like that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question