user14480036
user14480036

Reputation:

Shoud I unsubscribe from observable in case?

I have method that is called from template:

public submit(): void {
    const data = { ...this.parcel, ...this.form.value, appid: this.appid };
    const requestEgrnData = {};

    iif(
        () => this.mode === MODES.CREATE,
        this.applicationOrderParcelsRepository
            .create(data)
            .pipe(switchMap(() => (this.cadnum.value ? this.egrnService.SendRequestGetEGRP(requestEgrnData) : of(null)))),
        this.applicationOrderParcelsRepository.update(data),
    )
        .pipe(indicate(this.loading$), observableHandlerResponse(this.messageService))
        .subscribe(() => {
            this.dialogRef.close(true);
        });
}

Should I unsubscribe from this.applicationOrderParcelsRepository and from outer this.egrnService.SendRequestGetEGRP, this.applicationOrderParcelsRepository.update?

Or enough unsubscribe from let subscription = this.applicationOrderParcelsRepository()...?

Upvotes: 0

Views: 146

Answers (2)

Marcin Milewicz
Marcin Milewicz

Reputation: 315

In your case the entire subscription is const subscription = iif(...) .subscribe(() => { this.dialogRef.close(true);});

so this subscription can be unsubscribed.

Upvotes: 2

Andrei
Andrei

Reputation: 12001

you should and only can unsubscribe only in places where you've called subscribe() (or in rare cases connect()) explicitly. the dependant "subscriptions" if any, will be auto unsubscribed when you unsubscribe from the main one

Upvotes: 2

Related Questions