user11472365
user11472365

Reputation:

Why doesn't skipeWhile display the correct results?

SkipWhile() continues to skip elements as long as the entry condition is true. When the condition becomes false, all remaining elements will return.

What I'm trying to do are two types of conditions:

  1. It must enter when loading === false and when arrIds.length > 0
  2. It must enter when loading === false and when arrIds.length === 0

My Example:

combineLatest([this.peopleSelectorsService.loading, this.peopleSelectorsService.allIds])
    .pipe(skipWhile((observables) => !observables[0] && observables[1].length === 0))
    .subscribe((observables) => {

    });

RESULT:

enter image description here

Upvotes: 0

Views: 117

Answers (1)

bryan60
bryan60

Reputation: 29345

your first emission is [true, []]

your skip condition can be rewritten as:

skipWhile(([loading, items]) => !loading && !items.length)

in english: skip while not loading and there are not items, in your first emission case this evaluates to false && true which is false.

skipWhile stops skipping after one false result, so the first emission stops it from evaluating anymore.

you either need to adjust your logic or use a different operator. can't say for sure as you haven't outlined your expected results. what I SUSPECT you want is:

skipWhile(([loading, items]) => loading || !items.length)

which will skip the first 2 emissions and emit the third.

Upvotes: 1

Related Questions