Can't unsubscribe from ngrx store

81 Views Asked by At

I really confused with next situation. Maybe I don't understand something in browser.

I have a Subscription to select from my ngrx/entity store. It works good. Code below.

constructor(private store: Store<State>) {
    this.formConfiguration();

    this.moveTradeSubscription = this.store.select(selectTradeEntities).subscribe((tradeDictionary) => {
      const tradeFromStore = Object.values(tradeDictionary)[0];
      if (tradeFromStore !== null && tradeFromStore !== undefined && tradeFromStore.Stage === 2) {
        // this.store.dispatch(removeTrade());
        console.log('remove from panel draft stage 2');
        this.tradeDraftPanelEmitter.emit(tradeFromStore.TradeId);
        this.store.dispatch(deleteTrade({ TradeId: tradeFromStore.TradeId }));
      }
    })
  }

And you can see I have console.log('remove from panel draft stage 2');

Also I unsubscribe from my Subscription

ngOnDestroy(): void {
  this.moveTradeSubscription.unsubscribe();
}

But I have always repeat this console.log('remove from panel draft stage 2'); after destroy of component and the most strange after reload and close and open again browser.

After reload of my page.

As I understand I didn't unsubscribe

1

There are 1 best solutions below

0
On

give type moveTradeSubscription !: Subscription

Subscription comes from rxjs

and second one use

this.store.select(selectTradeEntities).pipe(take(1)).subscribe() => ...continue with your code you will use take , takeUntill accoding to you