Improve example Documentation for Typeahead to make sense

I’m creating a typeahead that remotely calls an api every time someone types in the input, with a small delay after typing.

This code is from the bootstrap 4 typeahead example docs (Wikipedia example) makes no sense to me with all the .call and _do functions.

Angular Component

    search = (text$: Observable<string>) =>
      _do.call(
         switchMap.call(
            _do.call(distinctUntilChanged.call(
               debounceTime.call(text$, 300)),
               () => this.searching = true),
               (term) => _catch.call(
                  _do.call(this._service.search(term),
                  () => this.searchFailed = false),
                  () => {
                  this.searchFailed = true;
                  return of.call([]);
            })),
         () => this.searching = false);

HTML

          <md-input-container>
            <input mdInput [ngbTypeahead]="search"
               [(ngModel)]="model"
               [formControl]="lookupSubscriberControl"
               type="text"
               placeholder="Search by Name">
            <button type="submit" mdSuffix class="material-icons">search</button>
         </md-input-container>
  1. What does this do in English? Right now I do not understand how to read this in normal terms and therefore cannot rewrite it for my needs.

  2. Can someone help me rewrite this in a more readable format? Such as using the chained sequence of promises, or anything else that makes more sense.

1 possible answer(s) on “Improve example Documentation for Typeahead to make sense

  1. I agree that in the current form the example is very hard to read… I’m going to revert the change that introduced .call(...) as we care about this library working with the closure compiler. We don’t build demo with closure so we don’t need to keep it closure-compatible. On top of this .call are needed only because of an issue in the closure compiler itself…