K
K
Konstantin2020-10-19 19:44:15
Angular
Konstantin, 2020-10-19 19:44:15

How to exclude a repeated click event?

I have several components in the template of which the event <div (click)="edit(obj)"></div>

of the Same type handler is bound:

public edit(actdoc: any): void {
        this.applicationRelationShipsService
            .get(actdoc.actdocid)
            .pipe(
                indicate(this.loading$),
                observableTimestampResponse(),
                switchMap((actdoc) =>
                    this.dialog
                        .open(DialogAddExistingRelationshipDetailsComponent, {
                            ...this.dialogConfig,
                            height: '480px',
                            data: { appid: this.application.appid, mode: MODES.EDIT, actdoc },
                        })
                        .afterClosed()
                        .pipe(
                            filter(Boolean),
                            concatMap(() => this.applicationRelationShipsService.getByAppId(this.application.appid)),
                        ),
                ),
            )
            .subscribe((actdocs) => {
                this.actdocs = actdocs.slice();
                this.changeDetection.detectChanges();
            });
    }


How to exclude repeated click and call this.applicationRelationShipsService.get. until the dialog opens and then closes. Otherwise, a request error will not occur.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-10-20
@Junart1

event.pipe(
  exhaustMap(() => someFiniteAction)
)

On event, someFiniteAction will be fired, and until it completes, any subsequent events will be ignored. After completion will again will listen.
And you should always unsubscribe.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question