K
K
kodwi2017-02-22 12:21:00
JavaScript
kodwi, 2017-02-22 12:21:00

Why does take from RxJS skip all data further without clipping?

From the method I return a chain, at the end of which .take(5).do(...). But take does not work, does not take the first 5 elements, but skips everything that came to it, further. Everything is connected, there are no errors/warnings in the console at all. What could be the problem?

getGithubAccounts(firstName: string): Observable<GithubAccount[]> {
    return this.accountList ? Observable.of(this.accountList) :
      this.init
        .delay(this.delayTime)
        .switchMap(() => this._http.get(`${this.githubUrl}${firstName}`))
        .map(list => list.json().items)
        .take(5)
        .do(accountList => this.accountList = accountList);
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2017-02-22
@kodwi

take will select the first 5 events from the stream, while you will have one event in the stream containing a list of five elements. To leave only the first five elements in the resulting list, transform the list itself
.map(list => list.json().items.slice(0, 5))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question