1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

takeUntil() after a filter() behaves differently from take(n) in pipe

Discussão em 'Angular' iniciado por Jagan Pandurangan, Setembro 25, 2024.

  1. this.activatedRoute.queryParamMap
    .pipe(
    // activatedRoute.queryParamMap emits null values first. So let's avoid it
    filter((paramMap) => paramMap && paramMap.keys.length > 0),
    // unsubscribe immediately if some params are found
    take(1),
    // If the params are really empty, filter will never pass. So let's unsubscribe after sometime
    takeUntil(timer(1000)),
    delay(1),
    combineLatestWith(this.sortableColumns$),
    )
    .subscribe(([paramMap, sortableColumns]) => {
    console.log("paramMap")
    this.setTableOptionsFromUrl(paramMap, sortableColumns);
    });


    I have the above code.

    • So take(1) unsubscribes from the source observable only when the filter passes after a valid emission from source (only when there is atleast one paramMap)
    • takeUntil also comes after the filter but it unsubscribes from the source irrespective of whether the filter passes or not once the timer emits

    My question is,

    • If filter blocks the pipeline until it passes shouldn't it block takeUntil too?
    • If this is the expected behaviour, how can I know which operators will be blocked by the filter operator and which all will not be
    • If this is not the expected behaviour, how else can we achieve this?

    Continue reading...

Compartilhe esta Página