[RxJS] Using iif

If you have a popup window, if value is false should close the popup, true is displaying the popup.

But if value is ture, you want to delay 365ms before it open the popup;

If value is false, you want to close the popup right away.

    this.isOpen$ = merge(
      this.closeDialogSubject.asObservable().pipe(mapTo(false)),
      this.display$.pipe(mergeMap((open: boolean) => iif(() => open, timer(DEBOUNCE_TIME).pipe(mapTo(true)), of(false))))
    );

 

posted @ 2022-02-04 17:00  Zhentiw  阅读(47)  评论(0编辑  收藏  举报