I found this code online and trying to understand it.
public searchFunctionFactory($index: any): (text: Observable<string>) => Observable<any[]> {
//Create a function that considers the specified $index parameter value
let getCities = (text$: Observable<string>) =>
text$
.debounceTime(300)
.distinctUntilChanged()
.switchMap( query => {
//some logic involving $index here
//...
//query.length < 2 ? [] : this.apiService.getCities(query).catch(() => {
//return Observable.of([]);
});
//Return that "custom" function, which will in turn be called by the ngbTypescript component
return getCities;
}
My question revolves around the method signature.
public searchFunctionFactory($index: any): (text: Observable<string>) => Observable<any[]>
I understand
$index: any is an input parameter of type Any.
The function returns Observable an observable of any.
But what is
: (text: Observable<string>)
Is it a second parameter?
If its a second parameter shouldn't it be
public searchFunctionFactory($index: any ,text: Observable<string>) => Observable<any[]>