Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update operator imports in examples #6678

Merged
6 changes: 2 additions & 4 deletions src/internal/Observable.ts
Expand Up @@ -263,8 +263,7 @@ export class Observable<T> implements Subscribable<T> {
* ### Example:
*
* ```ts
* import { interval } from 'rxjs';
* import { take } from 'rxjs/operators';
* import { interval, take } from 'rxjs';
*
* const source$ = interval(1000).pipe(take(4));
*
Expand Down Expand Up @@ -423,8 +422,7 @@ export class Observable<T> implements Subscribable<T> {
*
* ### Example
* ```ts
* import { interval } from 'rxjs';
* import { map, filter, scan } from 'rxjs/operators';
* import { interval, filter, map, scan } from 'rxjs';
*
* interval(1000)
* .pipe(
Expand Down
18 changes: 6 additions & 12 deletions src/internal/ajax/ajax.ts
Expand Up @@ -15,8 +15,7 @@ export interface AjaxCreationMethod {
* ### Example
* ```ts
* import { ajax } from 'rxjs/ajax';
* import { map, catchError } from 'rxjs/operators';
* import { of } from 'rxjs';
* import { map, catchError, of } from 'rxjs';
*
* const obs$ = ajax({
* method: 'GET',
Expand All @@ -41,8 +40,7 @@ export interface AjaxCreationMethod {
* ### Example
* ```ts
* import { ajax } from 'rxjs/ajax';
* import { map, catchError } from 'rxjs/operators';
* import { of } from 'rxjs';
* import { map, catchError, of } from 'rxjs';
*
* const obs$ = ajax(`https://api.github.com/users?per_page=5`).pipe(
* map(userResponse => console.log('users: ', userResponse)),
Expand Down Expand Up @@ -177,8 +175,7 @@ function ajaxGetJSON<T>(url: string, headers?: Record<string, string>): Observab
* ## Using ajax() to fetch the response object that is being returned from API.
* ```ts
* import { ajax } from 'rxjs/ajax';
* import { map, catchError } from 'rxjs/operators';
* import { of } from 'rxjs';
* import { map, catchError, of } from 'rxjs';
*
* const obs$ = ajax(`https://api.github.com/users?per_page=5`).pipe(
* map(userResponse => console.log('users: ', userResponse)),
Expand All @@ -192,8 +189,7 @@ function ajaxGetJSON<T>(url: string, headers?: Record<string, string>): Observab
* ## Using ajax.getJSON() to fetch data from API.
* ```ts
* import { ajax } from 'rxjs/ajax';
* import { map, catchError } from 'rxjs/operators';
* import { of } from 'rxjs';
* import { map, catchError, of } from 'rxjs';
*
* const obs$ = ajax.getJSON(`https://api.github.com/users?per_page=5`).pipe(
* map(userResponse => console.log('users: ', userResponse)),
Expand All @@ -208,8 +204,7 @@ function ajaxGetJSON<T>(url: string, headers?: Record<string, string>): Observab
* ## Using ajax() with object as argument and method POST with a two seconds delay.
* ```ts
* import { ajax } from 'rxjs/ajax';
* import { map, catchError } from 'rxjs/operators';
* import { of } from 'rxjs';
* import { map, catchError, of } from 'rxjs';
*
* const users = ajax({
* url: 'https://httpbin.org/delay/2',
Expand All @@ -234,8 +229,7 @@ function ajaxGetJSON<T>(url: string, headers?: Record<string, string>): Observab
* ## Using ajax() to fetch. An error object that is being returned from the request.
* ```ts
* import { ajax } from 'rxjs/ajax';
* import { map, catchError } from 'rxjs/operators';
* import { of } from 'rxjs';
* import { map, catchError, of } from 'rxjs';
*
* const obs$ = ajax(`https://api.github.com/404`).pipe(
* map(userResponse => console.log('users: ', userResponse)),
Expand Down
3 changes: 1 addition & 2 deletions src/internal/lastValueFrom.ts
Expand Up @@ -32,8 +32,7 @@ export function lastValueFrom<T>(source: Observable<T>): Promise<T>;
* an async function.
*
* ```ts
* import { interval, lastValueFrom } from 'rxjs';
* import { take } from 'rxjs/operators';
* import { interval, take, lastValueFrom } from 'rxjs';
*
* async function execute() {
* const source$ = interval(2000).pipe(take(10));
Expand Down
11 changes: 4 additions & 7 deletions src/internal/observable/combineLatest.ts
Expand Up @@ -112,7 +112,7 @@ export function combineLatest<T extends Record<string, ObservableInput<any>>>(
* ## Examples
* ### Combine two timer Observables
* ```ts
* import { combineLatest, timer } from 'rxjs';
* import { timer, combineLatest } from 'rxjs';
*
* const firstTimer = timer(0, 1000); // emit 0, 1, 2... after every second, starting from now
* const secondTimer = timer(500, 1000); // emit 0, 1, 2... after every second, starting 0,5s from now
Expand All @@ -126,8 +126,7 @@ export function combineLatest<T extends Record<string, ObservableInput<any>>>(
* ```
* ### Combine a dictionary of Observables
* ```ts
* import { combineLatest, of } from 'rxjs';
* import { delay, startWith } from 'rxjs/operators';
* import { of, delay, startWith, combineLatest } from 'rxjs';
*
* const observables = {
* a: of(1).pipe(delay(1000), startWith(0)),
Expand All @@ -144,8 +143,7 @@ export function combineLatest<T extends Record<string, ObservableInput<any>>>(
* ```
* ### Combine an array of Observables
* ```ts
* import { combineLatest, of } from 'rxjs';
* import { delay, startWith } from 'rxjs/operators';
* import { of, delay, startWith, combineLatest } from 'rxjs';
*
* const observables = [1, 5, 10].map(
* n => of(n).pipe(
Expand All @@ -165,8 +163,7 @@ export function combineLatest<T extends Record<string, ObservableInput<any>>>(
*
* ### Use map operator to dynamically calculate the Body-Mass Index
* ```ts
* import { combineLatest, of } from 'rxjs';
* import { map } from 'rxjs/operators';
* import { of, combineLatest, map } from 'rxjs';
*
* const weight = of(70, 72, 76, 79, 75);
* const height = of(1.76, 1.77, 1.78);
Expand Down
9 changes: 3 additions & 6 deletions src/internal/observable/concat.ts
Expand Up @@ -49,8 +49,7 @@ export function concat<T extends readonly unknown[]>(
* ## Examples
* ### Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10
* ```ts
* import { concat, interval, range } from 'rxjs';
* import { take } from 'rxjs/operators';
* import { interval, take, range, concat } from 'rxjs';
*
* const timer = interval(1000).pipe(take(4));
* const sequence = range(1, 10);
Expand All @@ -63,8 +62,7 @@ export function concat<T extends readonly unknown[]>(
*
* ### Concatenate 3 Observables
* ```ts
* import { concat, interval } from 'rxjs';
* import { take } from 'rxjs/operators';
* import { interval, take, concat } from 'rxjs';
*
* const timer1 = interval(1000).pipe(take(10));
* const timer2 = interval(2000).pipe(take(6));
Expand All @@ -82,8 +80,7 @@ export function concat<T extends readonly unknown[]>(
*
* ### Concatenate the same Observable to repeat it
* ```ts
* import { concat, interval } from 'rxjs';
* import { take } from 'rxjs/operators';
* import { interval, take, concat } from 'rxjs';
*
* const timer = interval(1000).pipe(take(2));
*
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/dom/animationFrames.ts
Expand Up @@ -24,8 +24,7 @@ import { animationFrameProvider } from '../../scheduler/animationFrameProvider';
* Tweening a div to move it on the screen
*
* ```ts
* import { animationFrames } from 'rxjs';
* import { map, takeWhile, endWith } from 'rxjs/operators';
* import { animationFrames, map, takeWhile, endWith } from 'rxjs';
*
* function tween(start: number, end: number, duration: number) {
* const diff = end - start;
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/dom/fetch.ts
Expand Up @@ -29,9 +29,8 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab
* ### Basic Use
*
* ```ts
* import { of } from 'rxjs';
* import { fromFetch } from 'rxjs/fetch';
* import { switchMap, catchError } from 'rxjs/operators';
* import { switchMap, of, catchError } from 'rxjs';
*
* const data$ = fromFetch('https://api.github.com/users?per_page=5').pipe(
* switchMap(response => {
Expand Down
6 changes: 2 additions & 4 deletions src/internal/observable/empty.ts
Expand Up @@ -44,8 +44,7 @@ export const EMPTY = new Observable<never>((subscriber) => subscriber.complete()
* ### Emit the number 7, then complete
*
* ```ts
* import { empty } from 'rxjs';
* import { startWith } from 'rxjs/operators';
* import { empty, startWith } from 'rxjs';
*
* const result = empty().pipe(startWith(7));
* result.subscribe(x => console.log(x));
Expand All @@ -57,8 +56,7 @@ export const EMPTY = new Observable<never>((subscriber) => subscriber.complete()
* ### Map and flatten only odd numbers to the sequence 'a', 'b', 'c'
*
* ```ts
* import { empty, interval, of } from 'rxjs';
* import { mergeMap } from 'rxjs/operators';
* import { interval, mergeMap, of, empty } from 'rxjs';
*
* const interval$ = interval(1000);
* const result = interval$.pipe(
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/from.ts
Expand Up @@ -43,8 +43,7 @@ export function from<O extends ObservableInput<any>>(input: O, scheduler: Schedu
* ### Convert an infinite iterable (from a generator) to an Observable
*
* ```ts
* import { from } from 'rxjs';
* import { take } from 'rxjs/operators';
* import { from, take } from 'rxjs';
*
* function* generateDoubles(seed) {
* let i = seed;
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/interval.ts
Expand Up @@ -22,8 +22,7 @@ import { timer } from './timer';
* ## Example
* Emits ascending numbers, one every second (1000ms) up to the number 3
* ```ts
* import { interval } from 'rxjs';
* import { take } from 'rxjs/operators';
* import { interval, take } from 'rxjs';
*
* const numbers = interval(1000);
*
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/merge.ts
Expand Up @@ -51,8 +51,7 @@ export function merge<A extends readonly unknown[]>(
*
* ### Merge together 3 Observables, but only 2 run concurrently
* ```ts
* import { merge, interval } from 'rxjs';
* import { take } from 'rxjs/operators';
* import { interval, take, merge } from 'rxjs';
*
* const timer1 = interval(1000).pipe(take(10));
* const timer2 = interval(2000).pipe(take(6));
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/never.ts
Expand Up @@ -15,8 +15,7 @@ import { noop } from '../util/noop';
* ## Example
* ### Emit the number 7, then never emit anything else (not even complete)
* ```ts
* import { NEVER } from 'rxjs';
* import { startWith } from 'rxjs/operators';
* import { NEVER, startWith } from 'rxjs';
*
* function info() {
* console.log('Will not be called');
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/onErrorResumeNext.ts
Expand Up @@ -34,8 +34,7 @@ export function onErrorResumeNext<A extends readonly unknown[]>(...sources: [...
* ## Example
* Subscribe to the next Observable after map fails</caption>
* ```ts
* import { onErrorResumeNext, of } from 'rxjs';
* import { map } from 'rxjs/operators';
* import { onErrorResumeNext, of, map } from 'rxjs';
*
* onErrorResumeNext(
* of(1, 2, 3, 0).pipe(
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/race.ts
Expand Up @@ -31,8 +31,7 @@ export function race<T extends readonly unknown[]>(...inputs: [...ObservableInpu
* ### Subscribes to the observable that was the first to start emitting.
*
* ```ts
* import { race, interval } from 'rxjs';
* import { mapTo } from 'rxjs/operators';
* import { interval, mapTo, race } from 'rxjs';
*
* const obs1 = interval(1000).pipe(mapTo('fast one'));
* const obs2 = interval(3000).pipe(mapTo('medium one'));
Expand Down
6 changes: 2 additions & 4 deletions src/internal/observable/throwError.ts
Expand Up @@ -50,8 +50,7 @@ import { isFunction } from '../util/isFunction';
* with a callback, is usually not necessary:
*
* ```ts
* import { throwError, timer, of } from 'rxjs';
* import { concatMap } from 'rxjs/operators';
* import { of, concatMap, timer, throwError } from 'rxjs';
*
* const delays$ = of(1000, 2000, Infinity, 3000);
*
Expand All @@ -74,8 +73,7 @@ import { isFunction } from '../util/isFunction';
* You can just throw the error instead:
*
* ```ts
* import { throwError, timer, of } from 'rxjs';
* import { concatMap } from 'rxjs/operators';
* import { of, concatMap, timer } from 'rxjs';
*
* const delays$ = of(1000, 2000, Infinity, 3000);
*
Expand Down
6 changes: 2 additions & 4 deletions src/internal/observable/timer.ts
Expand Up @@ -26,8 +26,7 @@ import { isValidDate } from '../util/isDate';
* a few seconds and start a subscription to a source.
*
* ```ts
* import { timer, of } from 'rxjs';
* import { concatMapTo } from 'rxjs/operators';
* import { of, timer, concatMapTo } from 'rxjs';
*
* // This could be any observable
* const source = of(1, 2, 3);
Expand All @@ -47,8 +46,7 @@ import { isValidDate } from '../util/isDate';
* {@link takeUntil}.
*
* ```ts
* import { interval, timer } from 'rxjs';
* import { takeUntil } from 'rxjs/operators';
* import { interval, takeUntil, timer } from 'rxjs';
*
* // Build a Date object that marks the
* // next minute.
Expand Down
3 changes: 1 addition & 2 deletions src/internal/observable/zip.ts
Expand Up @@ -28,8 +28,7 @@ export function zip<A extends readonly unknown[], R>(
* Combine age and name from different sources
*
* ```ts
* import { zip, of } from 'rxjs';
* import { map } from 'rxjs/operators';
* import { of, zip, map } from 'rxjs';
*
* let age$ = of(27, 25, 29);
* let name$ = of('Foo', 'Bar', 'Beer');
Expand Down
3 changes: 1 addition & 2 deletions src/internal/operators/audit.ts
Expand Up @@ -30,8 +30,7 @@ import { OperatorSubscriber } from './OperatorSubscriber';
*
* Emit clicks at a rate of at most one click per second
* ```ts
* import { fromEvent, interval } from 'rxjs';
* import { audit } from 'rxjs/operators'
* import { fromEvent, audit, interval } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const result = clicks.pipe(audit(ev => interval(1000)));
Expand Down
3 changes: 1 addition & 2 deletions src/internal/operators/auditTime.ts
Expand Up @@ -28,8 +28,7 @@ import { MonoTypeOperatorFunction, SchedulerLike } from '../types';
*
* Emit clicks at a rate of at most one click per second
* ```ts
* import { fromEvent } from 'rxjs';
* import { auditTime } from 'rxjs/operators';
* import { fromEvent, auditTime } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const result = clicks.pipe(auditTime(1000));
Expand Down
3 changes: 1 addition & 2 deletions src/internal/operators/buffer.ts
Expand Up @@ -22,8 +22,7 @@ import { OperatorSubscriber } from './OperatorSubscriber';
* On every click, emit array of most recent interval events
*
* ```ts
* import { fromEvent, interval } from 'rxjs';
* import { buffer } from 'rxjs/operators';
* import { fromEvent, interval, buffer } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const intervalEvents = interval(1000);
Expand Down
6 changes: 2 additions & 4 deletions src/internal/operators/bufferCount.ts
Expand Up @@ -23,8 +23,7 @@ import { arrRemove } from '../util/arrRemove';
* Emit the last two click events as an array
*
* ```ts
* import { fromEvent } from 'rxjs';
* import { bufferCount } from 'rxjs/operators';
* import { fromEvent, bufferCount } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const buffered = clicks.pipe(bufferCount(2));
Expand All @@ -34,8 +33,7 @@ import { arrRemove } from '../util/arrRemove';
* On every click, emit the last two click events as an array
*
* ```ts
* import { fromEvent } from 'rxjs';
* import { bufferCount } from 'rxjs/operators';
* import { fromEvent, bufferCount } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const buffered = clicks.pipe(bufferCount(2, 1));
Expand Down
6 changes: 2 additions & 4 deletions src/internal/operators/bufferTime.ts
Expand Up @@ -44,8 +44,7 @@ export function bufferTime<T>(
* Every second, emit an array of the recent click events
*
* ```ts
* import { fromEvent } from 'rxjs';
* import { bufferTime } from 'rxjs/operators';
* import { fromEvent, bufferTime } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const buffered = clicks.pipe(bufferTime(1000));
Expand All @@ -55,8 +54,7 @@ export function bufferTime<T>(
* Every 5 seconds, emit the click events from the next 2 seconds
*
* ```ts
* import { fromEvent } from 'rxjs';
* import { bufferTime } from 'rxjs/operators';
* import { fromEvent, bufferTime } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const buffered = clicks.pipe(bufferTime(2000, 5000));
Expand Down
3 changes: 1 addition & 2 deletions src/internal/operators/bufferToggle.ts
Expand Up @@ -26,8 +26,7 @@ import { arrRemove } from '../util/arrRemove';
* Every other second, emit the click events from the next 500ms
*
* ```ts
* import { fromEvent, interval, EMPTY } from 'rxjs';
* import { bufferToggle } from 'rxjs/operators';
* import { fromEvent, interval, bufferToggle, EMPTY } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const openings = interval(1000);
Expand Down
3 changes: 1 addition & 2 deletions src/internal/operators/bufferWhen.ts
Expand Up @@ -24,8 +24,7 @@ import { innerFrom } from '../observable/innerFrom';
* Emit an array of the last clicks every [1-5] random seconds
*
* ```ts
* import { fromEvent, interval } from 'rxjs';
* import { bufferWhen } from 'rxjs/operators';
* import { fromEvent, bufferWhen, interval } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const buffered = clicks.pipe(bufferWhen(() =>
Expand Down