react-code-dataset / react-query /examples /angular /rxjs /src /app /api /autocomplete-mock.interceptor.ts
Download react-query/examples/angular/rxjs/src/app/api/autocomplete-mock.interceptor.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/angular/rxjs/src/app/api/autocomplete-mock.interceptor.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/angular/rxjs/src/app/api/autocomplete-mock.interceptor.ts
-
curl -L -o autocomplete-mock.interceptor.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/angular/rxjs/src/app/api/autocomplete-mock.interceptor.ts
1.21 kB
| import { HttpResponse } from '@angular/common/http' | |
| import { delayWhen, of, timer } from 'rxjs' | |
| import type { Observable } from 'rxjs' | |
| import type { HttpEvent, HttpInterceptorFn } from '@angular/common/http' | |
| export const autocompleteMockInterceptor: HttpInterceptorFn = ( | |
| req, | |
| next, | |
| ): Observable<HttpEvent<any>> => { | |
| const { url } = req | |
| if (url.includes('/api/autocomplete')) { | |
| const term = new URLSearchParams(req.url.split('?')[1]).get('term') || '' | |
| const data = [ | |
| 'C#', | |
| 'C++', | |
| 'Go', | |
| 'Java', | |
| 'JavaScript', | |
| 'Kotlin', | |
| 'Lisp', | |
| 'Objective-C', | |
| 'PHP', | |
| 'Perl', | |
| 'Python', | |
| 'R', | |
| 'Ruby', | |
| 'Rust', | |
| 'SQL', | |
| 'Scala', | |
| 'Shell', | |
| 'Swift', | |
| 'TypeScript', | |
| ] | |
| // Simulate network latency with a random delay between 100ms and 500ms | |
| const delayDuration = Math.random() * (500 - 100) + 100 | |
| return of( | |
| new HttpResponse({ | |
| status: 200, | |
| body: { | |
| suggestions: data.filter((item) => | |
| item.toLowerCase().startsWith(term.toLowerCase()), | |
| ), | |
| }, | |
| }), | |
| ).pipe(delayWhen(() => timer(delayDuration))) | |
| } | |
| return next(req) | |
| } | |