Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70429

NGRX multiple subscription issue with Ionic 4

$
0
0

@abhi03 wrote:

I am using ionic 4.1 with ngrx. I have a user selector on Page A and Page b both.

export class ComponentA implements OnInit, OnDestroy {

  private readonly ngUnsubscribe: Subject<void> = new Subject<void>();
  user:any;
  constructor(
    private readonly store: Store<AppState>,
  ) { }

ngOnInit(){}

  ionViewWillEnter(): void {
    this.store.select(getUserState)
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe((user) => {
        this.user = user;
      });
  }

  ionViewWillLeave(): void {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
    getUserState.release();
  }  

Same subscriptions on page b , when i move from page a to b unsubscribe works but then when i move from b to a and then a to b … subscription on page a doesn’t get unsubscribe. If you traverse back 5 times 5 subscription remains on page a.Both pages get notification. I know in ionic previous page remains in stack so onDestroy() never gets called on forward navigation that is why i have put in subscription and unsubscription in ionic lifecyle hooks.
Not sure if i am not subscribing the right way or missing something. This is giving me hard time.
Please suggest how to fix this . Thanks in advance.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>