From 8b43097ef744f1fd661a0b1bb447a4e4e91eb004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Sun, 5 Dec 2021 15:18:34 +0100 Subject: [PATCH 01/11] docs: update operator imports in examples --- src/internal/Observable.ts | 6 ++---- src/internal/ajax/ajax.ts | 18 ++++++------------ src/internal/lastValueFrom.ts | 3 +-- src/internal/observable/combineLatest.ts | 11 ++++------- src/internal/observable/concat.ts | 9 +++------ src/internal/observable/dom/animationFrames.ts | 3 +-- src/internal/observable/dom/fetch.ts | 3 +-- src/internal/observable/empty.ts | 6 ++---- src/internal/observable/from.ts | 3 +-- src/internal/observable/interval.ts | 3 +-- src/internal/observable/merge.ts | 3 +-- src/internal/observable/never.ts | 3 +-- src/internal/observable/onErrorResumeNext.ts | 3 +-- src/internal/observable/race.ts | 3 +-- src/internal/observable/throwError.ts | 6 ++---- src/internal/observable/timer.ts | 6 ++---- src/internal/observable/zip.ts | 3 +-- src/internal/operators/audit.ts | 3 +-- src/internal/operators/auditTime.ts | 3 +-- src/internal/operators/buffer.ts | 3 +-- src/internal/operators/bufferCount.ts | 6 ++---- src/internal/operators/bufferTime.ts | 6 ++---- src/internal/operators/bufferToggle.ts | 3 +-- src/internal/operators/bufferWhen.ts | 3 +-- src/internal/operators/catchError.ts | 9 +++------ src/internal/operators/combineLatestAll.ts | 3 +-- src/internal/operators/combineLatestWith.ts | 3 +-- src/internal/operators/concatAll.ts | 3 +-- src/internal/operators/concatMap.ts | 3 +-- src/internal/operators/concatMapTo.ts | 3 +-- src/internal/operators/concatWith.ts | 3 +-- src/internal/operators/connect.ts | 3 +-- src/internal/operators/count.ts | 6 ++---- src/internal/operators/debounce.ts | 3 +-- src/internal/operators/debounceTime.ts | 3 +-- src/internal/operators/defaultIfEmpty.ts | 3 +-- src/internal/operators/delay.ts | 6 ++---- src/internal/operators/delayWhen.ts | 3 +-- src/internal/operators/dematerialize.ts | 3 +-- src/internal/operators/distinct.ts | 6 ++---- src/internal/operators/distinctUntilChanged.ts | 11 +++++------ .../operators/distinctUntilKeyChanged.ts | 6 ++---- src/internal/operators/elementAt.ts | 3 +-- src/internal/operators/endWith.ts | 3 +-- src/internal/operators/every.ts | 3 +-- src/internal/operators/exhaustAll.ts | 3 +-- src/internal/operators/exhaustMap.ts | 3 +-- src/internal/operators/expand.ts | 3 +-- src/internal/operators/filter.ts | 3 +-- src/internal/operators/finalize.ts | 6 ++---- src/internal/operators/find.ts | 3 +-- src/internal/operators/findIndex.ts | 3 +-- src/internal/operators/first.ts | 6 ++---- src/internal/operators/groupBy.ts | 6 ++---- src/internal/operators/ignoreElements.ts | 3 +-- src/internal/operators/isEmpty.ts | 6 ++---- src/internal/operators/last.ts | 6 ++---- src/internal/operators/map.ts | 3 +-- src/internal/operators/mapTo.ts | 3 +-- src/internal/operators/materialize.ts | 3 +-- src/internal/operators/max.ts | 6 ++---- src/internal/operators/mergeAll.ts | 6 ++---- src/internal/operators/mergeMap.ts | 3 +-- src/internal/operators/mergeMapTo.ts | 3 +-- src/internal/operators/mergeScan.ts | 3 +-- src/internal/operators/mergeWith.ts | 3 +-- src/internal/operators/min.ts | 6 ++---- src/internal/operators/observeOn.ts | 3 +-- src/internal/operators/onErrorResumeNext.ts | 3 +-- src/internal/operators/pairwise.ts | 3 +-- src/internal/operators/pluck.ts | 3 +-- src/internal/operators/publish.ts | 3 +-- src/internal/operators/publishLast.ts | 3 +-- src/internal/operators/raceWith.ts | 3 +-- src/internal/operators/reduce.ts | 3 +-- src/internal/operators/refCount.ts | 3 +-- src/internal/operators/repeat.ts | 6 ++---- src/internal/operators/repeatWhen.ts | 3 +-- src/internal/operators/retry.ts | 3 +-- src/internal/operators/retryWhen.ts | 3 +-- src/internal/operators/sample.ts | 3 +-- src/internal/operators/sampleTime.ts | 3 +-- src/internal/operators/scan.ts | 6 ++---- src/internal/operators/sequenceEqual.ts | 3 +-- src/internal/operators/share.ts | 6 ++---- src/internal/operators/shareReplay.ts | 6 ++---- src/internal/operators/single.ts | 3 +-- src/internal/operators/skip.ts | 3 +-- src/internal/operators/skipLast.ts | 3 +-- src/internal/operators/skipUntil.ts | 3 +-- src/internal/operators/skipWhile.ts | 6 ++---- src/internal/operators/startWith.ts | 3 +-- src/internal/operators/subscribeOn.ts | 3 +-- src/internal/operators/switchAll.ts | 3 +-- src/internal/operators/switchMap.ts | 6 ++---- src/internal/operators/switchMapTo.ts | 3 +-- src/internal/operators/take.ts | 3 +-- src/internal/operators/takeLast.ts | 3 +-- src/internal/operators/takeUntil.ts | 3 +-- src/internal/operators/takeWhile.ts | 3 +-- src/internal/operators/tap.ts | 10 +++------- src/internal/operators/throttle.ts | 3 +-- src/internal/operators/throttleTime.ts | 6 ++---- src/internal/operators/throwIfEmpty.ts | 3 +-- src/internal/operators/timeInterval.ts | 3 +-- src/internal/operators/timeout.ts | 15 +++++---------- src/internal/operators/timeoutWith.ts | 6 ++---- src/internal/operators/timestamp.ts | 3 +-- src/internal/operators/toArray.ts | 3 +-- src/internal/operators/window.ts | 3 +-- src/internal/operators/windowCount.ts | 6 ++---- src/internal/operators/windowTime.ts | 9 +++------ src/internal/operators/windowToggle.ts | 3 +-- src/internal/operators/windowWhen.ts | 3 +-- src/internal/operators/withLatestFrom.ts | 3 +-- 115 files changed, 166 insertions(+), 328 deletions(-) diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index aca3a3add8..3937f775d4 100644 --- a/src/internal/Observable.ts +++ b/src/internal/Observable.ts @@ -263,8 +263,7 @@ export class Observable implements Subscribable { * ### Example: * * ```ts - * import { interval } from 'rxjs'; - * import { take } from 'rxjs/operators'; + * import { interval, take } from 'rxjs'; * * const source$ = interval(1000).pipe(take(4)); * @@ -423,8 +422,7 @@ export class Observable implements Subscribable { * * ### Example * ```ts - * import { interval } from 'rxjs'; - * import { map, filter, scan } from 'rxjs/operators'; + * import { interval, filter, map, scan } from 'rxjs'; * * interval(1000) * .pipe( diff --git a/src/internal/ajax/ajax.ts b/src/internal/ajax/ajax.ts index e54e2cbd4c..e5964b0b60 100644 --- a/src/internal/ajax/ajax.ts +++ b/src/internal/ajax/ajax.ts @@ -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', @@ -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)), @@ -177,8 +175,7 @@ function ajaxGetJSON(url: string, headers?: Record): 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)), @@ -192,8 +189,7 @@ function ajaxGetJSON(url: string, headers?: Record): 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)), @@ -208,8 +204,7 @@ function ajaxGetJSON(url: string, headers?: Record): 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', @@ -234,8 +229,7 @@ function ajaxGetJSON(url: string, headers?: Record): 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)), diff --git a/src/internal/lastValueFrom.ts b/src/internal/lastValueFrom.ts index b70000f47e..8a47c74074 100644 --- a/src/internal/lastValueFrom.ts +++ b/src/internal/lastValueFrom.ts @@ -32,8 +32,7 @@ export function lastValueFrom(source: Observable): Promise; * 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)); diff --git a/src/internal/observable/combineLatest.ts b/src/internal/observable/combineLatest.ts index b207405fe9..65e3ded544 100644 --- a/src/internal/observable/combineLatest.ts +++ b/src/internal/observable/combineLatest.ts @@ -112,7 +112,7 @@ export function combineLatest>>( * ## 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 @@ -126,8 +126,7 @@ export function combineLatest>>( * ``` * ### 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)), @@ -144,8 +143,7 @@ export function combineLatest>>( * ``` * ### 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( @@ -165,8 +163,7 @@ export function combineLatest>>( * * ### 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); diff --git a/src/internal/observable/concat.ts b/src/internal/observable/concat.ts index 230c1a7bb9..f18037fb32 100644 --- a/src/internal/observable/concat.ts +++ b/src/internal/observable/concat.ts @@ -49,8 +49,7 @@ export function concat( * ## 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); @@ -63,8 +62,7 @@ export function concat( * * ### 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)); @@ -82,8 +80,7 @@ export function concat( * * ### 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)); * diff --git a/src/internal/observable/dom/animationFrames.ts b/src/internal/observable/dom/animationFrames.ts index 7ac4bfca82..5bbfba3181 100644 --- a/src/internal/observable/dom/animationFrames.ts +++ b/src/internal/observable/dom/animationFrames.ts @@ -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; diff --git a/src/internal/observable/dom/fetch.ts b/src/internal/observable/dom/fetch.ts index bc04708823..b95c380eb7 100644 --- a/src/internal/observable/dom/fetch.ts +++ b/src/internal/observable/dom/fetch.ts @@ -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 => { diff --git a/src/internal/observable/empty.ts b/src/internal/observable/empty.ts index 14edd1a2b9..90103d4ee8 100644 --- a/src/internal/observable/empty.ts +++ b/src/internal/observable/empty.ts @@ -44,8 +44,7 @@ export const EMPTY = new Observable((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)); @@ -57,8 +56,7 @@ export const EMPTY = new Observable((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( diff --git a/src/internal/observable/from.ts b/src/internal/observable/from.ts index 1bbea4dd92..6ab2def3d7 100644 --- a/src/internal/observable/from.ts +++ b/src/internal/observable/from.ts @@ -43,8 +43,7 @@ export function from>(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; diff --git a/src/internal/observable/interval.ts b/src/internal/observable/interval.ts index 9b195134bd..91953b53d0 100644 --- a/src/internal/observable/interval.ts +++ b/src/internal/observable/interval.ts @@ -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); * diff --git a/src/internal/observable/merge.ts b/src/internal/observable/merge.ts index 268c03363b..5522ff94d7 100644 --- a/src/internal/observable/merge.ts +++ b/src/internal/observable/merge.ts @@ -51,8 +51,7 @@ export function merge( * * ### 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)); diff --git a/src/internal/observable/never.ts b/src/internal/observable/never.ts index ead9ba1895..789fea072d 100644 --- a/src/internal/observable/never.ts +++ b/src/internal/observable/never.ts @@ -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'); diff --git a/src/internal/observable/onErrorResumeNext.ts b/src/internal/observable/onErrorResumeNext.ts index fe945c26b2..357b6eeaf6 100644 --- a/src/internal/observable/onErrorResumeNext.ts +++ b/src/internal/observable/onErrorResumeNext.ts @@ -34,8 +34,7 @@ export function onErrorResumeNext(...sources: [... * ## Example * Subscribe to the next Observable after map fails * ```ts - * import { onErrorResumeNext, of } from 'rxjs'; - * import { map } from 'rxjs/operators'; + * import { onErrorResumeNext, of, map } from 'rxjs'; * * onErrorResumeNext( * of(1, 2, 3, 0).pipe( diff --git a/src/internal/observable/race.ts b/src/internal/observable/race.ts index 2093ad926e..f26c96f2f6 100644 --- a/src/internal/observable/race.ts +++ b/src/internal/observable/race.ts @@ -31,8 +31,7 @@ export function race(...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')); diff --git a/src/internal/observable/throwError.ts b/src/internal/observable/throwError.ts index 8faab39be4..f4f1687cf0 100644 --- a/src/internal/observable/throwError.ts +++ b/src/internal/observable/throwError.ts @@ -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); * @@ -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); * diff --git a/src/internal/observable/timer.ts b/src/internal/observable/timer.ts index 361e7730d9..963f4b3e1a 100644 --- a/src/internal/observable/timer.ts +++ b/src/internal/observable/timer.ts @@ -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); @@ -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. diff --git a/src/internal/observable/zip.ts b/src/internal/observable/zip.ts index 4301089cd4..16aa4bbbbf 100644 --- a/src/internal/observable/zip.ts +++ b/src/internal/observable/zip.ts @@ -28,8 +28,7 @@ export function zip( * 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'); diff --git a/src/internal/operators/audit.ts b/src/internal/operators/audit.ts index e8bdfa000f..785cc1abf7 100644 --- a/src/internal/operators/audit.ts +++ b/src/internal/operators/audit.ts @@ -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))); diff --git a/src/internal/operators/auditTime.ts b/src/internal/operators/auditTime.ts index 7777ddce18..85755c95de 100644 --- a/src/internal/operators/auditTime.ts +++ b/src/internal/operators/auditTime.ts @@ -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)); diff --git a/src/internal/operators/buffer.ts b/src/internal/operators/buffer.ts index e7631aaecb..1a911019c2 100644 --- a/src/internal/operators/buffer.ts +++ b/src/internal/operators/buffer.ts @@ -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); diff --git a/src/internal/operators/bufferCount.ts b/src/internal/operators/bufferCount.ts index ee7bf6844a..553e77bd3d 100644 --- a/src/internal/operators/bufferCount.ts +++ b/src/internal/operators/bufferCount.ts @@ -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)); @@ -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)); diff --git a/src/internal/operators/bufferTime.ts b/src/internal/operators/bufferTime.ts index cab6dd2b21..afc6c1d045 100644 --- a/src/internal/operators/bufferTime.ts +++ b/src/internal/operators/bufferTime.ts @@ -44,8 +44,7 @@ export function bufferTime( * 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)); @@ -55,8 +54,7 @@ export function bufferTime( * 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)); diff --git a/src/internal/operators/bufferToggle.ts b/src/internal/operators/bufferToggle.ts index 61d3613570..41f6a2c804 100644 --- a/src/internal/operators/bufferToggle.ts +++ b/src/internal/operators/bufferToggle.ts @@ -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); diff --git a/src/internal/operators/bufferWhen.ts b/src/internal/operators/bufferWhen.ts index fd8638e09b..ce12509b64 100644 --- a/src/internal/operators/bufferWhen.ts +++ b/src/internal/operators/bufferWhen.ts @@ -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(() => diff --git a/src/internal/operators/catchError.ts b/src/internal/operators/catchError.ts index 7a69d49774..eec51f2a9f 100644 --- a/src/internal/operators/catchError.ts +++ b/src/internal/operators/catchError.ts @@ -31,8 +31,7 @@ export function catchError>( * Continues with a different Observable when there's an error * * ```ts - * import { of } from 'rxjs'; - * import { map, catchError } from 'rxjs/operators'; + * import { of, map, catchError } from 'rxjs'; * * of(1, 2, 3, 4, 5).pipe( * map(n => { @@ -50,8 +49,7 @@ export function catchError>( * Retries the caught source Observable again in case of error, similar to retry() operator * * ```ts - * import { of } from 'rxjs'; - * import { map, catchError, take } from 'rxjs/operators'; + * import { of, map, catchError, take } from 'rxjs'; * * of(1, 2, 3, 4, 5).pipe( * map(n => { @@ -70,8 +68,7 @@ export function catchError>( * Throws a new error when the source Observable throws an error * * ```ts - * import { of } from 'rxjs'; - * import { map, catchError } from 'rxjs/operators'; + * import { of, map, catchError } from 'rxjs'; * * of(1, 2, 3, 4, 5).pipe( * map(n => { diff --git a/src/internal/operators/combineLatestAll.ts b/src/internal/operators/combineLatestAll.ts index 7d06b87bcc..b8ce348dbf 100644 --- a/src/internal/operators/combineLatestAll.ts +++ b/src/internal/operators/combineLatestAll.ts @@ -28,8 +28,7 @@ export function combineLatestAll(project: (...values: Array) => R): Oper * ### Map two click events to a finite interval Observable, then apply `combineLatestAll` * * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { map, combineLatestAll, take } from 'rxjs/operators'; + * import { fromEvent, map, interval, take, combineLatestAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe( diff --git a/src/internal/operators/combineLatestWith.ts b/src/internal/operators/combineLatestWith.ts index 7a6b177dad..6d72438368 100644 --- a/src/internal/operators/combineLatestWith.ts +++ b/src/internal/operators/combineLatestWith.ts @@ -17,8 +17,7 @@ import { combineLatest } from './combineLatest'; * Simple calculation from two inputs. * * ```ts - * import { fromEvent } from 'rxjs'; - * import { map, combineLatestWith } from 'rxjs/operators'; + * import { fromEvent, combineLatestWith, map } from 'rxjs'; * * // Setup: Add two inputs to the page * const input1 = document.createElement('input'); diff --git a/src/internal/operators/concatAll.ts b/src/internal/operators/concatAll.ts index 727b7f1bd3..8c2aab31ff 100644 --- a/src/internal/operators/concatAll.ts +++ b/src/internal/operators/concatAll.ts @@ -27,8 +27,7 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * * For each click event, tick every second from 0 to 3, with no concurrency * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { map, take, concatAll } from 'rxjs/operators'; + * import { fromEvent, map, interval, take, concatAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe( diff --git a/src/internal/operators/concatMap.ts b/src/internal/operators/concatMap.ts index 7dfbac5bcf..f8bbac15d3 100644 --- a/src/internal/operators/concatMap.ts +++ b/src/internal/operators/concatMap.ts @@ -45,8 +45,7 @@ export function concatMap>( * For each click event, tick every second from 0 to 3, with no concurrency * * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { concatMap, take } from 'rxjs/operators'; + * import { fromEvent, concatMap, interval, take } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( diff --git a/src/internal/operators/concatMapTo.ts b/src/internal/operators/concatMapTo.ts index e0142721dc..409f76ffa5 100644 --- a/src/internal/operators/concatMapTo.ts +++ b/src/internal/operators/concatMapTo.ts @@ -42,8 +42,7 @@ export function concatMapTo>( * ## Example * For each click event, tick every second from 0 to 3, with no concurrency * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { concatMapTo, take } from 'rxjs/operators'; + * import { fromEvent, concatMapTo, interval, take } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( diff --git a/src/internal/operators/concatWith.ts b/src/internal/operators/concatWith.ts index 6fd4b8f36f..b836b29e22 100644 --- a/src/internal/operators/concatWith.ts +++ b/src/internal/operators/concatWith.ts @@ -13,8 +13,7 @@ import { concat } from './concat'; * Listen for one mouse click, then listen for all mouse moves. * * ```ts - * import { fromEvent } from 'rxjs'; - * import { concatWith, map, take } from 'rxjs/operators'; + * import { fromEvent, map, take, concatWith } from 'rxjs'; * * const clicks$ = fromEvent(document, 'click'); * const moves$ = fromEvent(document, 'mousemove'); diff --git a/src/internal/operators/connect.ts b/src/internal/operators/connect.ts index 0bc14cb9e2..85221fac9a 100644 --- a/src/internal/operators/connect.ts +++ b/src/internal/operators/connect.ts @@ -48,8 +48,7 @@ const DEFAULT_CONFIG: ConnectConfig = { * Sharing a totally synchronous observable * * ```ts - * import { defer, merge, of } from 'rxjs'; - * import { tap, connect, filter, map } from 'rxjs/operators'; + * import { defer, of, tap, connect, merge, map, filter } from 'rxjs'; * * const source$ = defer(() => { * console.log('subscription started'); diff --git a/src/internal/operators/count.ts b/src/internal/operators/count.ts index 81d037be3f..f297a43df2 100644 --- a/src/internal/operators/count.ts +++ b/src/internal/operators/count.ts @@ -22,8 +22,7 @@ import { reduce } from './reduce'; * * Counts how many seconds have passed before the first click happened * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { count, takeUntil } from 'rxjs/operators'; + * import { interval, fromEvent, takeUntil, count } from 'rxjs'; * * const seconds = interval(1000); * const clicks = fromEvent(document, 'click'); @@ -34,8 +33,7 @@ import { reduce } from './reduce'; * * Counts how many odd numbers are there between 1 and 7 * ```ts - * import { range } from 'rxjs'; - * import { count } from 'rxjs/operators'; + * import { range, count } from 'rxjs'; * * const numbers = range(1, 7); * const result = numbers.pipe(count(i => i % 2 === 1)); diff --git a/src/internal/operators/debounce.ts b/src/internal/operators/debounce.ts index 1724904c87..6f736a0e81 100644 --- a/src/internal/operators/debounce.ts +++ b/src/internal/operators/debounce.ts @@ -35,8 +35,7 @@ import { innerFrom } from '../observable/innerFrom'; * ## Example * Emit the most recent click after a burst of clicks * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { scan, debounce } from 'rxjs/operators'; + * import { fromEvent, scan, debounce, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( diff --git a/src/internal/operators/debounceTime.ts b/src/internal/operators/debounceTime.ts index 875116fe88..f1e3076819 100644 --- a/src/internal/operators/debounceTime.ts +++ b/src/internal/operators/debounceTime.ts @@ -34,8 +34,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * Emit the most recent click after a burst of clicks * ```ts - * import { fromEvent } from 'rxjs'; - * import { debounceTime } from 'rxjs/operators'; + * import { fromEvent, debounceTime } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(debounceTime(1000)); diff --git a/src/internal/operators/defaultIfEmpty.ts b/src/internal/operators/defaultIfEmpty.ts index 53f99b055f..19e22a7646 100644 --- a/src/internal/operators/defaultIfEmpty.ts +++ b/src/internal/operators/defaultIfEmpty.ts @@ -18,8 +18,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * If no clicks happen in 5 seconds, then emit "no clicks" * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { defaultIfEmpty, takeUntil } from 'rxjs/operators'; + * import { fromEvent, takeUntil, interval, defaultIfEmpty } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const clicksBeforeFive = clicks.pipe(takeUntil(interval(5000))); diff --git a/src/internal/operators/delay.ts b/src/internal/operators/delay.ts index 5758c95016..93c8be0da6 100644 --- a/src/internal/operators/delay.ts +++ b/src/internal/operators/delay.ts @@ -22,8 +22,7 @@ import { timer } from '../observable/timer'; * ## Examples * Delay each click by one second * ```ts - * import { fromEvent } from 'rxjs'; - * import { delay } from 'rxjs/operators'; + * import { fromEvent, delay } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const delayedClicks = clicks.pipe(delay(1000)); // each click emitted after 1 second @@ -32,8 +31,7 @@ import { timer } from '../observable/timer'; * * Delay all clicks until a future date happens * ```ts - * import { fromEvent } from 'rxjs'; - * import { delay } from 'rxjs/operators'; + * import { fromEvent, delay } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const date = new Date('March 15, 2050 12:00:00'); // in the future diff --git a/src/internal/operators/delayWhen.ts b/src/internal/operators/delayWhen.ts index 208438fffb..53df4e9441 100644 --- a/src/internal/operators/delayWhen.ts +++ b/src/internal/operators/delayWhen.ts @@ -41,8 +41,7 @@ export function delayWhen(delayDurationSelector: (value: T, index: number) => * ## Example * Delay each click by a random amount of time, between 0 and 5 seconds * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { delayWhen } from 'rxjs/operators'; + * import { fromEvent, delayWhen, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const delayedClicks = clicks.pipe( diff --git a/src/internal/operators/dematerialize.ts b/src/internal/operators/dematerialize.ts index 2c6e8e3d8b..798ddaf9e1 100644 --- a/src/internal/operators/dematerialize.ts +++ b/src/internal/operators/dematerialize.ts @@ -25,8 +25,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Convert an Observable of Notifications to an actual Observable * * ```ts - * import { of } from 'rxjs'; - * import { dematerialize } from 'rxjs/operators'; + * import { of, dematerialize } from 'rxjs'; * * const notifA = { kind: 'N', value: 'A' }; * const notifB = { kind: 'N', value: 'B' }; diff --git a/src/internal/operators/distinct.ts b/src/internal/operators/distinct.ts index b713204fdc..52fa9302f7 100644 --- a/src/internal/operators/distinct.ts +++ b/src/internal/operators/distinct.ts @@ -23,8 +23,7 @@ import { noop } from '../util/noop'; * A simple example with numbers * * ```ts - * import { of } from 'rxjs'; - * import { distinct } from 'rxjs/operators'; + * import { of, distinct } from 'rxjs'; * * of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1) * .pipe( @@ -42,8 +41,7 @@ import { noop } from '../util/noop'; * An example using a keySelector function * * ```ts - * import { of } from 'rxjs'; - * import { distinct } from 'rxjs/operators'; + * import { of, distinct } from 'rxjs'; * * interface Person { * age: number, diff --git a/src/internal/operators/distinctUntilChanged.ts b/src/internal/operators/distinctUntilChanged.ts index 30f87bcc96..9ca2ded444 100644 --- a/src/internal/operators/distinctUntilChanged.ts +++ b/src/internal/operators/distinctUntilChanged.ts @@ -20,8 +20,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * not in comparison to _all other emitted values_. * * ```ts - * import { of } from 'rxjs'; - * import { distinctUntilChanged } from 'rxjs/operators'; + * import { of, distinctUntilChanged } from 'rxjs'; * * of(1, 1, 1, 2, 2, 2, 1, 1, 3, 3).pipe( * distinctUntilChanged() @@ -37,8 +36,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * changed: * * ```ts - * import { of } from 'rxjs'; - * import { distinctUntilChanged } from 'rxjs/operators'; + * import { of, distinctUntilChanged } from 'rxjs'; * * const totallyDifferentBuilds$ = of( * { engineVersion: '1.1.0', transmissionVersion: '1.2.0' }, @@ -70,8 +68,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * the next record temperature: * * ```ts - * import { of } from "rxjs"; - * import { distinctUntilChanged } from "rxjs/operators"; + * import { of, distinctUntilChanged } from 'rxjs'; * * const temps$ = of(30, 31, 20, 34, 33, 29, 35, 20); * @@ -112,6 +109,8 @@ export function distinctUntilChanged(comparator?: (previous: T, current: T) = * the account changed hands... * * ```ts + * import { of, distinctUntilChanged } from 'rxjs'; + * * // A stream of updates to a given account * const accountUpdates$ = of( * { updatedBy: "blesh", data: [] }, diff --git a/src/internal/operators/distinctUntilKeyChanged.ts b/src/internal/operators/distinctUntilKeyChanged.ts index 45112b9219..045707a0c8 100644 --- a/src/internal/operators/distinctUntilKeyChanged.ts +++ b/src/internal/operators/distinctUntilKeyChanged.ts @@ -17,8 +17,7 @@ export function distinctUntilKeyChanged(key: K, compare: ( * ## Examples * An example comparing the name of persons * ```typescript - * import { of } from 'rxjs'; - * import { distinctUntilKeyChanged } from 'rxjs/operators'; + * import { of, distinctUntilKeyChanged } from 'rxjs'; * * interface Person { * age: number, @@ -43,8 +42,7 @@ export function distinctUntilKeyChanged(key: K, compare: ( * * An example comparing the first letters of the name * ```typescript - * import { of } from 'rxjs'; - * import { distinctUntilKeyChanged } from 'rxjs/operators'; + * import { of, distinctUntilKeyChanged } from 'rxjs'; * * interface Person { * age: number, diff --git a/src/internal/operators/elementAt.ts b/src/internal/operators/elementAt.ts index 21454089e0..5a6a66862b 100644 --- a/src/internal/operators/elementAt.ts +++ b/src/internal/operators/elementAt.ts @@ -23,8 +23,7 @@ import { take } from './take'; * ## Example * Emit only the third click event * ```ts - * import { fromEvent } from 'rxjs'; - * import { elementAt } from 'rxjs/operators'; + * import { fromEvent, elementAt } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(elementAt(2)); diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index ed5e0985c1..e3a315f40a 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -31,8 +31,7 @@ export function endWith(...values: A): OperatorFun * stop when a user clicks anywhere on the document. * * ```ts - * import { interval, fromEvent } from 'rxjs'; - * import { map, startWith, takeUntil, endWith } from 'rxjs/operators'; + * import { interval, map, fromEvent, startWith, takeUntil, endWith } from 'rxjs'; * * const ticker$ = interval(5000).pipe( * map(() => 'tick'), diff --git a/src/internal/operators/every.ts b/src/internal/operators/every.ts index c7c52d4bcb..5056c52cdf 100644 --- a/src/internal/operators/every.ts +++ b/src/internal/operators/every.ts @@ -27,8 +27,7 @@ export function every(predicate: (value: T, index: number, source: Observable * ## Example * A simple example emitting true if all elements are less than 5, false otherwise * ```ts - * import { of } from 'rxjs'; - * import { every } from 'rxjs/operators'; + * import { of, every } from 'rxjs'; * * of(1, 2, 3, 4, 5, 6).pipe( * every(x => x < 5), diff --git a/src/internal/operators/exhaustAll.ts b/src/internal/operators/exhaustAll.ts index d5ebd59fa4..5a48a1ec05 100644 --- a/src/internal/operators/exhaustAll.ts +++ b/src/internal/operators/exhaustAll.ts @@ -24,8 +24,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * Run a finite timer for each click, only if there is no currently active timer * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { exhaustAll, map, take } from 'rxjs/operators'; + * import { fromEvent, map, interval, take, exhaustAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe( diff --git a/src/internal/operators/exhaustMap.ts b/src/internal/operators/exhaustMap.ts index b2ea51b6f4..8d4ace559f 100644 --- a/src/internal/operators/exhaustMap.ts +++ b/src/internal/operators/exhaustMap.ts @@ -43,8 +43,7 @@ export function exhaustMap( * ## Example * Run a finite timer for each click, only if there is no currently active timer * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { exhaustMap, take } from 'rxjs/operators'; + * import { fromEvent, exhaustMap, interval, take } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( diff --git a/src/internal/operators/expand.ts b/src/internal/operators/expand.ts index b79f6376e2..6205ed5890 100644 --- a/src/internal/operators/expand.ts +++ b/src/internal/operators/expand.ts @@ -43,8 +43,7 @@ export function expand>( * ## Example * Start emitting the powers of two on every click, at most 10 of them * ```ts - * import { fromEvent, of } from 'rxjs'; - * import { expand, mapTo, delay, take } from 'rxjs/operators'; + * import { fromEvent, mapTo, expand, of, delay, take } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const powersOfTwo = clicks.pipe( diff --git a/src/internal/operators/filter.ts b/src/internal/operators/filter.ts index 97d5e8b62d..7c6f5f2976 100644 --- a/src/internal/operators/filter.ts +++ b/src/internal/operators/filter.ts @@ -27,8 +27,7 @@ export function filter(predicate: (value: T, index: number) => boolean): Mono * ## Example * Emit only click events whose target was a DIV element * ```ts - * import { fromEvent } from 'rxjs'; - * import { filter } from 'rxjs/operators'; + * import { fromEvent, filter } from 'rxjs'; * * const div = document.createElement('div'); * div.style.cssText = `width: 200px;height: 200px;background: #09c;`; diff --git a/src/internal/operators/finalize.ts b/src/internal/operators/finalize.ts index aa4575be35..2844fe9acd 100644 --- a/src/internal/operators/finalize.ts +++ b/src/internal/operators/finalize.ts @@ -10,8 +10,7 @@ import { operate } from '../util/lift'; * Execute callback function when the observable completes * * ```ts - * import { interval } from 'rxjs'; - * import { take, finalize } from 'rxjs/operators'; + * import { interval, take, finalize } from 'rxjs'; * * // emit value in sequence every 1 second * const source = interval(1000); @@ -33,8 +32,7 @@ import { operate } from '../util/lift'; * Execute callback function when the subscriber explicitly unsubscribes * * ```ts - * import { interval, timer, noop } from 'rxjs'; - * import { finalize, tap } from 'rxjs/operators'; + * import { interval, finalize, tap, noop, timer } from 'rxjs'; * * const source = interval(100).pipe( * finalize(() => console.log('[finalize] Called')), diff --git a/src/internal/operators/find.ts b/src/internal/operators/find.ts index 89952ce621..7f46f414dc 100644 --- a/src/internal/operators/find.ts +++ b/src/internal/operators/find.ts @@ -37,8 +37,7 @@ export function find(predicate: (value: T, index: number, source: Observable< * ## Example * Find and emit the first click that happens on a DIV element * ```ts - * import { fromEvent } from 'rxjs'; - * import { find } from 'rxjs/operators'; + * import { fromEvent, find } from 'rxjs'; * * const div = document.createElement('div'); * div.style.cssText = 'width: 200px; height: 200px; background: #09c;'; diff --git a/src/internal/operators/findIndex.ts b/src/internal/operators/findIndex.ts index 6016493f90..593078865b 100644 --- a/src/internal/operators/findIndex.ts +++ b/src/internal/operators/findIndex.ts @@ -31,8 +31,7 @@ export function findIndex(predicate: (value: T, index: number, source: Observ * ## Example * Emit the index of first click that happens on a DIV element * ```ts - * import { fromEvent } from 'rxjs'; - * import { findIndex } from 'rxjs/operators'; + * import { fromEvent, findIndex } from 'rxjs'; * * const div = document.createElement('div'); * div.style.cssText = 'width: 200px; height: 200px; background: #09c;'; diff --git a/src/internal/operators/first.ts b/src/internal/operators/first.ts index 4339bd8c34..6cb4cb7312 100644 --- a/src/internal/operators/first.ts +++ b/src/internal/operators/first.ts @@ -40,8 +40,7 @@ export function first( * ## Examples * Emit only the first click that happens on the DOM * ```ts - * import { fromEvent } from 'rxjs'; - * import { first } from 'rxjs/operators'; + * import { fromEvent, first } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(first()); @@ -50,8 +49,7 @@ export function first( * * Emits the first click that happens on a DIV * ```ts - * import { fromEvent } from 'rxjs'; - * import { first } from 'rxjs/operators'; + * import { fromEvent, first } from 'rxjs'; * * const div = document.createElement('div'); * div.style.cssText = 'width: 200px; height: 200px; background: #09c;'; diff --git a/src/internal/operators/groupBy.ts b/src/internal/operators/groupBy.ts index c79df357b6..29ecb25194 100644 --- a/src/internal/operators/groupBy.ts +++ b/src/internal/operators/groupBy.ts @@ -71,8 +71,7 @@ export function groupBy( * ### Group objects by id and return as array * * ```ts - * import { of } from 'rxjs'; - * import { mergeMap, groupBy, reduce } from 'rxjs/operators'; + * import { of, groupBy, mergeMap, reduce } from 'rxjs'; * * of( * {id: 1, name: 'JavaScript'}, @@ -99,8 +98,7 @@ export function groupBy( * ### Pivot data on the id field * * ```ts - * import { of } from 'rxjs'; - * import { groupBy, map, mergeMap, reduce } from 'rxjs/operators'; + * import { of, groupBy, mergeMap, reduce, map } from 'rxjs'; * * of( * { id: 1, name: 'JavaScript' }, diff --git a/src/internal/operators/ignoreElements.ts b/src/internal/operators/ignoreElements.ts index 8df5dd0ec6..f5a50d6ada 100644 --- a/src/internal/operators/ignoreElements.ts +++ b/src/internal/operators/ignoreElements.ts @@ -17,8 +17,7 @@ import { noop } from '../util/noop'; * * ## Examples * ```ts - * import { of } from 'rxjs'; - * import { ignoreElements } from 'rxjs/operators'; + * import { of, ignoreElements } from 'rxjs'; * * of('you', 'talking', 'to', 'me').pipe( * ignoreElements(), diff --git a/src/internal/operators/isEmpty.ts b/src/internal/operators/isEmpty.ts index 4c7996b906..ea1cad56f7 100644 --- a/src/internal/operators/isEmpty.ts +++ b/src/internal/operators/isEmpty.ts @@ -25,8 +25,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Emit `false` for a non-empty Observable. * * ```ts - * import { Subject } from 'rxjs'; - * import { isEmpty } from 'rxjs/operators'; + * import { Subject, isEmpty } from 'rxjs'; * * const source = new Subject(); * const result = source.pipe(isEmpty()); @@ -49,8 +48,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Emit `true` for an empty Observable. * * ```ts - * import { EMPTY } from 'rxjs'; - * import { isEmpty } from 'rxjs/operators'; + * import { EMPTY, isEmpty } from 'rxjs'; * * const result = EMPTY.pipe(isEmpty()); * result.subscribe(x => console.log(x)); diff --git a/src/internal/operators/last.ts b/src/internal/operators/last.ts index 5117db061a..d014d21408 100644 --- a/src/internal/operators/last.ts +++ b/src/internal/operators/last.ts @@ -34,8 +34,7 @@ export function last( * ## Example * Last alphabet from the sequence. * ```ts - * import { from } from 'rxjs'; - * import { last } from 'rxjs/operators'; + * import { from, last } from 'rxjs'; * * const source = from(['x', 'y', 'z']); * const example = source.pipe(last()); @@ -45,8 +44,7 @@ export function last( * * Default value when the value in the predicate is not matched. * ```ts - * import { from } from 'rxjs'; - * import { last } from 'rxjs/operators'; + * import { from, last } from 'rxjs'; * * const source = from(['x', 'y', 'z']); * const example = source.pipe(last(char => char === 'a','not exist')); diff --git a/src/internal/operators/map.ts b/src/internal/operators/map.ts index 3e4e513558..25fde84926 100644 --- a/src/internal/operators/map.ts +++ b/src/internal/operators/map.ts @@ -23,8 +23,7 @@ export function map(project: (this: A, value: T, index: number) => R, t * ## Example * Map every click to the clientX position of that click * ```ts - * import { fromEvent } from 'rxjs'; - * import { map } from 'rxjs/operators'; + * import { fromEvent, map } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const positions = clicks.pipe(map(ev => ev.clientX)); diff --git a/src/internal/operators/mapTo.ts b/src/internal/operators/mapTo.ts index 4608b00d05..155f510c9f 100644 --- a/src/internal/operators/mapTo.ts +++ b/src/internal/operators/mapTo.ts @@ -21,8 +21,7 @@ export function mapTo(value: R): OperatorFunction; * ## Example * Map every click to the string 'Hi' * ```ts - * import { fromEvent } from 'rxjs'; - * import { mapTo } from 'rxjs/operators'; + * import { fromEvent, mapTo } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const greetings = clicks.pipe(mapTo('Hi')); diff --git a/src/internal/operators/materialize.ts b/src/internal/operators/materialize.ts index 70257b9bfe..570c04d26d 100644 --- a/src/internal/operators/materialize.ts +++ b/src/internal/operators/materialize.ts @@ -30,8 +30,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Convert a faulty Observable to an Observable of Notifications * * ```ts - * import { of } from 'rxjs'; - * import { materialize, map } from 'rxjs/operators'; + * import { of, materialize, map } from 'rxjs'; * * const letters = of('a', 'b', 13, 'd'); * const upperCase = letters.pipe(map(x => x.toUpperCase())); diff --git a/src/internal/operators/max.ts b/src/internal/operators/max.ts index 744ff8ea5e..c8e7417cb3 100644 --- a/src/internal/operators/max.ts +++ b/src/internal/operators/max.ts @@ -11,8 +11,7 @@ import { isFunction } from '../util/isFunction'; * ## Examples * Get the maximal value of a series of numbers * ```ts - * import { of } from 'rxjs'; - * import { max } from 'rxjs/operators'; + * import { of, max } from 'rxjs'; * * of(5, 4, 7, 2, 8).pipe( * max(), @@ -22,8 +21,7 @@ import { isFunction } from '../util/isFunction'; * * Use a comparer function to get the maximal item * ```typescript - * import { of } from 'rxjs'; - * import { max } from 'rxjs/operators'; + * import { of, max } from 'rxjs'; * * interface Person { * age: number, diff --git a/src/internal/operators/mergeAll.ts b/src/internal/operators/mergeAll.ts index c5fb539ff9..06f8212e69 100644 --- a/src/internal/operators/mergeAll.ts +++ b/src/internal/operators/mergeAll.ts @@ -20,8 +20,7 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * ## Examples * Spawn a new interval Observable for each click event, and blend their outputs as one Observable * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { map, mergeAll } from 'rxjs/operators'; + * import { fromEvent, map, interval, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe(map((ev) => interval(1000))); @@ -31,8 +30,7 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * * Count from 0 to 9 every second for each click, but only allow 2 concurrent timers * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { take, map, mergeAll } from 'rxjs/operators'; + * import { fromEvent, map, interval, take, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe( diff --git a/src/internal/operators/mergeMap.ts b/src/internal/operators/mergeMap.ts index b159bda883..71af090c54 100644 --- a/src/internal/operators/mergeMap.ts +++ b/src/internal/operators/mergeMap.ts @@ -41,8 +41,7 @@ export function mergeMap>( * ## Example * Map and flatten each letter to an Observable ticking every 1 second * ```ts - * import { of, interval } from 'rxjs'; - * import { mergeMap, map } from 'rxjs/operators'; + * import { of, mergeMap, interval, map } from 'rxjs'; * * const letters = of('a', 'b', 'c'); * const result = letters.pipe( diff --git a/src/internal/operators/mergeMapTo.ts b/src/internal/operators/mergeMapTo.ts index d22a0c718e..114218f304 100644 --- a/src/internal/operators/mergeMapTo.ts +++ b/src/internal/operators/mergeMapTo.ts @@ -31,8 +31,7 @@ export function mergeMapTo>( * ## Example * For each click event, start an interval Observable ticking every 1 second * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { mergeMapTo } from 'rxjs/operators'; + * import { fromEvent, mergeMapTo, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(mergeMapTo(interval(1000))); diff --git a/src/internal/operators/mergeScan.ts b/src/internal/operators/mergeScan.ts index 1425234c6d..ac738095a5 100644 --- a/src/internal/operators/mergeScan.ts +++ b/src/internal/operators/mergeScan.ts @@ -37,8 +37,7 @@ import { mergeInternals } from './mergeInternals'; * ## Example * Count the number of click events * ```ts - * import { fromEvent, of } from 'rxjs'; - * import { mapTo, mergeScan } from 'rxjs/operators'; + * import { fromEvent, mapTo, mergeScan, of } from 'rxjs'; * * const click$ = fromEvent(document, 'click'); * const one$ = click$.pipe(mapTo(1)); diff --git a/src/internal/operators/mergeWith.ts b/src/internal/operators/mergeWith.ts index 8046e141e2..3a6d68628b 100644 --- a/src/internal/operators/mergeWith.ts +++ b/src/internal/operators/mergeWith.ts @@ -18,8 +18,7 @@ import { merge } from './merge'; * Joining all outputs from multiple user input event streams: * * ```ts - * import { fromEvent } from 'rxjs'; - * import { map, mergeWith } from 'rxjs/operators'; + * import { fromEvent, map, mergeWith } from 'rxjs'; * * const clicks$ = fromEvent(document, 'click').pipe(map(() => 'click')); * const mousemoves$ = fromEvent(document, 'mousemove').pipe(map(() => 'mousemove')); diff --git a/src/internal/operators/min.ts b/src/internal/operators/min.ts index 8a8058f862..4f2778c6c1 100644 --- a/src/internal/operators/min.ts +++ b/src/internal/operators/min.ts @@ -11,8 +11,7 @@ import { isFunction } from '../util/isFunction'; * ## Examples * Get the minimal value of a series of numbers * ```ts - * import { of } from 'rxjs'; - * import { min } from 'rxjs/operators'; + * import { of, min } from 'rxjs'; * * of(5, 4, 7, 2, 8).pipe( * min(), @@ -22,8 +21,7 @@ import { isFunction } from '../util/isFunction'; * * Use a comparer function to get the minimal item * ```typescript - * import { of } from 'rxjs'; - * import { min } from 'rxjs/operators'; + * import { of, min } from 'rxjs'; * * interface Person { * age: number, diff --git a/src/internal/operators/observeOn.ts b/src/internal/operators/observeOn.ts index 8f0b23c038..6701a75464 100644 --- a/src/internal/operators/observeOn.ts +++ b/src/internal/operators/observeOn.ts @@ -35,8 +35,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Ensure values in subscribe are called just before browser repaint. * * ```ts - * import { interval, animationFrameScheduler } from 'rxjs'; - * import { observeOn } from 'rxjs/operators'; + * import { interval, observeOn, animationFrameScheduler } from 'rxjs'; * * const someDiv = document.createElement('div'); * someDiv.style.cssText = 'width: 200px;background: #09c'; diff --git a/src/internal/operators/onErrorResumeNext.ts b/src/internal/operators/onErrorResumeNext.ts index 9fdfcb1348..adb60001ea 100644 --- a/src/internal/operators/onErrorResumeNext.ts +++ b/src/internal/operators/onErrorResumeNext.ts @@ -46,8 +46,7 @@ export function onErrorResumeNext( * ## Example * Subscribe to the next Observable after map fails * ```ts - * import { of } from 'rxjs'; - * import { onErrorResumeNext, map } from 'rxjs/operators'; + * import { of, onErrorResumeNext, map } from 'rxjs'; * * of(1, 2, 3, 0).pipe( * map(x => { diff --git a/src/internal/operators/pairwise.ts b/src/internal/operators/pairwise.ts index b040463563..b64a33ddb8 100644 --- a/src/internal/operators/pairwise.ts +++ b/src/internal/operators/pairwise.ts @@ -20,8 +20,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * On every click (starting from the second), emit the relative distance to the previous click * ```ts - * import { fromEvent } from 'rxjs'; - * import { pairwise, map } from 'rxjs/operators'; + * import { fromEvent, pairwise, map } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const pairs = clicks.pipe(pairwise()); diff --git a/src/internal/operators/pluck.ts b/src/internal/operators/pluck.ts index aa1dc49a40..3a08dba190 100644 --- a/src/internal/operators/pluck.ts +++ b/src/internal/operators/pluck.ts @@ -60,8 +60,7 @@ export function pluck(...properties: string[]): OperatorFunction; * ## Example * Map every click to the tagName of the clicked target element * ```ts - * import { fromEvent } from 'rxjs'; - * import { pluck } from 'rxjs/operators'; + * import { fromEvent, pluck } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const tagNames = clicks.pipe(pluck('target', 'tagName')); diff --git a/src/internal/operators/publish.ts b/src/internal/operators/publish.ts index 7de67d27aa..333b63cfd1 100644 --- a/src/internal/operators/publish.ts +++ b/src/internal/operators/publish.ts @@ -45,8 +45,7 @@ export function publish>(selector: (shared: Ob * Make source$ hot by applying publish operator, then merge each inner observable into a single one * and subscribe. * ```ts - * import { of, zip, interval, merge } from "rxjs"; - * import { map, publish, tap } from "rxjs/operators"; + * import { zip, interval, of, map, publish, merge, tap } from 'rxjs'; * * const source$ = zip(interval(2000), of(1, 2, 3, 4, 5, 6, 7, 8, 9)).pipe( * map(values => values[1]) diff --git a/src/internal/operators/publishLast.ts b/src/internal/operators/publishLast.ts index 7cde7f50d5..fa6d0d3c7e 100644 --- a/src/internal/operators/publishLast.ts +++ b/src/internal/operators/publishLast.ts @@ -18,8 +18,7 @@ import { UnaryFunction } from '../types'; * ## Example * * ```ts - * import { interval } from 'rxjs'; - * import { publishLast, tap, take } from 'rxjs/operators'; + * import { interval, publishLast, tap, take } from 'rxjs'; * * const connectable = * interval(1000) diff --git a/src/internal/operators/raceWith.ts b/src/internal/operators/raceWith.ts index 3953fa55cf..58663ff9ef 100644 --- a/src/internal/operators/raceWith.ts +++ b/src/internal/operators/raceWith.ts @@ -11,8 +11,7 @@ import { identity } from '../util/identity'; * ## Example * * ```ts - * import { interval } from 'rxjs'; - * import { mapTo, raceWith } from 'rxjs/operators'; + * import { interval, mapTo, raceWith } from 'rxjs'; * * const obs1 = interval(1000).pipe(mapTo('fast one')); * const obs2 = interval(3000).pipe(mapTo('medium one')); diff --git a/src/internal/operators/reduce.ts b/src/internal/operators/reduce.ts index 9ff5de8566..441a450eb3 100644 --- a/src/internal/operators/reduce.ts +++ b/src/internal/operators/reduce.ts @@ -32,8 +32,7 @@ export function reduce(accumulator: (acc: A | S, value: V, index: n * ## Example * Count the number of click events that happened in 5 seconds * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { reduce, takeUntil, mapTo } from 'rxjs/operators'; + * import { fromEvent, takeUntil, interval, mapTo, reduce } from 'rxjs'; * * const clicksInFiveSeconds = fromEvent(document, 'click').pipe( * takeUntil(interval(5000)), diff --git a/src/internal/operators/refCount.ts b/src/internal/operators/refCount.ts index 2fab3f55f8..1b4f6baeb4 100644 --- a/src/internal/operators/refCount.ts +++ b/src/internal/operators/refCount.ts @@ -27,8 +27,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * until you call its connect function. * * ```ts - * import { interval } from 'rxjs'; - * import { tap, publish, refCount } from 'rxjs/operators'; + * import { interval, tap, publish, refCount } from 'rxjs'; * * // Turn the interval observable into a ConnectableObservable (hot) * const refCountInterval = interval(400).pipe( diff --git a/src/internal/operators/repeat.ts b/src/internal/operators/repeat.ts index 09da1190e8..e68035d4c7 100644 --- a/src/internal/operators/repeat.ts +++ b/src/internal/operators/repeat.ts @@ -19,8 +19,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * Repeat a message stream * ```ts - * import { of } from 'rxjs'; - * import { repeat } from 'rxjs/operators'; + * import { of, repeat } from 'rxjs'; * * const source = of('Repeat message'); * const example = source.pipe(repeat(3)); @@ -34,8 +33,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * Repeat 3 values, 2 times * ```ts - * import { interval } from 'rxjs'; - * import { repeat, take } from 'rxjs/operators'; + * import { interval, take, repeat } from 'rxjs'; * * const source = interval(1000); * const example = source.pipe(take(3), repeat(2)); diff --git a/src/internal/operators/repeatWhen.ts b/src/internal/operators/repeatWhen.ts index 7253ade1cd..09e1cb253b 100644 --- a/src/internal/operators/repeatWhen.ts +++ b/src/internal/operators/repeatWhen.ts @@ -17,8 +17,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * Repeat a message stream on click * ```ts - * import { of, fromEvent } from 'rxjs'; - * import { repeatWhen } from 'rxjs/operators'; + * import { of, fromEvent, repeatWhen } from 'rxjs'; * * const source = of('Repeat message'); * const documentClick$ = fromEvent(document, 'click'); diff --git a/src/internal/operators/retry.ts b/src/internal/operators/retry.ts index 554528c225..c2fe7b29e4 100644 --- a/src/internal/operators/retry.ts +++ b/src/internal/operators/retry.ts @@ -40,8 +40,7 @@ export interface RetryConfig { * * ## Example * ```ts - * import { interval, of, throwError } from 'rxjs'; - * import { mergeMap, retry } from 'rxjs/operators'; + * import { interval, mergeMap, throwError, of, retry } from 'rxjs'; * * const source = interval(1000); * const example = source.pipe( diff --git a/src/internal/operators/retryWhen.ts b/src/internal/operators/retryWhen.ts index 5d5f15c547..101384ecb0 100644 --- a/src/internal/operators/retryWhen.ts +++ b/src/internal/operators/retryWhen.ts @@ -18,8 +18,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * ## Example * ```ts - * import { timer, interval } from 'rxjs'; - * import { map, tap, retryWhen, delayWhen } from 'rxjs/operators'; + * import { interval, map, retryWhen, tap, delayWhen, timer } from 'rxjs'; * * const source = interval(1000); * const example = source.pipe( diff --git a/src/internal/operators/sample.ts b/src/internal/operators/sample.ts index 7ce877f917..abb472f109 100644 --- a/src/internal/operators/sample.ts +++ b/src/internal/operators/sample.ts @@ -22,8 +22,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * On every click, sample the most recent "seconds" timer * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { sample } from 'rxjs/operators'; + * import { fromEvent, interval, sample } from 'rxjs'; * * const seconds = interval(1000); * const clicks = fromEvent(document, 'click'); diff --git a/src/internal/operators/sampleTime.ts b/src/internal/operators/sampleTime.ts index 0a5dda2830..014939361d 100644 --- a/src/internal/operators/sampleTime.ts +++ b/src/internal/operators/sampleTime.ts @@ -22,8 +22,7 @@ import { interval } from '../observable/interval'; * ## Example * Every second, emit the most recent click at most once * ```ts - * import { fromEvent } from 'rxjs'; - * import { sampleTime } from 'rxjs/operators'; + * import { fromEvent, sampleTime } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(sampleTime(1000)); diff --git a/src/internal/operators/scan.ts b/src/internal/operators/scan.ts index 1242994386..44fa2932f4 100644 --- a/src/internal/operators/scan.ts +++ b/src/internal/operators/scan.ts @@ -35,8 +35,7 @@ export function scan(accumulator: (acc: A | S, value: V, index: number) * first value from the source. * * ```ts - * import { interval, of } from 'rxjs'; - * import { scan, map } from 'rxjs/operators'; + * import { of, scan, map } from 'rxjs'; * * const numbers$ = of(1, 2, 3); * @@ -59,8 +58,7 @@ export function scan(accumulator: (acc: A | S, value: V, index: number) * in job interviews. Now you can show them the Rx version! (Please don't, haha) * * ```ts - * import { interval } from 'rxjs'; - * import { scan, map, startWith } from 'rxjs/operators'; + * import { interval, scan, map, startWith } from 'rxjs'; * * const firstTwoFibs = [0, 1]; * // An endless stream of Fibonnaci numbers. diff --git a/src/internal/operators/sequenceEqual.ts b/src/internal/operators/sequenceEqual.ts index 9d1d7be642..1e43a78a6c 100644 --- a/src/internal/operators/sequenceEqual.ts +++ b/src/internal/operators/sequenceEqual.ts @@ -23,8 +23,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * figure out if the Konami code matches * ```ts - * import { from, fromEvent } from 'rxjs'; - * import { sequenceEqual, bufferCount, mergeMap, map } from 'rxjs/operators'; + * import { from, fromEvent, map, bufferCount, mergeMap, sequenceEqual } from 'rxjs'; * * const codes = from([ * 'ArrowUp', diff --git a/src/internal/operators/share.ts b/src/internal/operators/share.ts index 433649149b..b1acc2a04c 100644 --- a/src/internal/operators/share.ts +++ b/src/internal/operators/share.ts @@ -70,8 +70,7 @@ export function share(options: ShareConfig): MonoTypeOperatorFunction; * ## Example * Generate new multicast Observable from the source Observable value * ```ts - * import { interval } from 'rxjs'; - * import { share, map } from 'rxjs/operators'; + * import { interval, map, share } from 'rxjs'; * * const source = interval(1000) * .pipe( @@ -103,8 +102,7 @@ export function share(options: ShareConfig): MonoTypeOperatorFunction; * * ## Example with notifier factory: Delayed reset * ```ts - * import { interval, timer } from 'rxjs'; - * import { share, take } from 'rxjs/operators'; + * import { interval, take, share, timer } from 'rxjs'; * * const source = interval(1000).pipe(take(3), share({ resetOnRefCountZero: () => timer(1000) })); * diff --git a/src/internal/operators/shareReplay.ts b/src/internal/operators/shareReplay.ts index 49c59e9314..229218eeb2 100644 --- a/src/internal/operators/shareReplay.ts +++ b/src/internal/operators/shareReplay.ts @@ -40,8 +40,7 @@ export function shareReplay(bufferSize?: number, windowTime?: number, schedul * * ## Example * ```ts - * import { interval } from 'rxjs'; - * import { shareReplay, take } from 'rxjs/operators'; + * import { interval, take, shareReplay } from 'rxjs'; * * const obs$ = interval(1000); * const shared$ = obs$.pipe( @@ -55,8 +54,7 @@ export function shareReplay(bufferSize?: number, windowTime?: number, schedul * * ## Example for refCount usage * ```ts - * import { interval, Observable, defer } from 'rxjs'; - * import { shareReplay, take, tap, finalize } from 'rxjs/operators'; + * import { Observable, defer, tap, finalize, interval, shareReplay, take } from 'rxjs'; * * const log = (source: Observable, name: string) => defer(() => { * console.log(`${name}: subscribed`); diff --git a/src/internal/operators/single.ts b/src/internal/operators/single.ts index e4151a6aa1..0537275ddc 100644 --- a/src/internal/operators/single.ts +++ b/src/internal/operators/single.ts @@ -31,8 +31,7 @@ export function single(predicate?: (value: T, index: number, source: Observab * Expect only name beginning with 'B': * * ```ts - * import { of } from 'rxjs'; - * import { single } from 'rxjs/operators'; + * import { of, single } from 'rxjs'; * * const source1 = of( * { name: 'Ben' }, diff --git a/src/internal/operators/skip.ts b/src/internal/operators/skip.ts index 02f8fc0930..1d4e958607 100644 --- a/src/internal/operators/skip.ts +++ b/src/internal/operators/skip.ts @@ -12,8 +12,7 @@ import { filter } from './filter'; * ## Example * Skip the values before the emission * ```ts - * import { interval } from 'rxjs'; - * import { skip } from 'rxjs/operators'; + * import { interval, skip } from 'rxjs'; * * //emit every half second * const source = interval(500); diff --git a/src/internal/operators/skipLast.ts b/src/internal/operators/skipLast.ts index 20e652920d..97d410859e 100644 --- a/src/internal/operators/skipLast.ts +++ b/src/internal/operators/skipLast.ts @@ -25,8 +25,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Skip the last 2 values of an observable with many values * * ```ts - * import { of } from 'rxjs'; - * import { skipLast } from 'rxjs/operators'; + * import { of, skipLast } from 'rxjs'; * * const numbers = of(1, 2, 3, 4, 5); * const skipLastTwo = numbers.pipe(skipLast(2)); diff --git a/src/internal/operators/skipUntil.ts b/src/internal/operators/skipUntil.ts index b17bdb96b8..c220b90fcf 100644 --- a/src/internal/operators/skipUntil.ts +++ b/src/internal/operators/skipUntil.ts @@ -23,8 +23,7 @@ import { noop } from '../util/noop'; * In the following example, all emitted values ​​of the interval observable are skipped until the user clicks anywhere within the page. * * ```ts - * import { interval, fromEvent } from 'rxjs'; - * import { skipUntil } from 'rxjs/operators'; + * import { interval, fromEvent, skipUntil } from 'rxjs'; * * const intervalObservable = interval(1000); * const click = fromEvent(document, 'click'); diff --git a/src/internal/operators/skipWhile.ts b/src/internal/operators/skipWhile.ts index 18367c15cc..02a17d0598 100644 --- a/src/internal/operators/skipWhile.ts +++ b/src/internal/operators/skipWhile.ts @@ -18,8 +18,7 @@ export function skipWhile(predicate: (value: T, index: number) => boolean): M * ## Example * Using Value: Skip some super heroes * ```ts - * import { from } from 'rxjs'; - * import { skipWhile } from 'rxjs/operators'; + * import { from, skipWhile } from 'rxjs'; * * const source = from(['Green Arrow', 'SuperMan', 'Flash', 'SuperGirl', 'Black Canary']) * // Skip the heroes until SuperGirl @@ -29,8 +28,7 @@ export function skipWhile(predicate: (value: T, index: number) => boolean): M * ``` * Using Index: Skip value from the array until index 5 * ```ts - * import { from } from 'rxjs'; - * import { skipWhile } from 'rxjs/operators'; + * import { from, skipWhile } from 'rxjs'; * * const source = from([1, 2, 3, 4, 5, 6, 7, 9, 10]); * const example = source.pipe(skipWhile((_, i) => i !== 5)); diff --git a/src/internal/operators/startWith.ts b/src/internal/operators/startWith.ts index b639a16f7f..09ce423b8a 100644 --- a/src/internal/operators/startWith.ts +++ b/src/internal/operators/startWith.ts @@ -34,8 +34,7 @@ export function startWith(...values: A): * Emit a value when a timer starts. * * ```ts - * import { timer } from 'rxjs'; - * import { startWith, map } from 'rxjs/operators'; + * import { timer, map, startWith } from 'rxjs'; * * timer(1000) * .pipe( diff --git a/src/internal/operators/subscribeOn.ts b/src/internal/operators/subscribeOn.ts index 0e90593221..8f50fd3bd7 100644 --- a/src/internal/operators/subscribeOn.ts +++ b/src/internal/operators/subscribeOn.ts @@ -36,8 +36,7 @@ import { operate } from '../util/lift'; * If we instead use the `subscribeOn` operator declaring that we want to use the {@link asyncScheduler} for values emited by Observable `a`: * * ```ts - * import { of, merge, asyncScheduler } from 'rxjs'; - * import { subscribeOn } from 'rxjs/operators'; + * import { of, subscribeOn, asyncScheduler, merge } from 'rxjs'; * * const a = of(1, 2, 3).pipe(subscribeOn(asyncScheduler)); * const b = of(4, 5, 6); diff --git a/src/internal/operators/switchAll.ts b/src/internal/operators/switchAll.ts index 9e854dda6a..1a5efe0cac 100644 --- a/src/internal/operators/switchAll.ts +++ b/src/internal/operators/switchAll.ts @@ -23,8 +23,7 @@ import { identity } from '../util/identity'; * click, cancel the previous interval and subscribe to the new one. * * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { switchAll, map, tap } from 'rxjs/operators'; + * import { fromEvent, tap, map, interval, switchAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click').pipe(tap(() => console.log('click'))); * const source = clicks.pipe(map((ev) => interval(1000))); diff --git a/src/internal/operators/switchMap.ts b/src/internal/operators/switchMap.ts index 3c8cd1fa3f..3993aec1b5 100644 --- a/src/internal/operators/switchMap.ts +++ b/src/internal/operators/switchMap.ts @@ -41,8 +41,7 @@ export function switchMap>( * ## Example * Generate new Observable according to source Observable values * ```typescript - * import { of } from 'rxjs'; - * import { switchMap } from 'rxjs/operators'; + * import { of, switchMap } from 'rxjs'; * * const switched = of(1, 2, 3).pipe(switchMap((x: number) => of(x, x ** 2, x ** 3))); * switched.subscribe(x => console.log(x)); @@ -58,8 +57,7 @@ export function switchMap>( * * Restart an interval Observable on every click event * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { switchMap } from 'rxjs/operators'; + * import { fromEvent, switchMap, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(switchMap((ev) => interval(1000))); diff --git a/src/internal/operators/switchMapTo.ts b/src/internal/operators/switchMapTo.ts index 5025d4ce2b..e4bf9a50b1 100644 --- a/src/internal/operators/switchMapTo.ts +++ b/src/internal/operators/switchMapTo.ts @@ -34,8 +34,7 @@ export function switchMapTo>( * ## Example * Rerun an interval Observable on every click event * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { switchMapTo } from 'rxjs/operators'; + * import { fromEvent, switchMapTo, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(switchMapTo(interval(1000))); diff --git a/src/internal/operators/take.ts b/src/internal/operators/take.ts index e8bc9ba931..9464add731 100644 --- a/src/internal/operators/take.ts +++ b/src/internal/operators/take.ts @@ -19,8 +19,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * Take the first 5 seconds of an infinite 1-second interval Observable * ```ts - * import { interval } from 'rxjs'; - * import { take } from 'rxjs/operators'; + * import { interval, take } from 'rxjs'; * * const intervalCount = interval(1000); * const takeFive = intervalCount.pipe(take(5)); diff --git a/src/internal/operators/takeLast.ts b/src/internal/operators/takeLast.ts index 3e3697ce60..c10828db13 100644 --- a/src/internal/operators/takeLast.ts +++ b/src/internal/operators/takeLast.ts @@ -25,8 +25,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Take the last 3 values of an Observable with many values * * ```ts - * import { range } from 'rxjs'; - * import { takeLast } from 'rxjs/operators'; + * import { range, takeLast } from 'rxjs'; * * const many = range(1, 100); * const lastThree = many.pipe(takeLast(3)); diff --git a/src/internal/operators/takeUntil.ts b/src/internal/operators/takeUntil.ts index 3c594a0420..5a0984fce7 100644 --- a/src/internal/operators/takeUntil.ts +++ b/src/internal/operators/takeUntil.ts @@ -22,8 +22,7 @@ import { noop } from '../util/noop'; * ## Example * Tick every second until the first click happens * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { takeUntil } from 'rxjs/operators'; + * import { interval, fromEvent, takeUntil } from 'rxjs'; * * const source = interval(1000); * const clicks = fromEvent(document, 'click'); diff --git a/src/internal/operators/takeWhile.ts b/src/internal/operators/takeWhile.ts index 1ae3f0e8c0..8099c1a369 100644 --- a/src/internal/operators/takeWhile.ts +++ b/src/internal/operators/takeWhile.ts @@ -32,8 +32,7 @@ export function takeWhile(predicate: (value: T, index: number) => boolean, in * ## Example * Emit click events only while the clientX property is greater than 200 * ```ts - * import { fromEvent } from 'rxjs'; - * import { takeWhile } from 'rxjs/operators'; + * import { fromEvent, takeWhile } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(takeWhile(ev => ev.clientX > 200)); diff --git a/src/internal/operators/tap.ts b/src/internal/operators/tap.ts index 364d4ca3eb..67a7cc859d 100644 --- a/src/internal/operators/tap.ts +++ b/src/internal/operators/tap.ts @@ -49,8 +49,7 @@ export function tap( * was, so we have added a `tap(console.log)`. * * ```ts - * import { of } from 'rxjs'; - * import { tap, map } from 'rxjs/operators'; + * import { of, tap, map } from 'rxjs'; * * of(Math.random()).pipe( * tap(console.log), @@ -64,8 +63,7 @@ export function tap( * using `tap`. * * ```ts - * import { of } from 'rxjs'; - * import { tap } from 'rxjs/operators'; + * import { of, tap } from 'rxjs'; * * const source = of(1, 2, 3, 4, 5) * @@ -86,9 +84,7 @@ export function tap( * we have added a `tap` with the side-effect of logging to console. * * ```ts - * import { of, interval } from 'rxjs'; - * import { tap, map, concatMap, take } from 'rxjs/operators'; - * + * import { of, concatMap, interval, take, map, tap } from 'rxjs'; * * of(1, 2, 3).pipe( * concatMap(n => interval(1000).pipe( diff --git a/src/internal/operators/throttle.ts b/src/internal/operators/throttle.ts index 454d67b6fc..0d65b2e6cd 100644 --- a/src/internal/operators/throttle.ts +++ b/src/internal/operators/throttle.ts @@ -37,8 +37,7 @@ export const defaultThrottleConfig: ThrottleConfig = { * ## Example * Emit clicks at a rate of at most one click per second * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { throttle } from 'rxjs/operators'; + * import { fromEvent, throttle, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(throttle(ev => interval(1000))); diff --git a/src/internal/operators/throttleTime.ts b/src/internal/operators/throttleTime.ts index 8dc17e6f9f..cb27cf5278 100644 --- a/src/internal/operators/throttleTime.ts +++ b/src/internal/operators/throttleTime.ts @@ -27,8 +27,7 @@ import { timer } from '../observable/timer'; * * Emit clicks at a rate of at most one click per second * ```ts - * import { fromEvent } from 'rxjs'; - * import { throttleTime } from 'rxjs/operators'; + * import { fromEvent, throttleTime } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(throttleTime(1000)); @@ -42,8 +41,7 @@ import { timer } from '../observable/timer'; * click. It makes use of the `trailing` parameter of the throttle configuration. * * ```ts - * import { fromEvent, asyncScheduler } from 'rxjs'; - * import { throttleTime, withLatestFrom } from 'rxjs/operators'; + * import { fromEvent, throttleTime, asyncScheduler } from 'rxjs'; * * // defaultThottleConfig = { leading: true, trailing: false } * const throttleConfig = { diff --git a/src/internal/operators/throwIfEmpty.ts b/src/internal/operators/throwIfEmpty.ts index b7ab366598..1c383be79e 100644 --- a/src/internal/operators/throwIfEmpty.ts +++ b/src/internal/operators/throwIfEmpty.ts @@ -12,8 +12,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * ## Example * ```ts - * import { fromEvent, timer } from 'rxjs'; - * import { throwIfEmpty, takeUntil } from 'rxjs/operators'; + * import { fromEvent, takeUntil, timer, throwIfEmpty } from 'rxjs'; * * const click$ = fromEvent(document, 'click'); * diff --git a/src/internal/operators/timeInterval.ts b/src/internal/operators/timeInterval.ts index 8fa26950b6..96d904e3d4 100644 --- a/src/internal/operators/timeInterval.ts +++ b/src/internal/operators/timeInterval.ts @@ -23,8 +23,7 @@ import { map } from './map'; * Emit interval between current value with the last value * * ```ts - * import { interval } from "rxjs"; - * import { timeInterval, timeout } from "rxjs/operators"; + * import { interval, timeInterval } from 'rxjs'; * * const seconds = interval(1000); * diff --git a/src/internal/operators/timeout.ts b/src/internal/operators/timeout.ts index d3d8fdcdf4..a7309f3c29 100644 --- a/src/internal/operators/timeout.ts +++ b/src/internal/operators/timeout.ts @@ -121,8 +121,7 @@ export const TimeoutError: TimeoutErrorCtor = createErrorClass( * Emit a custom error if there is too much time between values * * ```ts - * import { interval, throwError } from 'rxjs'; - * import { timeout } from 'rxjs/operators'; + * import { interval, timeout, throwError } from 'rxjs'; * * class CustomTimeoutError extends Error { * constructor() { @@ -149,8 +148,7 @@ export const TimeoutError: TimeoutErrorCtor = createErrorClass( * Switch to a faster observable if your source is slow. * * ```ts - * import { interval, throwError } from 'rxjs'; - * import { timeout } from 'rxjs/operators'; + * import { interval, timeout } from 'rxjs'; * * const slow$ = interval(900); * const fast$ = interval(500); @@ -206,8 +204,7 @@ export function timeout, M = unknown>( * Emit a {@link TimeoutError} if the first value, and _only_ the first value, does not arrive within 5 seconds * * ```ts - * import { interval } from 'rxjs'; - * import { timeout } from 'rxjs/operators'; + * import { interval, timeout } from 'rxjs'; * * // A random interval that lasts between 0 and 10 seconds per tick * const source$ = interval(Math.round(Math.random() * 10000)); @@ -224,8 +221,7 @@ export function timeout, M = unknown>( * and subscription. * * ```ts - * import { timer } from 'rxjs'; - * import { timeout, expand } from 'rxjs/operators'; + * import { timer, timeout, expand } from 'rxjs'; * * const getRandomTime = () => Math.round(Math.random() * 10000); * @@ -246,8 +242,7 @@ export function timeout, M = unknown>( * 5 seconds between any two values after the first. * * ```ts - * import { timer } from 'rxjs'; - * import { timeout, expand } from 'rxjs/operators'; + * import { timer, timeout, expand } from 'rxjs'; * * const getRandomTime = () => Math.round(Math.random() * 10000); * diff --git a/src/internal/operators/timeoutWith.ts b/src/internal/operators/timeoutWith.ts index 0870d8013a..d3ded16d08 100644 --- a/src/internal/operators/timeoutWith.ts +++ b/src/internal/operators/timeoutWith.ts @@ -37,8 +37,7 @@ export function timeoutWith(dueBy: Date, switchTo: ObservableInput, sch * Fallback to a faster observable * * ```ts - * import { interval } from 'rxjs'; - * import { timeoutWith } from 'rxjs/operators'; + * import { interval, timeoutWith } from 'rxjs'; * * const slow$ = interval(1000); * const faster$ = interval(500); @@ -54,8 +53,7 @@ export function timeoutWith(dueBy: Date, switchTo: ObservableInput, sch * Emit your own custom timeout error * * ```ts - * import { interval, throwError } from 'rxjs'; - * import { timeoutWith } from 'rxjs/operators'; + * import { interval, timeoutWith, throwError } from 'rxjs'; * * class CustomTimeoutError extends Error { * constructor() { diff --git a/src/internal/operators/timestamp.ts b/src/internal/operators/timestamp.ts index efecad7fb2..5a8a47538f 100644 --- a/src/internal/operators/timestamp.ts +++ b/src/internal/operators/timestamp.ts @@ -18,8 +18,7 @@ import { map } from './map'; * In this example there is a timestamp attached to the documents click event. * * ```ts - * import { fromEvent } from 'rxjs'; - * import { timestamp } from 'rxjs/operators'; + * import { fromEvent, timestamp } from 'rxjs'; * * const clickWithTimestamp = fromEvent(document, 'click').pipe( * timestamp() diff --git a/src/internal/operators/toArray.ts b/src/internal/operators/toArray.ts index bab880281f..36623b55d2 100644 --- a/src/internal/operators/toArray.ts +++ b/src/internal/operators/toArray.ts @@ -17,8 +17,7 @@ const arrReducer = (arr: any[], value: any) => (arr.push(value), arr); * * ## Example * ```ts - * import { interval } from 'rxjs'; - * import { toArray, take } from 'rxjs/operators'; + * import { interval, take, toArray } from 'rxjs'; * * const source = interval(1000); * const example = source.pipe( diff --git a/src/internal/operators/window.ts b/src/internal/operators/window.ts index 3be79a09cf..0d047f61dc 100644 --- a/src/internal/operators/window.ts +++ b/src/internal/operators/window.ts @@ -23,8 +23,7 @@ import { noop } from '../util/noop'; * ## Example * In every window of 1 second each, emit at most 2 click events * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { window, mergeAll, map, take } from 'rxjs/operators'; + * import { fromEvent, interval, window, map, take, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const sec = interval(1000); diff --git a/src/internal/operators/windowCount.ts b/src/internal/operators/windowCount.ts index d01e09335e..778ec43cb9 100644 --- a/src/internal/operators/windowCount.ts +++ b/src/internal/operators/windowCount.ts @@ -25,8 +25,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Examples * Ignore every 3rd click event, starting from the first one * ```ts - * import { fromEvent } from 'rxjs'; - * import { windowCount, map, mergeAll, skip } from 'rxjs/operators'; + * import { fromEvent, windowCount, map, skip, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( @@ -39,8 +38,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * Ignore every 3rd click event, starting from the third one * ```ts - * import { fromEvent } from 'rxjs'; - * import { windowCount, mergeAll } from 'rxjs/operators'; + * import { fromEvent, windowCount, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( diff --git a/src/internal/operators/windowTime.ts b/src/internal/operators/windowTime.ts index 4301e616ad..24ded37d0c 100644 --- a/src/internal/operators/windowTime.ts +++ b/src/internal/operators/windowTime.ts @@ -46,8 +46,7 @@ export function windowTime( * ## Examples * In every window of 1 second each, emit at most 2 click events * ```ts - * import { fromEvent } from 'rxjs'; - * import { windowTime, map, mergeAll, take } from 'rxjs/operators'; + * import { fromEvent, windowTime, map, take, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( @@ -60,8 +59,7 @@ export function windowTime( * * Every 5 seconds start a window 1 second long, and emit at most 2 click events per window * ```ts - * import { fromEvent } from 'rxjs'; - * import { windowTime, map, mergeAll, take } from 'rxjs/operators'; + * import { fromEvent, windowTime, map, take, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( @@ -74,8 +72,7 @@ export function windowTime( * * Same as example above but with maxWindowCount instead of take * ```ts - * import { fromEvent } from 'rxjs'; - * import { windowTime, mergeAll } from 'rxjs/operators'; + * import { fromEvent, windowTime, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( diff --git a/src/internal/operators/windowToggle.ts b/src/internal/operators/windowToggle.ts index ce1c3958b8..05f2f30984 100644 --- a/src/internal/operators/windowToggle.ts +++ b/src/internal/operators/windowToggle.ts @@ -27,8 +27,7 @@ import { arrRemove } from '../util/arrRemove'; * ## Example * Every other second, emit the click events from the next 500ms * ```ts - * import { fromEvent, interval, EMPTY } from 'rxjs'; - * import { windowToggle, mergeAll } from 'rxjs/operators'; + * import { fromEvent, interval, windowToggle, EMPTY, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const openings = interval(1000); diff --git a/src/internal/operators/windowWhen.ts b/src/internal/operators/windowWhen.ts index c8ae1556de..3cf8ae35ef 100644 --- a/src/internal/operators/windowWhen.ts +++ b/src/internal/operators/windowWhen.ts @@ -25,8 +25,7 @@ import { innerFrom } from '../observable/innerFrom'; * ## Example * Emit only the first two clicks events in every window of [1-5] random seconds * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { windowWhen, map, mergeAll, take } from 'rxjs/operators'; + * import { fromEvent, windowWhen, interval, map, take, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( diff --git a/src/internal/operators/withLatestFrom.ts b/src/internal/operators/withLatestFrom.ts index 9e4bc97a17..97acab7c2b 100644 --- a/src/internal/operators/withLatestFrom.ts +++ b/src/internal/operators/withLatestFrom.ts @@ -32,8 +32,7 @@ export function withLatestFrom( * ## Example * On every click event, emit an array with the latest timer event plus the click event * ```ts - * import { fromEvent, interval } from 'rxjs'; - * import { withLatestFrom } from 'rxjs/operators'; + * import { fromEvent, interval, withLatestFrom } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const timer = interval(1000); From 130d29603ec58893f7d875fe2d0ab95c479c875a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Mon, 6 Dec 2021 15:28:54 +0100 Subject: [PATCH 02/11] docs(README.md): update operator imports in examples --- README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 24de33ab0b..f15e29c1ae 100644 --- a/README.md +++ b/README.md @@ -36,15 +36,29 @@ By contributing or commenting on issues in this repository, whether you've read ### ES6 via npm -```sh +```shell npm install rxjs ``` -It's recommended to pull in the Observable creation methods you need directly from `'rxjs'` as shown below with `range`. And you can pull in any operator you need from one spot, under `'rxjs/operators'`. +It's recommended to pull in the Observable creation methods you need directly from `'rxjs'` as shown below with `range`. +If you're using RxJS version 7.2 or above, you can pull in any operator you need from the same spot, `'rxjs'`. ```ts -import { range } from "rxjs"; -import { map, filter } from "rxjs/operators"; +import { range, filter, map } from 'rxjs'; + +range(1, 200) + .pipe( + filter(x => x % 2 === 1), + map(x => x + x) + ) + .subscribe(x => console.log(x)); +``` + +If you're using RxJS version below 7.2, you can pull in any operator you need from one spot, under `'rxjs/operators'`. + +```ts +import { range } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; range(1, 200) .pipe( @@ -64,7 +78,7 @@ The global namespace for rxjs is `rxjs`: ```js const { range } = rxjs; -const { map, filter } = rxjs.operators; +const { filter, map } = rxjs.operators; range(1, 200) .pipe( From 27c19b5eb8eb6605ff1188820b2728c28eb56c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Mon, 6 Dec 2021 15:34:25 +0100 Subject: [PATCH 03/11] docs: use shorthand version for TypeScript at code markup start Change from 'typescript' to 'ts' at the beginning of markup code examples, as 'ts' is used in almost every other file. --- src/internal/operators/distinctUntilKeyChanged.ts | 4 ++-- src/internal/operators/max.ts | 2 +- src/internal/operators/min.ts | 2 +- src/internal/operators/switchMap.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/internal/operators/distinctUntilKeyChanged.ts b/src/internal/operators/distinctUntilKeyChanged.ts index 045707a0c8..85c22322c5 100644 --- a/src/internal/operators/distinctUntilKeyChanged.ts +++ b/src/internal/operators/distinctUntilKeyChanged.ts @@ -16,7 +16,7 @@ export function distinctUntilKeyChanged(key: K, compare: ( * * ## Examples * An example comparing the name of persons - * ```typescript + * ```ts * import { of, distinctUntilKeyChanged } from 'rxjs'; * * interface Person { @@ -41,7 +41,7 @@ export function distinctUntilKeyChanged(key: K, compare: ( * ``` * * An example comparing the first letters of the name - * ```typescript + * ```ts * import { of, distinctUntilKeyChanged } from 'rxjs'; * * interface Person { diff --git a/src/internal/operators/max.ts b/src/internal/operators/max.ts index c8e7417cb3..fde2205984 100644 --- a/src/internal/operators/max.ts +++ b/src/internal/operators/max.ts @@ -20,7 +20,7 @@ import { isFunction } from '../util/isFunction'; * ``` * * Use a comparer function to get the maximal item - * ```typescript + * ```ts * import { of, max } from 'rxjs'; * * interface Person { diff --git a/src/internal/operators/min.ts b/src/internal/operators/min.ts index 4f2778c6c1..4808f7a116 100644 --- a/src/internal/operators/min.ts +++ b/src/internal/operators/min.ts @@ -20,7 +20,7 @@ import { isFunction } from '../util/isFunction'; * ``` * * Use a comparer function to get the minimal item - * ```typescript + * ```ts * import { of, min } from 'rxjs'; * * interface Person { diff --git a/src/internal/operators/switchMap.ts b/src/internal/operators/switchMap.ts index 3993aec1b5..1b7efc8c5c 100644 --- a/src/internal/operators/switchMap.ts +++ b/src/internal/operators/switchMap.ts @@ -40,7 +40,7 @@ export function switchMap>( * * ## Example * Generate new Observable according to source Observable values - * ```typescript + * ```ts * import { of, switchMap } from 'rxjs'; * * const switched = of(1, 2, 3).pipe(switchMap((x: number) => of(x, x ** 2, x ** 3))); From 99704ee95438c0c30e88771d29aee830e35907fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Mon, 6 Dec 2021 15:35:52 +0100 Subject: [PATCH 04/11] refactor: use 'asyncScheduler' instead of 'async' where possible --- src/internal/operators/auditTime.ts | 4 ++-- src/internal/operators/timeInterval.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internal/operators/auditTime.ts b/src/internal/operators/auditTime.ts index 85755c95de..f11aefcc7c 100644 --- a/src/internal/operators/auditTime.ts +++ b/src/internal/operators/auditTime.ts @@ -1,4 +1,4 @@ -import { async } from '../scheduler/async'; +import { asyncScheduler } from '../scheduler/async'; import { audit } from './audit'; import { timer } from '../observable/timer'; import { MonoTypeOperatorFunction, SchedulerLike } from '../types'; @@ -49,6 +49,6 @@ import { MonoTypeOperatorFunction, SchedulerLike } from '../types'; * @return A function that returns an Observable that performs rate-limiting of * emissions from the source Observable. */ -export function auditTime(duration: number, scheduler: SchedulerLike = async): MonoTypeOperatorFunction { +export function auditTime(duration: number, scheduler: SchedulerLike = asyncScheduler): MonoTypeOperatorFunction { return audit(() => timer(duration, scheduler)); } diff --git a/src/internal/operators/timeInterval.ts b/src/internal/operators/timeInterval.ts index 96d904e3d4..7823128633 100644 --- a/src/internal/operators/timeInterval.ts +++ b/src/internal/operators/timeInterval.ts @@ -1,5 +1,5 @@ import { Observable } from '../Observable'; -import { async } from '../scheduler/async'; +import { asyncScheduler } from '../scheduler/async'; import { SchedulerLike, OperatorFunction } from '../types'; import { scan } from './scan'; import { defer } from '../observable/defer'; @@ -52,7 +52,7 @@ import { map } from './map'; * @return A function that returns an Observable that emits information about * value and interval. */ -export function timeInterval(scheduler: SchedulerLike = async): OperatorFunction> { +export function timeInterval(scheduler: SchedulerLike = asyncScheduler): OperatorFunction> { return (source: Observable) => defer(() => { return source.pipe( From 82c27fa0eda128f49e5000590cf16229b6fbafbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Mon, 6 Dec 2021 19:35:11 +0100 Subject: [PATCH 05/11] docs: fix headings --- src/internal/Observable.ts | 17 ++++++++++------ src/internal/ajax/ajax.ts | 19 ++++++++++++------ src/internal/firstValueFrom.ts | 4 ++-- src/internal/lastValueFrom.ts | 4 ++-- src/internal/observable/combineLatest.ts | 14 +++++++++---- src/internal/observable/concat.ts | 10 +++++++--- src/internal/observable/defer.ts | 4 +++- .../observable/dom/WebSocketSubject.ts | 12 ++++++----- .../observable/dom/animationFrames.ts | 4 +--- src/internal/observable/dom/fetch.ts | 4 +++- src/internal/observable/dom/webSocket.ts | 12 +++++++---- src/internal/observable/empty.ts | 6 +++--- src/internal/observable/forkJoin.ts | 6 ++++-- src/internal/observable/from.ts | 10 +++------- src/internal/observable/fromEvent.ts | 7 +++++-- src/internal/observable/fromEventPattern.ts | 11 +++++----- src/internal/observable/generate.ts | 20 +++++++++---------- src/internal/observable/iif.ts | 4 ++-- src/internal/observable/interval.ts | 5 +++-- src/internal/observable/merge.ts | 7 +++++-- src/internal/observable/never.ts | 4 +++- src/internal/observable/onErrorResumeNext.ts | 4 +++- src/internal/observable/pairs.ts | 4 +++- src/internal/observable/partition.ts | 2 ++ src/internal/observable/race.ts | 3 ++- src/internal/observable/range.ts | 2 +- src/internal/observable/throwError.ts | 8 ++++---- src/internal/observable/timer.ts | 4 ++-- src/internal/operators/audit.ts | 1 + src/internal/operators/auditTime.ts | 1 + src/internal/operators/catchError.ts | 7 ++++--- src/internal/operators/combineLatestAll.ts | 6 ++---- src/internal/operators/combineLatestWith.ts | 8 ++++---- src/internal/operators/concatAll.ts | 1 + src/internal/operators/concatMap.ts | 1 + src/internal/operators/concatMapTo.ts | 2 ++ src/internal/operators/connect.ts | 2 +- src/internal/operators/count.ts | 2 ++ src/internal/operators/debounce.ts | 2 ++ src/internal/operators/debounceTime.ts | 2 ++ src/internal/operators/defaultIfEmpty.ts | 4 +++- src/internal/operators/delay.ts | 3 +++ src/internal/operators/delayWhen.ts | 2 ++ src/internal/operators/distinct.ts | 2 +- .../operators/distinctUntilChanged.ts | 6 +----- .../operators/distinctUntilKeyChanged.ts | 3 +++ src/internal/operators/elementAt.ts | 2 ++ src/internal/operators/every.ts | 2 ++ src/internal/operators/exhaustAll.ts | 2 ++ src/internal/operators/exhaustMap.ts | 2 ++ src/internal/operators/expand.ts | 2 ++ src/internal/operators/filter.ts | 2 ++ src/internal/operators/finalize.ts | 1 + src/internal/operators/find.ts | 2 ++ src/internal/operators/findIndex.ts | 2 ++ src/internal/operators/first.ts | 3 +++ src/internal/operators/groupBy.ts | 4 ++-- src/internal/operators/ignoreElements.ts | 5 ++++- src/internal/operators/isEmpty.ts | 4 ++-- src/internal/operators/last.ts | 9 ++++++--- src/internal/operators/map.ts | 4 +++- src/internal/operators/mapTo.ts | 4 +++- src/internal/operators/max.ts | 3 +++ src/internal/operators/mergeAll.ts | 3 +++ src/internal/operators/mergeMap.ts | 2 ++ src/internal/operators/mergeMapTo.ts | 2 ++ src/internal/operators/mergeScan.ts | 2 ++ src/internal/operators/mergeWith.ts | 5 ++--- src/internal/operators/min.ts | 3 +++ src/internal/operators/observeOn.ts | 2 +- src/internal/operators/onErrorResumeNext.ts | 2 ++ src/internal/operators/pairwise.ts | 2 ++ src/internal/operators/partition.ts | 2 ++ src/internal/operators/pluck.ts | 2 ++ src/internal/operators/publish.ts | 6 ++++-- src/internal/operators/reduce.ts | 2 ++ src/internal/operators/repeat.ts | 3 +++ src/internal/operators/repeatWhen.ts | 2 ++ src/internal/operators/retry.ts | 1 + src/internal/operators/retryWhen.ts | 1 + src/internal/operators/sample.ts | 4 +++- src/internal/operators/sampleTime.ts | 2 ++ src/internal/operators/scan.ts | 6 ++---- src/internal/operators/sequenceEqual.ts | 4 +++- src/internal/operators/share.ts | 5 ++++- src/internal/operators/shareReplay.ts | 8 ++++++-- src/internal/operators/single.ts | 2 +- src/internal/operators/skip.ts | 2 ++ src/internal/operators/skipUntil.ts | 2 +- src/internal/operators/skipWhile.ts | 8 ++++++-- src/internal/operators/switchAll.ts | 3 ++- src/internal/operators/switchMap.ts | 3 +++ src/internal/operators/switchMapTo.ts | 4 +++- src/internal/operators/take.ts | 2 ++ src/internal/operators/takeUntil.ts | 2 ++ src/internal/operators/takeWhile.ts | 2 ++ src/internal/operators/tap.ts | 11 +++++----- src/internal/operators/throttle.ts | 2 ++ src/internal/operators/throttleTime.ts | 5 +++-- src/internal/operators/throwIfEmpty.ts | 3 +++ src/internal/operators/timeInterval.ts | 3 ++- src/internal/operators/timeout.ts | 13 +++--------- src/internal/operators/timeoutWith.ts | 4 +--- src/internal/operators/timestamp.ts | 4 ++-- src/internal/operators/toArray.ts | 5 +++-- src/internal/operators/window.ts | 2 ++ src/internal/operators/windowCount.ts | 3 +++ src/internal/operators/windowTime.ts | 6 +++++- src/internal/operators/windowToggle.ts | 2 ++ src/internal/operators/windowWhen.ts | 2 ++ src/internal/operators/withLatestFrom.ts | 2 ++ 111 files changed, 326 insertions(+), 161 deletions(-) diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index 3937f775d4..3fae2dc938 100644 --- a/src/internal/Observable.ts +++ b/src/internal/Observable.ts @@ -124,8 +124,10 @@ export class Observable implements Subscribable { * by default emits all its values synchronously. Always check documentation for how given Observable * will behave when subscribed and if its default behavior can be modified with a `scheduler`. * - * ## Example - * ### Subscribe with an Observer + * ## Examples + * + * Subscribe with an {@link guide/observer Observer} + * * ```ts * import { of } from 'rxjs'; * @@ -154,7 +156,8 @@ export class Observable implements Subscribable { * // "Sum equals: 6" * ``` * - * ### Subscribe with functions + * Subscribe with functions ({@link deprecations/subscribe-arguments deprecated}) + * * ```ts * import { of } from 'rxjs' * @@ -176,7 +179,8 @@ export class Observable implements Subscribable { * // "Sum equals: 6" * ``` * - * ### Cancel a subscription + * Cancel a subscription + * * ```ts * import { interval } from 'rxjs'; * @@ -260,7 +264,7 @@ export class Observable implements Subscribable { * this situation, look into adding something like {@link timeout}, {@link take}, * {@link takeWhile}, or {@link takeUntil} amongst others. * - * ### Example: + * ## Example * * ```ts * import { interval, take } from 'rxjs'; @@ -420,7 +424,8 @@ export class Observable implements Subscribable { * @return {Observable} the Observable result of all of the operators having * been called in the order they were passed in. * - * ### Example + * ## Example + * * ```ts * import { interval, filter, map, scan } from 'rxjs'; * diff --git a/src/internal/ajax/ajax.ts b/src/internal/ajax/ajax.ts index e5964b0b60..3baf3e4eb9 100644 --- a/src/internal/ajax/ajax.ts +++ b/src/internal/ajax/ajax.ts @@ -12,7 +12,8 @@ export interface AjaxCreationMethod { * * This is the most configurable option, and the basis for all other AJAX calls in the library. * - * ### Example + * ## Example + * * ```ts * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; @@ -37,7 +38,8 @@ export interface AjaxCreationMethod { * [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) in * global scope. Defaults to a `responseType` of `"json"`. * - * ### Example + * ## Example + * * ```ts * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; @@ -171,8 +173,10 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * It creates an observable for an Ajax request with either a request object with * url, headers, etc or a string for a URL. * + * ## Examples + * + * Using `ajax()` to fetch the response object that is being returned from API * - * ## Using ajax() to fetch the response object that is being returned from API. * ```ts * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; @@ -186,7 +190,8 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * ); * ``` * - * ## Using ajax.getJSON() to fetch data from API. + * Using `ajax.getJSON()` to fetch data from API + * * ```ts * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; @@ -201,7 +206,8 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * * ``` * - * ## Using ajax() with object as argument and method POST with a two seconds delay. + * Using `ajax()` with object as argument and method POST with a two seconds delay + * * ```ts * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; @@ -226,7 +232,8 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * * ``` * - * ## Using ajax() to fetch. An error object that is being returned from the request. + * Using `ajax()` to fetch. An error object that is being returned from the request + * * ```ts * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; diff --git a/src/internal/firstValueFrom.ts b/src/internal/firstValueFrom.ts index de6e237c63..54687b1d52 100644 --- a/src/internal/firstValueFrom.ts +++ b/src/internal/firstValueFrom.ts @@ -28,10 +28,10 @@ export function firstValueFrom(source: Observable): Promise; * something like {@link timeout}, {@link take}, {@link takeWhile}, or {@link takeUntil} * amongst others. * - * ### Example + * ## Example * * Wait for the first value from a stream and emit it from a promise in - * an async function. + * an async function * * ```ts * import { interval, firstValueFrom } from 'rxjs'; diff --git a/src/internal/lastValueFrom.ts b/src/internal/lastValueFrom.ts index 8a47c74074..dfa4909930 100644 --- a/src/internal/lastValueFrom.ts +++ b/src/internal/lastValueFrom.ts @@ -26,10 +26,10 @@ export function lastValueFrom(source: Observable): Promise; * this situation, look into adding something like {@link timeout}, {@link take}, * {@link takeWhile}, or {@link takeUntil} amongst others. * - * ### Example + * ## Example * * Wait for the last value from a stream and emit it from a promise in - * an async function. + * an async function * * ```ts * import { interval, take, lastValueFrom } from 'rxjs'; diff --git a/src/internal/observable/combineLatest.ts b/src/internal/observable/combineLatest.ts index 65e3ded544..66f1f3a626 100644 --- a/src/internal/observable/combineLatest.ts +++ b/src/internal/observable/combineLatest.ts @@ -110,7 +110,9 @@ export function combineLatest>>( * will error immediately as well, and all other Observables will be unsubscribed. * * ## Examples - * ### Combine two timer Observables + * + * Combine two timer Observables + * * ```ts * import { timer, combineLatest } from 'rxjs'; * @@ -124,7 +126,9 @@ export function combineLatest>>( * // [1, 1] after 1.5s * // [2, 1] after 2s * ``` - * ### Combine a dictionary of Observables + * + * Combine a dictionary of Observables + * * ```ts * import { of, delay, startWith, combineLatest } from 'rxjs'; * @@ -141,7 +145,9 @@ export function combineLatest>>( * // {a: 1, b: 5, c: 0} after 5s * // {a: 1, b: 5, c: 10} after 10s * ``` - * ### Combine an array of Observables + * + * Combine an array of Observables + * * ```ts * import { of, delay, startWith, combineLatest } from 'rxjs'; * @@ -160,8 +166,8 @@ export function combineLatest>>( * // [1, 5, 10] after 10s * ``` * + * Use map operator to dynamically calculate the Body-Mass Index * - * ### Use map operator to dynamically calculate the Body-Mass Index * ```ts * import { of, combineLatest, map } from 'rxjs'; * diff --git a/src/internal/observable/concat.ts b/src/internal/observable/concat.ts index f18037fb32..fcbe9b642f 100644 --- a/src/internal/observable/concat.ts +++ b/src/internal/observable/concat.ts @@ -47,7 +47,9 @@ export function concat( * you can always use {@link repeat}. * * ## Examples - * ### Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10 + * + * Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10 + * * ```ts * import { interval, take, range, concat } from 'rxjs'; * @@ -60,7 +62,8 @@ export function concat( * // 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10 * ``` * - * ### Concatenate 3 Observables + * Concatenate 3 Observables + * * ```ts * import { interval, take, concat } from 'rxjs'; * @@ -78,7 +81,8 @@ export function concat( * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9 * ``` * - * ### Concatenate the same Observable to repeat it + * Concatenate the same Observable to repeat it + * * ```ts * import { interval, take, concat } from 'rxjs'; * diff --git a/src/internal/observable/defer.ts b/src/internal/observable/defer.ts index 417f867790..d555e05d34 100644 --- a/src/internal/observable/defer.ts +++ b/src/internal/observable/defer.ts @@ -21,7 +21,9 @@ import { innerFrom } from './innerFrom'; * function call is transferred to the Observer by calling `error`. * * ## Example - * ### Subscribe to either an Observable of clicks or an Observable of interval, at random + * + * Subscribe to either an Observable of clicks or an Observable of interval, at random + * * ```ts * import { defer, fromEvent, interval } from 'rxjs'; * diff --git a/src/internal/observable/dom/WebSocketSubject.ts b/src/internal/observable/dom/WebSocketSubject.ts index 05d9fc4aae..4c6f145a2b 100644 --- a/src/internal/observable/dom/WebSocketSubject.ts +++ b/src/internal/observable/dom/WebSocketSubject.ts @@ -20,7 +20,8 @@ import { Observer, NextObserver } from '../../types'; * to the socket client. By default `deserializer` is going to apply `JSON.parse` to each message coming * from the Server. * - * ## Example + * ## Examples + * * **deserializer**, the default for this property is `JSON.parse` but since there are just two options * for incoming data, either be text or binarydata. We can apply a custom deserialization strategy * or just simply skip the default behaviour. @@ -41,7 +42,8 @@ import { Observer, NextObserver } from '../../types'; * // This is a msg from the server * ``` * - * **serializer** allows us to apply custom serialization strategy but for the outgoing messages + * **serializer** allows us to apply custom serialization strategy but for the outgoing messages. + * * ```ts * import { webSocket } from 'rxjs/webSocket'; * @@ -61,7 +63,8 @@ import { Observer, NextObserver } from '../../types'; * // {"channel":"webDevelopment","msg":"msg to the server"} * ``` * - * **closeObserver** allows us to set a custom error when an error raise up. + * **closeObserver** allows us to set a custom error when an error raises up. + * * ```ts * import { webSocket } from 'rxjs/webSocket'; * @@ -97,8 +100,7 @@ import { Observer, NextObserver } from '../../types'; * //output * // connetion ok` * ``` - * */ - + */ export interface WebSocketSubjectConfig { /** The url of the socket server to connect to */ url: string; diff --git a/src/internal/observable/dom/animationFrames.ts b/src/internal/observable/dom/animationFrames.ts index 5bbfba3181..64a65cd014 100644 --- a/src/internal/observable/dom/animationFrames.ts +++ b/src/internal/observable/dom/animationFrames.ts @@ -19,7 +19,7 @@ import { animationFrameProvider } from '../../scheduler/animationFrameProvider'; * * This is useful for setting up animations with RxJS. * - * ### Example + * ## Examples * * Tweening a div to move it on the screen * @@ -54,8 +54,6 @@ import { animationFrameProvider } from '../../scheduler/animationFrameProvider'; * }); * ``` * - * ### Example - * * Providing a custom timestamp provider * * ```ts diff --git a/src/internal/observable/dom/fetch.ts b/src/internal/observable/dom/fetch.ts index b95c380eb7..202c93c622 100644 --- a/src/internal/observable/dom/fetch.ts +++ b/src/internal/observable/dom/fetch.ts @@ -26,7 +26,9 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab * `fetch`. If the provided `signal` aborts, the error that `fetch` normally rejects with * in that scenario will be emitted as an error from the observable. * - * ### Basic Use + * ## Examples + * + * Basic use * * ```ts * import { fromFetch } from 'rxjs/fetch'; diff --git a/src/internal/observable/dom/webSocket.ts b/src/internal/observable/dom/webSocket.ts index e11560748c..bb8d9115cb 100644 --- a/src/internal/observable/dom/webSocket.ts +++ b/src/internal/observable/dom/webSocket.ts @@ -82,8 +82,10 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject'; * is not a `WebSocketSubject`, so calling `next` or `multiplex` again will fail. For pushing values to the * server, use root `WebSocketSubject`. * - * ### Examples - * #### Listening for messages from the server + * ## Examples + * + * Listening for messages from the server + * * ```ts * import { webSocket } from "rxjs/webSocket"; * const subject = webSocket("ws://localhost:8081"); @@ -95,7 +97,8 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject'; * ); * ``` * - * #### Pushing messages to the server + * Pushing messages to the server + * * ```ts * import { webSocket } from "rxjs/webSocket"; * const subject = webSocket('ws://localhost:8081'); @@ -113,7 +116,8 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject'; * // Also closes the connection, but let's the server know that this closing is caused by some error. * ``` * - * #### Multiplexing WebSocket + * Multiplexing WebSocket + * * ```ts * import { webSocket } from "rxjs/webSocket"; * const subject = webSocket('ws://localhost:8081'); diff --git a/src/internal/observable/empty.ts b/src/internal/observable/empty.ts index 90103d4ee8..d6fb8684a0 100644 --- a/src/internal/observable/empty.ts +++ b/src/internal/observable/empty.ts @@ -11,7 +11,7 @@ import { SchedulerLike } from '../types'; * * ## Examples * - * ### Log complete notification + * Log complete notification * * ```ts * import { EMPTY } from 'rxjs'; @@ -41,7 +41,7 @@ export const EMPTY = new Observable((subscriber) => subscriber.complete() * * ## Examples * - * ### Emit the number 7, then complete + * Emit the number 7, then complete * * ```ts * import { empty, startWith } from 'rxjs'; @@ -53,7 +53,7 @@ export const EMPTY = new Observable((subscriber) => subscriber.complete() * // 7 * ``` * - * ### Map and flatten only odd numbers to the sequence 'a', 'b', 'c' + * Map and flatten only odd numbers to the sequence 'a', 'b', 'c' * * ```ts * import { interval, mergeMap, of, empty } from 'rxjs'; diff --git a/src/internal/observable/forkJoin.ts b/src/internal/observable/forkJoin.ts index ab5a5a19e9..f0b1d351dd 100644 --- a/src/internal/observable/forkJoin.ts +++ b/src/internal/observable/forkJoin.ts @@ -94,7 +94,8 @@ export function forkJoin>>( * * ## Examples * - * ### Use forkJoin with a dictionary of observable inputs + * Use `forkJoin` with a dictionary of observable inputs + * * ```ts * import { forkJoin, of, timer } from 'rxjs'; * @@ -113,7 +114,8 @@ export function forkJoin>>( * // "This is how it ends!" immediately after * ``` * - * ### Use forkJoin with an array of observable inputs + * Use `forkJoin` with an array of observable inputs + * * ```ts * import { forkJoin, of, timer } from 'rxjs'; * diff --git a/src/internal/observable/from.ts b/src/internal/observable/from.ts index 6ab2def3d7..88b988724a 100644 --- a/src/internal/observable/from.ts +++ b/src/internal/observable/from.ts @@ -22,7 +22,7 @@ export function from>(input: O, scheduler: Schedu * * ## Examples * - * ### Converts an array to an Observable + * Converts an array to an Observable * * ```ts * import { from } from 'rxjs'; @@ -38,9 +38,7 @@ export function from>(input: O, scheduler: Schedu * // 30 * ``` * - * --- - * - * ### Convert an infinite iterable (from a generator) to an Observable + * Convert an infinite iterable (from a generator) to an Observable * * ```ts * import { from, take } from 'rxjs'; @@ -71,9 +69,7 @@ export function from>(input: O, scheduler: Schedu * // 1536 * ``` * - * --- - * - * ### With async scheduler + * With `asyncScheduler` * * ```ts * import { from, asyncScheduler } from 'rxjs'; diff --git a/src/internal/observable/fromEvent.ts b/src/internal/observable/fromEvent.ts index 8044ff9da9..0dd31bfe4b 100644 --- a/src/internal/observable/fromEvent.ts +++ b/src/internal/observable/fromEvent.ts @@ -185,7 +185,9 @@ export function fromEvent( * * * ## Examples - * ### Emits clicks happening on the DOM document + * + * Emit clicks happening on the DOM document + * * ```ts * import { fromEvent } from 'rxjs'; * @@ -197,7 +199,8 @@ export function fromEvent( * // occurs on the document. * ``` * - * ### Use addEventListener with capture option + * Use `addEventListener` with capture option + * * ```ts * import { fromEvent } from 'rxjs'; * diff --git a/src/internal/observable/fromEventPattern.ts b/src/internal/observable/fromEventPattern.ts index 92f5e45ab0..7545d9a99b 100644 --- a/src/internal/observable/fromEventPattern.ts +++ b/src/internal/observable/fromEventPattern.ts @@ -60,8 +60,9 @@ export function fromEventPattern( * that default project can be thought of as function that takes its first parameter * and ignores the rest. * - * ## Example - * ### Emits clicks happening on the DOM document + * ## Examples + * + * Emits clicks happening on the DOM document * * ```ts * import { fromEventPattern } from 'rxjs'; @@ -84,8 +85,7 @@ export function fromEventPattern( * // object will be logged. * ``` * - * ## Example - * ### Use with API that returns cancellation token + * Use with API that returns cancellation token * * ```ts * import { fromEventPattern } from 'rxjs'; @@ -100,8 +100,7 @@ export function fromEventPattern( * ); * ``` * - * ## Example - * ### Use with project function + * Use with project function * * ```ts * import { fromEventPattern } from 'rxjs'; diff --git a/src/internal/observable/generate.ts b/src/internal/observable/generate.ts index ed467e0703..767d1fd21c 100644 --- a/src/internal/observable/generate.ts +++ b/src/internal/observable/generate.ts @@ -47,7 +47,7 @@ export interface GenerateOptions extends GenerateBaseOptions { * * ## Examples * - * ### Produces sequences of number + * Produces sequence of numbers * * ```ts * import { generate } from 'rxjs'; @@ -62,12 +62,12 @@ export interface GenerateOptions extends GenerateBaseOptions { * // 2 * ``` * - * ### Use asap scheduler + * Use `asapScheduler` * * ```ts - * import { generate } from 'rxjs'; + * import { generate, asapScheduler } from 'rxjs'; * - * const result = generate(1, x => x < 5, x => x * 2, x => x + 1, asap); + * const result = generate(1, x => x < 5, x => x * 2, x => x + 1, asapScheduler); * * result.subscribe(x => console.log(x)); * @@ -142,7 +142,7 @@ export function generate( * * ## Examples * - * ### Use with condition and iterate functions + * Use with condition and iterate functions * * ```ts * import { generate } from 'rxjs'; @@ -161,7 +161,7 @@ export function generate( * // "Complete!" * ``` * - * ### Use with condition, iterate and resultSelector functions + * Use with condition, iterate and resultSelector functions * * ```ts * import { generate } from 'rxjs'; @@ -180,7 +180,7 @@ export function generate( * // "complete!" * ``` * - * ### Use with options object + * Use with options object * * ```ts * import { generate } from 'rxjs'; @@ -204,7 +204,7 @@ export function generate( * // "Complete!" * ``` * - * ### Use options object without condition function + * Use options object without condition function * * ```ts * import { generate } from 'rxjs'; @@ -257,7 +257,7 @@ export function generate( * * ## Examples * - * ### Use options object with condition function + * Use options object with condition function * * ```ts * import { generate } from 'rxjs'; @@ -299,7 +299,7 @@ export function generate(options: GenerateBaseOptions): Observable; * * ## Examples * - * ### Use options object with condition and iterate function + * Use options object with condition and iterate function * * ```ts * import { generate } from 'rxjs'; diff --git a/src/internal/observable/iif.ts b/src/internal/observable/iif.ts index d1e8e6544a..e23026f1e9 100644 --- a/src/internal/observable/iif.ts +++ b/src/internal/observable/iif.ts @@ -16,7 +16,7 @@ import { ObservableInput } from '../types'; * * ## Examples * - * ### Change at runtime which Observable will be subscribed + * Change at runtime which Observable will be subscribed * * ```ts * import { iif, of } from 'rxjs'; @@ -42,7 +42,7 @@ import { ObservableInput } from '../types'; * * ``` * - * ### Control an access to an Observable + * Control access to an Observable * * ```ts * let accessGranted; diff --git a/src/internal/observable/interval.ts b/src/internal/observable/interval.ts index 91953b53d0..fc1b3e0a77 100644 --- a/src/internal/observable/interval.ts +++ b/src/internal/observable/interval.ts @@ -7,8 +7,7 @@ import { timer } from './timer'; * Creates an Observable that emits sequential numbers every specified * interval of time, on a specified {@link SchedulerLike}. * - * Emits incremental numbers periodically in time. - * + * Emits incremental numbers periodically in time. * * ![](interval.png) * @@ -20,7 +19,9 @@ import { timer } from './timer'; * {@link SchedulerLike} to it. * * ## Example + * * Emits ascending numbers, one every second (1000ms) up to the number 3 + * * ```ts * import { interval, take } from 'rxjs'; * diff --git a/src/internal/observable/merge.ts b/src/internal/observable/merge.ts index 5522ff94d7..9953d0cd3e 100644 --- a/src/internal/observable/merge.ts +++ b/src/internal/observable/merge.ts @@ -33,7 +33,9 @@ export function merge( * Observable will be immediately emitted on the output Observable. * * ## Examples - * ### Merge together two Observables: 1s interval and clicks + * + * Merge together two Observables: 1s interval and clicks + * * ```ts * import { merge, fromEvent, interval } from 'rxjs'; * @@ -49,7 +51,8 @@ export function merge( * // as they occur. * ``` * - * ### Merge together 3 Observables, but only 2 run concurrently + * Merge together 3 Observables, but run only 2 concurrently + * * ```ts * import { interval, take, merge } from 'rxjs'; * diff --git a/src/internal/observable/never.ts b/src/internal/observable/never.ts index 789fea072d..c8177a0716 100644 --- a/src/internal/observable/never.ts +++ b/src/internal/observable/never.ts @@ -13,7 +13,9 @@ import { noop } from '../util/noop'; * Subscriptions need to be manually disposed. * * ## Example - * ### Emit the number 7, then never emit anything else (not even complete) + * + * Emit the number 7, then never emit anything else (not even complete) + * * ```ts * import { NEVER, startWith } from 'rxjs'; * diff --git a/src/internal/observable/onErrorResumeNext.ts b/src/internal/observable/onErrorResumeNext.ts index 357b6eeaf6..6cb016ff6a 100644 --- a/src/internal/observable/onErrorResumeNext.ts +++ b/src/internal/observable/onErrorResumeNext.ts @@ -32,7 +32,9 @@ export function onErrorResumeNext(...sources: [... * always use the {@link catchError} operator on them before passing them into `onErrorResumeNext`. * * ## Example - * Subscribe to the next Observable after map fails + * + * Subscribe to the next Observable after map fails + * * ```ts * import { onErrorResumeNext, of, map } from 'rxjs'; * diff --git a/src/internal/observable/pairs.ts b/src/internal/observable/pairs.ts index 071879bce8..2e0caa8b79 100644 --- a/src/internal/observable/pairs.ts +++ b/src/internal/observable/pairs.ts @@ -40,7 +40,9 @@ export function pairs( * pass a {@link SchedulerLike} as a second argument to `pairs`. * * ## Example - * ### Converts an object to an Observable + * + * Converts an object to an Observable + * * ```ts * import { pairs } from 'rxjs'; * diff --git a/src/internal/observable/partition.ts b/src/internal/observable/partition.ts index 1c3c9dfa9b..e2f741deb6 100644 --- a/src/internal/observable/partition.ts +++ b/src/internal/observable/partition.ts @@ -41,7 +41,9 @@ export function partition(source: ObservableInput, predicate: (value: T, i * behaves like {@link filter} with the predicate negated. * * ## Example + * * Partition a set of numbers into odds and evens observables + * * ```ts * import { of, partition } from 'rxjs'; * diff --git a/src/internal/observable/race.ts b/src/internal/observable/race.ts index f26c96f2f6..26e56d0ac2 100644 --- a/src/internal/observable/race.ts +++ b/src/internal/observable/race.ts @@ -28,7 +28,8 @@ export function race(...inputs: [...ObservableInpu * input. * * ## Example - * ### Subscribes to the observable that was the first to start emitting. + * + * Subscribes to the observable that was the first to start emitting. * * ```ts * import { interval, mapTo, race } from 'rxjs'; diff --git a/src/internal/observable/range.ts b/src/internal/observable/range.ts index 834e393932..df205e9349 100644 --- a/src/internal/observable/range.ts +++ b/src/internal/observable/range.ts @@ -24,7 +24,7 @@ export function range(start: number, count: number | undefined, scheduler: Sched * * ## Example * - * ### Produce a range of numbers + * Produce a range of numbers * * ```ts * import { range } from 'rxjs'; diff --git a/src/internal/observable/throwError.ts b/src/internal/observable/throwError.ts index f4f1687cf0..aeed06c01c 100644 --- a/src/internal/observable/throwError.ts +++ b/src/internal/observable/throwError.ts @@ -20,7 +20,7 @@ import { isFunction } from '../util/isFunction'; * ## Example * * Create a simple observable that will create a new error with a timestamp and log it - * and the message every time you subscribe to it. + * and the message every time you subscribe to it * * ```ts * import { throwError } from 'rxjs'; @@ -44,10 +44,10 @@ import { isFunction } from '../util/isFunction'; * // Logs the timestamp and a new error message each subscription; * ``` * - * ## Unnecessary usage + * ### Unnecessary usage * * Using `throwError` inside of an operator or creation function - * with a callback, is usually not necessary: + * with a callback, is usually not necessary * * ```ts * import { of, concatMap, timer, throwError } from 'rxjs'; @@ -70,7 +70,7 @@ import { isFunction } from '../util/isFunction'; * }); * ``` * - * You can just throw the error instead: + * You can just throw the error instead * * ```ts * import { of, concatMap, timer } from 'rxjs'; diff --git a/src/internal/observable/timer.ts b/src/internal/observable/timer.ts index 963f4b3e1a..94d93fdc26 100644 --- a/src/internal/observable/timer.ts +++ b/src/internal/observable/timer.ts @@ -18,7 +18,7 @@ import { isValidDate } from '../util/isDate'; * * ## Examples * - * ### Wait 3 seconds and start another observable + * Wait 3 seconds and start another observable * * You might want to use `timer` to delay subscription to an * observable by a set amount of time. Here we use a timer with @@ -37,7 +37,7 @@ import { isValidDate } from '../util/isDate'; * .subscribe(console.log); * ``` * - * ### Take all of the values until the start of the next minute + * Take all values until the start of the next minute * * Using a `Date` as the trigger for the first emission, you can * do things like wait until midnight to fire an event, or in this case, diff --git a/src/internal/operators/audit.ts b/src/internal/operators/audit.ts index 785cc1abf7..4f109a9f5f 100644 --- a/src/internal/operators/audit.ts +++ b/src/internal/operators/audit.ts @@ -29,6 +29,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ## Example * * Emit clicks at a rate of at most one click per second + * * ```ts * import { fromEvent, audit, interval } from 'rxjs'; * diff --git a/src/internal/operators/auditTime.ts b/src/internal/operators/auditTime.ts index f11aefcc7c..af83889db9 100644 --- a/src/internal/operators/auditTime.ts +++ b/src/internal/operators/auditTime.ts @@ -27,6 +27,7 @@ import { MonoTypeOperatorFunction, SchedulerLike } from '../types'; * ## Example * * Emit clicks at a rate of at most one click per second + * * ```ts * import { fromEvent, auditTime } from 'rxjs'; * diff --git a/src/internal/operators/catchError.ts b/src/internal/operators/catchError.ts index eec51f2a9f..325581d7c9 100644 --- a/src/internal/operators/catchError.ts +++ b/src/internal/operators/catchError.ts @@ -28,7 +28,8 @@ export function catchError>( * subscribe to it, and forward all of its events to the resulting observable. * * ## Examples - * Continues with a different Observable when there's an error + * + * Continue with a different Observable when there's an error * * ```ts * import { of, map, catchError } from 'rxjs'; @@ -46,7 +47,7 @@ export function catchError>( * // 1, 2, 3, I, II, III, IV, V * ``` * - * Retries the caught source Observable again in case of error, similar to retry() operator + * Retry the caught source Observable again in case of error, similar to `retry()` operator * * ```ts * import { of, map, catchError, take } from 'rxjs'; @@ -65,7 +66,7 @@ export function catchError>( * // 1, 2, 3, 1, 2, 3, ... * ``` * - * Throws a new error when the source Observable throws an error + * Throw a new error when the source Observable throws an error * * ```ts * import { of, map, catchError } from 'rxjs'; diff --git a/src/internal/operators/combineLatestAll.ts b/src/internal/operators/combineLatestAll.ts index b8ce348dbf..b0b390ac96 100644 --- a/src/internal/operators/combineLatestAll.ts +++ b/src/internal/operators/combineLatestAll.ts @@ -21,11 +21,9 @@ export function combineLatestAll(project: (...values: Array) => R): Oper * arrived, and the result of the `project` function is what is emitted by the output Observable. * * If there is no `project` function, an array of all the most recent values is emitted by the output Observable. * - * --- + * ## Example * - * ## Examples - * - * ### Map two click events to a finite interval Observable, then apply `combineLatestAll` + * Map two click events to a finite interval Observable, then apply `combineLatestAll` * * ```ts * import { fromEvent, map, interval, take, combineLatestAll } from 'rxjs'; diff --git a/src/internal/operators/combineLatestWith.ts b/src/internal/operators/combineLatestWith.ts index 6d72438368..b262f890b8 100644 --- a/src/internal/operators/combineLatestWith.ts +++ b/src/internal/operators/combineLatestWith.ts @@ -12,9 +12,9 @@ import { combineLatest } from './combineLatest'; * * This is a useful operator for eagerly calculating values based off of changed inputs. * - * ### Example + * ## Example * - * Simple calculation from two inputs. + * Simple concatenation of values from two inputs * * ```ts * import { fromEvent, combineLatestWith, map } from 'rxjs'; @@ -32,11 +32,11 @@ import { combineLatest } from './combineLatest'; * // Combine the changes by adding them together * input1Changes$.pipe( * combineLatestWith(input2Changes$), - * map(([e1, e2]) => Number(e1.target.value) + Number(e2.target.value)), + * map(([e1, e2]) => (e1.target).value + ' - ' + (e2.target).value) * ) * .subscribe(x => console.log(x)); - * * ``` + * * @param otherSources the other sources to subscribe to. * @return A function that returns an Observable that emits the latest * emissions from both source and provided Observables. diff --git a/src/internal/operators/concatAll.ts b/src/internal/operators/concatAll.ts index 8c2aab31ff..9ff80a0891 100644 --- a/src/internal/operators/concatAll.ts +++ b/src/internal/operators/concatAll.ts @@ -26,6 +26,7 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * ## Example * * For each click event, tick every second from 0 to 3, with no concurrency + * * ```ts * import { fromEvent, map, interval, take, concatAll } from 'rxjs'; * diff --git a/src/internal/operators/concatMap.ts b/src/internal/operators/concatMap.ts index f8bbac15d3..21bbf42431 100644 --- a/src/internal/operators/concatMap.ts +++ b/src/internal/operators/concatMap.ts @@ -42,6 +42,7 @@ export function concatMap>( * to `1`. * * ## Example + * * For each click event, tick every second from 0 to 3, with no concurrency * * ```ts diff --git a/src/internal/operators/concatMapTo.ts b/src/internal/operators/concatMapTo.ts index 409f76ffa5..6b179064ef 100644 --- a/src/internal/operators/concatMapTo.ts +++ b/src/internal/operators/concatMapTo.ts @@ -40,7 +40,9 @@ export function concatMapTo>( * set to `1`. * * ## Example + * * For each click event, tick every second from 0 to 3, with no concurrency + * * ```ts * import { fromEvent, concatMapTo, interval, take } from 'rxjs'; * diff --git a/src/internal/operators/connect.ts b/src/internal/operators/connect.ts index 85221fac9a..9908fbbfda 100644 --- a/src/internal/operators/connect.ts +++ b/src/internal/operators/connect.ts @@ -43,7 +43,7 @@ const DEFAULT_CONFIG: ConnectConfig = { * the `selector` function returns, the observable it returns will be subscribed to, _then_ the * multicast will be connected to the source. * - * ### Example + * ## Example * * Sharing a totally synchronous observable * diff --git a/src/internal/operators/count.ts b/src/internal/operators/count.ts index f297a43df2..09e26969f6 100644 --- a/src/internal/operators/count.ts +++ b/src/internal/operators/count.ts @@ -21,6 +21,7 @@ import { reduce } from './reduce'; * ## Examples * * Counts how many seconds have passed before the first click happened + * * ```ts * import { interval, fromEvent, takeUntil, count } from 'rxjs'; * @@ -32,6 +33,7 @@ import { reduce } from './reduce'; * ``` * * Counts how many odd numbers are there between 1 and 7 + * * ```ts * import { range, count } from 'rxjs'; * diff --git a/src/internal/operators/debounce.ts b/src/internal/operators/debounce.ts index 6f736a0e81..191c546376 100644 --- a/src/internal/operators/debounce.ts +++ b/src/internal/operators/debounce.ts @@ -33,7 +33,9 @@ import { innerFrom } from '../observable/innerFrom'; * same time as they did on the source Observable. * * ## Example + * * Emit the most recent click after a burst of clicks + * * ```ts * import { fromEvent, scan, debounce, interval } from 'rxjs'; * diff --git a/src/internal/operators/debounceTime.ts b/src/internal/operators/debounceTime.ts index f1e3076819..6b8afb2dae 100644 --- a/src/internal/operators/debounceTime.ts +++ b/src/internal/operators/debounceTime.ts @@ -32,7 +32,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * managing timers. * * ## Example + * * Emit the most recent click after a burst of clicks + * * ```ts * import { fromEvent, debounceTime } from 'rxjs'; * diff --git a/src/internal/operators/defaultIfEmpty.ts b/src/internal/operators/defaultIfEmpty.ts index 19e22a7646..eb27f463ec 100644 --- a/src/internal/operators/defaultIfEmpty.ts +++ b/src/internal/operators/defaultIfEmpty.ts @@ -16,7 +16,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * having emitted any `next` value). * * ## Example - * If no clicks happen in 5 seconds, then emit "no clicks" + * + * If no clicks happen in 5 seconds, then emit 'no clicks' + * * ```ts * import { fromEvent, takeUntil, interval, defaultIfEmpty } from 'rxjs'; * diff --git a/src/internal/operators/delay.ts b/src/internal/operators/delay.ts index 93c8be0da6..299259b0e9 100644 --- a/src/internal/operators/delay.ts +++ b/src/internal/operators/delay.ts @@ -20,7 +20,9 @@ import { timer } from '../observable/timer'; * Observable execution until the given date occurs. * * ## Examples + * * Delay each click by one second + * * ```ts * import { fromEvent, delay } from 'rxjs'; * @@ -30,6 +32,7 @@ import { timer } from '../observable/timer'; * ``` * * Delay all clicks until a future date happens + * * ```ts * import { fromEvent, delay } from 'rxjs'; * diff --git a/src/internal/operators/delayWhen.ts b/src/internal/operators/delayWhen.ts index 53df4e9441..c2a0546980 100644 --- a/src/internal/operators/delayWhen.ts +++ b/src/internal/operators/delayWhen.ts @@ -39,7 +39,9 @@ export function delayWhen(delayDurationSelector: (value: T, index: number) => * Observable is subscribed. * * ## Example + * * Delay each click by a random amount of time, between 0 and 5 seconds + * * ```ts * import { fromEvent, delayWhen, interval } from 'rxjs'; * diff --git a/src/internal/operators/distinct.ts b/src/internal/operators/distinct.ts index 52fa9302f7..bc266420a7 100644 --- a/src/internal/operators/distinct.ts +++ b/src/internal/operators/distinct.ts @@ -38,7 +38,7 @@ import { noop } from '../util/noop'; * // 4 * ``` * - * An example using a keySelector function + * An example using the `keySelector` function * * ```ts * import { of, distinct } from 'rxjs'; diff --git a/src/internal/operators/distinctUntilChanged.ts b/src/internal/operators/distinctUntilChanged.ts index 9ca2ded444..53432d1304 100644 --- a/src/internal/operators/distinctUntilChanged.ts +++ b/src/internal/operators/distinctUntilChanged.ts @@ -13,7 +13,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * 3. If the value pushed by the source is determined to be unequal by this check, that value is emitted and * becomes the new "previously emitted value" internally. * - * ## Example + * ## Examples * * A very basic example with no `comparator`. Note that `1` is emitted more than once, * because it's distinct in comparison to the _previously emitted_ value, @@ -29,8 +29,6 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * // Logs: 1, 2, 1, 3 * ``` * - * ## Example - * * With a `comparator`, you can do custom comparisons. Let's say * you only want to emit a value when all of its components have * changed: @@ -61,8 +59,6 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * // {engineVersion: "2.0.0", transmissionVersion: "1.5.0"} * ``` * - * ## Example - * * You can also provide a custom `comparator` to check that emitted * changes are only in one direction. Let's say you only want to get * the next record temperature: diff --git a/src/internal/operators/distinctUntilKeyChanged.ts b/src/internal/operators/distinctUntilKeyChanged.ts index 85c22322c5..3bfbc07b30 100644 --- a/src/internal/operators/distinctUntilKeyChanged.ts +++ b/src/internal/operators/distinctUntilKeyChanged.ts @@ -15,7 +15,9 @@ export function distinctUntilKeyChanged(key: K, compare: ( * If a comparator function is not provided, an equality check is used by default. * * ## Examples + * * An example comparing the name of persons + * * ```ts * import { of, distinctUntilKeyChanged } from 'rxjs'; * @@ -41,6 +43,7 @@ export function distinctUntilKeyChanged(key: K, compare: ( * ``` * * An example comparing the first letters of the name + * * ```ts * import { of, distinctUntilKeyChanged } from 'rxjs'; * diff --git a/src/internal/operators/elementAt.ts b/src/internal/operators/elementAt.ts index 5a6a66862b..6a817fc5dd 100644 --- a/src/internal/operators/elementAt.ts +++ b/src/internal/operators/elementAt.ts @@ -21,7 +21,9 @@ import { take } from './take'; * `ArgumentOutOfRangeError` error. * * ## Example + * * Emit only the third click event + * * ```ts * import { fromEvent, elementAt } from 'rxjs'; * diff --git a/src/internal/operators/every.ts b/src/internal/operators/every.ts index 5056c52cdf..036ce82e96 100644 --- a/src/internal/operators/every.ts +++ b/src/internal/operators/every.ts @@ -25,7 +25,9 @@ export function every(predicate: (value: T, index: number, source: Observable * ![](every.png) * * ## Example + * * A simple example emitting true if all elements are less than 5, false otherwise + * * ```ts * import { of, every } from 'rxjs'; * diff --git a/src/internal/operators/exhaustAll.ts b/src/internal/operators/exhaustAll.ts index 5a48a1ec05..eca72e979b 100644 --- a/src/internal/operators/exhaustAll.ts +++ b/src/internal/operators/exhaustAll.ts @@ -22,7 +22,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * next inner Observable and repeat this process. * * ## Example + * * Run a finite timer for each click, only if there is no currently active timer + * * ```ts * import { fromEvent, map, interval, take, exhaustAll } from 'rxjs'; * diff --git a/src/internal/operators/exhaustMap.ts b/src/internal/operators/exhaustMap.ts index 8d4ace559f..c016745687 100644 --- a/src/internal/operators/exhaustMap.ts +++ b/src/internal/operators/exhaustMap.ts @@ -41,7 +41,9 @@ export function exhaustMap( * and repeat this process. * * ## Example + * * Run a finite timer for each click, only if there is no currently active timer + * * ```ts * import { fromEvent, exhaustMap, interval, take } from 'rxjs'; * diff --git a/src/internal/operators/expand.ts b/src/internal/operators/expand.ts index 6205ed5890..8dbb08172e 100644 --- a/src/internal/operators/expand.ts +++ b/src/internal/operators/expand.ts @@ -41,7 +41,9 @@ export function expand>( * *expand* behaves recursively. * * ## Example + * * Start emitting the powers of two on every click, at most 10 of them + * * ```ts * import { fromEvent, mapTo, expand, of, delay, take } from 'rxjs'; * diff --git a/src/internal/operators/filter.ts b/src/internal/operators/filter.ts index 7c6f5f2976..ec41fd17cf 100644 --- a/src/internal/operators/filter.ts +++ b/src/internal/operators/filter.ts @@ -25,7 +25,9 @@ export function filter(predicate: (value: T, index: number) => boolean): Mono * function and only emits those values that yielded `true`. * * ## Example + * * Emit only click events whose target was a DIV element + * * ```ts * import { fromEvent, filter } from 'rxjs'; * diff --git a/src/internal/operators/finalize.ts b/src/internal/operators/finalize.ts index 2844fe9acd..70a9194552 100644 --- a/src/internal/operators/finalize.ts +++ b/src/internal/operators/finalize.ts @@ -7,6 +7,7 @@ import { operate } from '../util/lift'; * The specified function will also be called when the subscriber explicitly unsubscribes. * * ## Examples + * * Execute callback function when the observable completes * * ```ts diff --git a/src/internal/operators/find.ts b/src/internal/operators/find.ts index 7f46f414dc..6099a84426 100644 --- a/src/internal/operators/find.ts +++ b/src/internal/operators/find.ts @@ -35,7 +35,9 @@ export function find(predicate: (value: T, index: number, source: Observable< * (emits `undefined` instead). * * ## Example + * * Find and emit the first click that happens on a DIV element + * * ```ts * import { fromEvent, find } from 'rxjs'; * diff --git a/src/internal/operators/findIndex.ts b/src/internal/operators/findIndex.ts index 593078865b..666cedc430 100644 --- a/src/internal/operators/findIndex.ts +++ b/src/internal/operators/findIndex.ts @@ -29,7 +29,9 @@ export function findIndex(predicate: (value: T, index: number, source: Observ * an error if a valid value is not found. * * ## Example + * * Emit the index of first click that happens on a DIV element + * * ```ts * import { fromEvent, findIndex } from 'rxjs'; * diff --git a/src/internal/operators/first.ts b/src/internal/operators/first.ts index 6cb4cb7312..1f53ae9fab 100644 --- a/src/internal/operators/first.ts +++ b/src/internal/operators/first.ts @@ -38,7 +38,9 @@ export function first( * `defaultValue` was not provided and a matching element is not found. * * ## Examples + * * Emit only the first click that happens on the DOM + * * ```ts * import { fromEvent, first } from 'rxjs'; * @@ -48,6 +50,7 @@ export function first( * ``` * * Emits the first click that happens on a DIV + * * ```ts * import { fromEvent, first } from 'rxjs'; * diff --git a/src/internal/operators/groupBy.ts b/src/internal/operators/groupBy.ts index 29ecb25194..835e3d59fa 100644 --- a/src/internal/operators/groupBy.ts +++ b/src/internal/operators/groupBy.ts @@ -68,7 +68,7 @@ export function groupBy( * * ## Examples * - * ### Group objects by id and return as array + * Group objects by `id` and return as array * * ```ts * import { of, groupBy, mergeMap, reduce } from 'rxjs'; @@ -95,7 +95,7 @@ export function groupBy( * // [ { id: 3, name: 'TSLint'} ] * ``` * - * ### Pivot data on the id field + * Pivot data on the `id` field * * ```ts * import { of, groupBy, mergeMap, reduce, map } from 'rxjs'; diff --git a/src/internal/operators/ignoreElements.ts b/src/internal/operators/ignoreElements.ts index f5a50d6ada..2fb7cc1179 100644 --- a/src/internal/operators/ignoreElements.ts +++ b/src/internal/operators/ignoreElements.ts @@ -15,7 +15,10 @@ import { noop } from '../util/noop'; * when it completes or when it terminates with an error, you can apply the `ignoreElements` operator * to the Observable, which will ensure that it will never call its observers’ `next` handlers. * - * ## Examples + * ## Example + * + * Ignore all `next` emissions from the source + * * ```ts * import { of, ignoreElements } from 'rxjs'; * diff --git a/src/internal/operators/isEmpty.ts b/src/internal/operators/isEmpty.ts index ea1cad56f7..1a8b82c381 100644 --- a/src/internal/operators/isEmpty.ts +++ b/src/internal/operators/isEmpty.ts @@ -22,7 +22,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * ## Examples * - * Emit `false` for a non-empty Observable. + * Emit `false` for a non-empty Observable * * ```ts * import { Subject, isEmpty } from 'rxjs'; @@ -45,7 +45,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * // c * ``` * - * Emit `true` for an empty Observable. + * Emit `true` for an empty Observable * * ```ts * import { EMPTY, isEmpty } from 'rxjs'; diff --git a/src/internal/operators/last.ts b/src/internal/operators/last.ts index d014d21408..58f77f7d48 100644 --- a/src/internal/operators/last.ts +++ b/src/internal/operators/last.ts @@ -31,8 +31,10 @@ export function last( * returns the last value or if a predicate is provided last value that matches the predicate. It returns the * given default value if no notification is emitted or matches the predicate. * - * ## Example - * Last alphabet from the sequence. + * ## Examples + * + * Last alphabet from the sequence + * * ```ts * import { from, last } from 'rxjs'; * @@ -42,7 +44,8 @@ export function last( * example.subscribe(val => console.log(`Last alphabet: ${val}`)); * ``` * - * Default value when the value in the predicate is not matched. + * Default value when the value in the predicate is not matched + * * ```ts * import { from, last } from 'rxjs'; * diff --git a/src/internal/operators/map.ts b/src/internal/operators/map.ts index 25fde84926..14aaa99837 100644 --- a/src/internal/operators/map.ts +++ b/src/internal/operators/map.ts @@ -21,7 +21,9 @@ export function map(project: (this: A, value: T, index: number) => R, t * Observable. * * ## Example - * Map every click to the clientX position of that click + * + * Map every click to the `clientX` position of that click + * * ```ts * import { fromEvent, map } from 'rxjs'; * diff --git a/src/internal/operators/mapTo.ts b/src/internal/operators/mapTo.ts index 155f510c9f..90b1823832 100644 --- a/src/internal/operators/mapTo.ts +++ b/src/internal/operators/mapTo.ts @@ -19,7 +19,9 @@ export function mapTo(value: R): OperatorFunction; * and simply uses the emission moment to know when to emit the given `value`. * * ## Example - * Map every click to the string 'Hi' + * + * Map every click to the string `'Hi'` + * * ```ts * import { fromEvent, mapTo } from 'rxjs'; * diff --git a/src/internal/operators/max.ts b/src/internal/operators/max.ts index fde2205984..ebb241ca3f 100644 --- a/src/internal/operators/max.ts +++ b/src/internal/operators/max.ts @@ -9,7 +9,9 @@ import { isFunction } from '../util/isFunction'; * ![](max.png) * * ## Examples + * * Get the maximal value of a series of numbers + * * ```ts * import { of, max } from 'rxjs'; * @@ -20,6 +22,7 @@ import { isFunction } from '../util/isFunction'; * ``` * * Use a comparer function to get the maximal item + * * ```ts * import { of, max } from 'rxjs'; * diff --git a/src/internal/operators/mergeAll.ts b/src/internal/operators/mergeAll.ts index 06f8212e69..8807374740 100644 --- a/src/internal/operators/mergeAll.ts +++ b/src/internal/operators/mergeAll.ts @@ -18,7 +18,9 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * a inner Observable will be immediately emitted on the output Observable. * * ## Examples + * * Spawn a new interval Observable for each click event, and blend their outputs as one Observable + * * ```ts * import { fromEvent, map, interval, mergeAll } from 'rxjs'; * @@ -29,6 +31,7 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * ``` * * Count from 0 to 9 every second for each click, but only allow 2 concurrent timers + * * ```ts * import { fromEvent, map, interval, take, mergeAll } from 'rxjs'; * diff --git a/src/internal/operators/mergeMap.ts b/src/internal/operators/mergeMap.ts index 71af090c54..e8ae950f5d 100644 --- a/src/internal/operators/mergeMap.ts +++ b/src/internal/operators/mergeMap.ts @@ -39,7 +39,9 @@ export function mergeMap>( * emitting the results of this merger. * * ## Example + * * Map and flatten each letter to an Observable ticking every 1 second + * * ```ts * import { of, mergeMap, interval, map } from 'rxjs'; * diff --git a/src/internal/operators/mergeMapTo.ts b/src/internal/operators/mergeMapTo.ts index 114218f304..f64d60c2d8 100644 --- a/src/internal/operators/mergeMapTo.ts +++ b/src/internal/operators/mergeMapTo.ts @@ -29,7 +29,9 @@ export function mergeMapTo>( * single Observable, which is the output Observable. * * ## Example + * * For each click event, start an interval Observable ticking every 1 second + * * ```ts * import { fromEvent, mergeMapTo, interval } from 'rxjs'; * diff --git a/src/internal/operators/mergeScan.ts b/src/internal/operators/mergeScan.ts index ac738095a5..c0987fb8be 100644 --- a/src/internal/operators/mergeScan.ts +++ b/src/internal/operators/mergeScan.ts @@ -35,7 +35,9 @@ import { mergeInternals } from './mergeInternals'; * at a time. * * ## Example + * * Count the number of click events + * * ```ts * import { fromEvent, mapTo, mergeScan, of } from 'rxjs'; * diff --git a/src/internal/operators/mergeWith.ts b/src/internal/operators/mergeWith.ts index 3a6d68628b..7cd5126502 100644 --- a/src/internal/operators/mergeWith.ts +++ b/src/internal/operators/mergeWith.ts @@ -12,10 +12,9 @@ import { merge } from './merge'; * * When any one source errors, the resulting observable will error. * + * ## Example * - * ### Example - * - * Joining all outputs from multiple user input event streams: + * Joining all outputs from multiple user input event streams * * ```ts * import { fromEvent, map, mergeWith } from 'rxjs'; diff --git a/src/internal/operators/min.ts b/src/internal/operators/min.ts index 4808f7a116..218256f91f 100644 --- a/src/internal/operators/min.ts +++ b/src/internal/operators/min.ts @@ -9,7 +9,9 @@ import { isFunction } from '../util/isFunction'; * ![](min.png) * * ## Examples + * * Get the minimal value of a series of numbers + * * ```ts * import { of, min } from 'rxjs'; * @@ -20,6 +22,7 @@ import { isFunction } from '../util/isFunction'; * ``` * * Use a comparer function to get the minimal item + * * ```ts * import { of, min } from 'rxjs'; * diff --git a/src/internal/operators/observeOn.ts b/src/internal/operators/observeOn.ts index 6701a75464..21867ae4db 100644 --- a/src/internal/operators/observeOn.ts +++ b/src/internal/operators/observeOn.ts @@ -32,7 +32,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * ## Example * - * Ensure values in subscribe are called just before browser repaint. + * Ensure values in subscribe are called just before browser repaint * * ```ts * import { interval, observeOn, animationFrameScheduler } from 'rxjs'; diff --git a/src/internal/operators/onErrorResumeNext.ts b/src/internal/operators/onErrorResumeNext.ts index adb60001ea..cfab3aa5a2 100644 --- a/src/internal/operators/onErrorResumeNext.ts +++ b/src/internal/operators/onErrorResumeNext.ts @@ -44,7 +44,9 @@ export function onErrorResumeNext( * * * ## Example + * * Subscribe to the next Observable after map fails + * * ```ts * import { of, onErrorResumeNext, map } from 'rxjs'; * diff --git a/src/internal/operators/pairwise.ts b/src/internal/operators/pairwise.ts index b64a33ddb8..3476b08250 100644 --- a/src/internal/operators/pairwise.ts +++ b/src/internal/operators/pairwise.ts @@ -18,7 +18,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * there is no previous value in that case. * * ## Example + * * On every click (starting from the second), emit the relative distance to the previous click + * * ```ts * import { fromEvent, pairwise, map } from 'rxjs'; * diff --git a/src/internal/operators/partition.ts b/src/internal/operators/partition.ts index 6fa9354cdd..7acef8405f 100644 --- a/src/internal/operators/partition.ts +++ b/src/internal/operators/partition.ts @@ -21,7 +21,9 @@ import { UnaryFunction } from '../types'; * behaves like {@link filter} with the predicate negated. * * ## Example + * * Partition click events into those on DIV elements and those elsewhere + * * ```ts * import { fromEvent } from 'rxjs'; * import { partition } from 'rxjs/operators'; diff --git a/src/internal/operators/pluck.ts b/src/internal/operators/pluck.ts index 3a08dba190..27dadb1332 100644 --- a/src/internal/operators/pluck.ts +++ b/src/internal/operators/pluck.ts @@ -58,7 +58,9 @@ export function pluck(...properties: string[]): OperatorFunction; * that value. * * ## Example + * * Map every click to the tagName of the clicked target element + * * ```ts * import { fromEvent, pluck } from 'rxjs'; * diff --git a/src/internal/operators/publish.ts b/src/internal/operators/publish.ts index 333b63cfd1..ad346ef300 100644 --- a/src/internal/operators/publish.ts +++ b/src/internal/operators/publish.ts @@ -42,8 +42,10 @@ export function publish>(selector: (shared: Ob * ![](publish.png) * * ## Examples - * Make source$ hot by applying publish operator, then merge each inner observable into a single one - * and subscribe. + * + * Make `source$` hot by applying `publish` operator, then merge each inner observable into a single one + * and subscribe + * * ```ts * import { zip, interval, of, map, publish, merge, tap } from 'rxjs'; * diff --git a/src/internal/operators/reduce.ts b/src/internal/operators/reduce.ts index 441a450eb3..43ba65b891 100644 --- a/src/internal/operators/reduce.ts +++ b/src/internal/operators/reduce.ts @@ -30,7 +30,9 @@ export function reduce(accumulator: (acc: A | S, value: V, index: n * value is specified, the first item of the source is used as the seed. * * ## Example + * * Count the number of click events that happened in 5 seconds + * * ```ts * import { fromEvent, takeUntil, interval, mapTo, reduce } from 'rxjs'; * diff --git a/src/internal/operators/repeat.ts b/src/internal/operators/repeat.ts index e68035d4c7..519174b926 100644 --- a/src/internal/operators/repeat.ts +++ b/src/internal/operators/repeat.ts @@ -17,7 +17,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Note: `repeat(0)` returns an empty observable and `repeat()` will repeat forever * * ## Example + * * Repeat a message stream + * * ```ts * import { of, repeat } from 'rxjs'; * @@ -32,6 +34,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ``` * * Repeat 3 values, 2 times + * * ```ts * import { interval, take, repeat } from 'rxjs'; * diff --git a/src/internal/operators/repeatWhen.ts b/src/internal/operators/repeatWhen.ts index 09e1cb253b..7962e585dc 100644 --- a/src/internal/operators/repeatWhen.ts +++ b/src/internal/operators/repeatWhen.ts @@ -15,7 +15,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ![](repeatWhen.png) * * ## Example + * * Repeat a message stream on click + * * ```ts * import { of, fromEvent, repeatWhen } from 'rxjs'; * diff --git a/src/internal/operators/retry.ts b/src/internal/operators/retry.ts index c2fe7b29e4..a619e486d0 100644 --- a/src/internal/operators/retry.ts +++ b/src/internal/operators/retry.ts @@ -39,6 +39,7 @@ export interface RetryConfig { * would be: [1, 2, 1, 2, 3, 4, 5, `complete`]. * * ## Example + * * ```ts * import { interval, mergeMap, throwError, of, retry } from 'rxjs'; * diff --git a/src/internal/operators/retryWhen.ts b/src/internal/operators/retryWhen.ts index 101384ecb0..11ddbac4fd 100644 --- a/src/internal/operators/retryWhen.ts +++ b/src/internal/operators/retryWhen.ts @@ -17,6 +17,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Retry an observable sequence on error based on custom criteria. * * ## Example + * * ```ts * import { interval, map, retryWhen, tap, delayWhen, timer } from 'rxjs'; * diff --git a/src/internal/operators/sample.ts b/src/internal/operators/sample.ts index abb472f109..bd90127531 100644 --- a/src/internal/operators/sample.ts +++ b/src/internal/operators/sample.ts @@ -20,7 +20,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * as the output Observable is subscribed. * * ## Example - * On every click, sample the most recent "seconds" timer + * + * On every click, sample the most recent `seconds` timer + * * ```ts * import { fromEvent, interval, sample } from 'rxjs'; * diff --git a/src/internal/operators/sampleTime.ts b/src/internal/operators/sampleTime.ts index 014939361d..f36ece8dca 100644 --- a/src/internal/operators/sampleTime.ts +++ b/src/internal/operators/sampleTime.ts @@ -20,7 +20,9 @@ import { interval } from '../observable/interval'; * the output Observable is subscribed. * * ## Example + * * Every second, emit the most recent click at most once + * * ```ts * import { fromEvent, sampleTime } from 'rxjs'; * diff --git a/src/internal/operators/scan.ts b/src/internal/operators/scan.ts index 44fa2932f4..8b548ab2ea 100644 --- a/src/internal/operators/scan.ts +++ b/src/internal/operators/scan.ts @@ -28,7 +28,7 @@ export function scan(accumulator: (acc: A | S, value: V, index: number) * 3. Emit `state`. * 4. Next value arrives, let `value = nextValue`, go to 2. * - * ## Example + * ## Examples * * An average of previous numbers. This example shows how * not providing a `seed` can prime the stream with the @@ -50,10 +50,8 @@ export function scan(accumulator: (acc: A | S, value: V, index: number) * .subscribe(console.log); * ``` * - * ## Example - * * The Fibonacci sequence. This example shows how you can use - * a seed to prime accumulation process. Also... you know... Fibinacci. + * a seed to prime accumulation process. Also... you know... Fibonacci. * So important to like, computers and stuff that its whiteboarded * in job interviews. Now you can show them the Rx version! (Please don't, haha) * diff --git a/src/internal/operators/sequenceEqual.ts b/src/internal/operators/sequenceEqual.ts index 1e43a78a6c..a34a4bcc71 100644 --- a/src/internal/operators/sequenceEqual.ts +++ b/src/internal/operators/sequenceEqual.ts @@ -21,7 +21,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * completes or emits after the other completes, the returned observable will never complete. * * ## Example - * figure out if the Konami code matches + * + * Figure out if the Konami code matches + * * ```ts * import { from, fromEvent, map, bufferCount, mergeMap, sequenceEqual } from 'rxjs'; * diff --git a/src/internal/operators/share.ts b/src/internal/operators/share.ts index b1acc2a04c..dc63b9d2c8 100644 --- a/src/internal/operators/share.ts +++ b/src/internal/operators/share.ts @@ -68,7 +68,9 @@ export function share(options: ShareConfig): MonoTypeOperatorFunction; * ![](share.png) * * ## Example - * Generate new multicast Observable from the source Observable value + * + * Generate new multicast Observable from the `source` Observable value + * * ```ts * import { interval, map, share } from 'rxjs'; * @@ -101,6 +103,7 @@ export function share(options: ShareConfig): MonoTypeOperatorFunction; * ``` * * ## Example with notifier factory: Delayed reset + * * ```ts * import { interval, take, share, timer } from 'rxjs'; * diff --git a/src/internal/operators/shareReplay.ts b/src/internal/operators/shareReplay.ts index 229218eeb2..8f20e922d8 100644 --- a/src/internal/operators/shareReplay.ts +++ b/src/internal/operators/shareReplay.ts @@ -38,7 +38,10 @@ export function shareReplay(bufferSize?: number, windowTime?: number, schedul * If `refCount` is false on the other hand, the source will not be unsubscribed meaning that the inner * `ReplaySubject` will still be subscribed to the source (and potentially run for ever). * - * ## Example + * ## Examples + * + * Example with a third subscriber coming late to the party + * * ```ts * import { interval, take, shareReplay } from 'rxjs'; * @@ -52,7 +55,8 @@ export function shareReplay(bufferSize?: number, windowTime?: number, schedul * * ``` * - * ## Example for refCount usage + * Example for `refCount` usage + * * ```ts * import { Observable, defer, tap, finalize, interval, shareReplay, take } from 'rxjs'; * diff --git a/src/internal/operators/single.ts b/src/internal/operators/single.ts index 0537275ddc..7f13eb2d6f 100644 --- a/src/internal/operators/single.ts +++ b/src/internal/operators/single.ts @@ -28,7 +28,7 @@ export function single(predicate?: (value: T, index: number, source: Observab * * ## Example * - * Expect only name beginning with 'B': + * Expect only `name` beginning with `'B'` * * ```ts * import { of, single } from 'rxjs'; diff --git a/src/internal/operators/skip.ts b/src/internal/operators/skip.ts index 1d4e958607..928ca760d3 100644 --- a/src/internal/operators/skip.ts +++ b/src/internal/operators/skip.ts @@ -10,7 +10,9 @@ import { filter } from './filter'; * an error if skip count is equal or more than the actual number of emits and source raises an error. * * ## Example + * * Skip the values before the emission + * * ```ts * import { interval, skip } from 'rxjs'; * diff --git a/src/internal/operators/skipUntil.ts b/src/internal/operators/skipUntil.ts index c220b90fcf..aded4a26f4 100644 --- a/src/internal/operators/skipUntil.ts +++ b/src/internal/operators/skipUntil.ts @@ -20,7 +20,7 @@ import { noop } from '../util/noop'; * * ## Example * - * In the following example, all emitted values ​​of the interval observable are skipped until the user clicks anywhere within the page. + * In the following example, all emitted values of the interval observable are skipped until the user clicks anywhere within the page * * ```ts * import { interval, fromEvent, skipUntil } from 'rxjs'; diff --git a/src/internal/operators/skipWhile.ts b/src/internal/operators/skipWhile.ts index 02a17d0598..5973bce763 100644 --- a/src/internal/operators/skipWhile.ts +++ b/src/internal/operators/skipWhile.ts @@ -16,7 +16,9 @@ export function skipWhile(predicate: (value: T, index: number) => boolean): M * It can also be skipped using index. Once the predicate is true, it will not be called again. * * ## Example - * Using Value: Skip some super heroes + * + * Skip some super heroes + * * ```ts * import { from, skipWhile } from 'rxjs'; * @@ -26,7 +28,9 @@ export function skipWhile(predicate: (value: T, index: number) => boolean): M * // output: SuperGirl, Black Canary * example.subscribe((femaleHero) => console.log(femaleHero)); * ``` - * Using Index: Skip value from the array until index 5 + * + * Skip values from the array until index 5 + * * ```ts * import { from, skipWhile } from 'rxjs'; * diff --git a/src/internal/operators/switchAll.ts b/src/internal/operators/switchAll.ts index 1a5efe0cac..c20ec4274b 100644 --- a/src/internal/operators/switchAll.ts +++ b/src/internal/operators/switchAll.ts @@ -19,8 +19,9 @@ import { identity } from '../util/identity'; * if there are any. * * ## Examples + * * Spawn a new interval observable for each click event, but for every new - * click, cancel the previous interval and subscribe to the new one. + * click, cancel the previous interval and subscribe to the new one * * ```ts * import { fromEvent, tap, map, interval, switchAll } from 'rxjs'; diff --git a/src/internal/operators/switchMap.ts b/src/internal/operators/switchMap.ts index 1b7efc8c5c..c59748e6e1 100644 --- a/src/internal/operators/switchMap.ts +++ b/src/internal/operators/switchMap.ts @@ -39,7 +39,9 @@ export function switchMap>( * subsequent inner Observables. * * ## Example + * * Generate new Observable according to source Observable values + * * ```ts * import { of, switchMap } from 'rxjs'; * @@ -56,6 +58,7 @@ export function switchMap>( * ``` * * Restart an interval Observable on every click event + * * ```ts * import { fromEvent, switchMap, interval } from 'rxjs'; * diff --git a/src/internal/operators/switchMapTo.ts b/src/internal/operators/switchMapTo.ts index e4bf9a50b1..a3ff875fe9 100644 --- a/src/internal/operators/switchMapTo.ts +++ b/src/internal/operators/switchMapTo.ts @@ -32,7 +32,9 @@ export function switchMapTo>( * `innerObservable`. * * ## Example - * Rerun an interval Observable on every click event + * + * Restart an interval Observable on every click event + * * ```ts * import { fromEvent, switchMapTo, interval } from 'rxjs'; * diff --git a/src/internal/operators/take.ts b/src/internal/operators/take.ts index 9464add731..35e5181b24 100644 --- a/src/internal/operators/take.ts +++ b/src/internal/operators/take.ts @@ -17,7 +17,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * source completes. * * ## Example + * * Take the first 5 seconds of an infinite 1-second interval Observable + * * ```ts * import { interval, take } from 'rxjs'; * diff --git a/src/internal/operators/takeUntil.ts b/src/internal/operators/takeUntil.ts index 5a0984fce7..7e37cc52c2 100644 --- a/src/internal/operators/takeUntil.ts +++ b/src/internal/operators/takeUntil.ts @@ -20,7 +20,9 @@ import { noop } from '../util/noop'; * then `takeUntil` will pass all values. * * ## Example + * * Tick every second until the first click happens + * * ```ts * import { interval, fromEvent, takeUntil } from 'rxjs'; * diff --git a/src/internal/operators/takeWhile.ts b/src/internal/operators/takeWhile.ts index 8099c1a369..5a06e2af30 100644 --- a/src/internal/operators/takeWhile.ts +++ b/src/internal/operators/takeWhile.ts @@ -30,7 +30,9 @@ export function takeWhile(predicate: (value: T, index: number) => boolean, in * Observable and completes the output Observable. * * ## Example + * * Emit click events only while the clientX property is greater than 200 + * * ```ts * import { fromEvent, takeWhile } from 'rxjs'; * diff --git a/src/internal/operators/tap.ts b/src/internal/operators/tap.ts index 67a7cc859d..f4a9143d51 100644 --- a/src/internal/operators/tap.ts +++ b/src/internal/operators/tap.ts @@ -43,9 +43,10 @@ export function tap( * in your observable `pipe`, log out the notifications as they are emitted by the source returned by the previous * operation. * - * ## Example + * ## Examples + * * Check a random number before it is handled. Below is an observable that will use a random number between 0 and 1, - * and emit "big" or "small" depending on the size of that number. But we wanted to log what the original number + * and emit `'big'` or `'small'` depending on the size of that number. But we wanted to log what the original number * was, so we have added a `tap(console.log)`. * * ```ts @@ -57,7 +58,6 @@ export function tap( * ).subscribe(console.log); * ``` * - * ## Example * Using `tap` to analyze a value and force an error. Below is an observable where in our system we only * want to emit numbers 3 or less we get from another source. We can force our observable to error * using `tap`. @@ -77,11 +77,10 @@ export function tap( * .subscribe(console.log); * ``` * - * ## Example * We want to know when an observable completes before moving on to the next observable. The system - * below will emit a random series of `"X"` characters from 3 different observables in sequence. The + * below will emit a random series of `'X'` characters from 3 different observables in sequence. The * only way we know when one observable completes and moves to the next one, in this case, is because - * we have added a `tap` with the side-effect of logging to console. + * we have added a `tap` with the side effect of logging to console. * * ```ts * import { of, concatMap, interval, take, map, tap } from 'rxjs'; diff --git a/src/internal/operators/throttle.ts b/src/internal/operators/throttle.ts index 0d65b2e6cd..978727c006 100644 --- a/src/internal/operators/throttle.ts +++ b/src/internal/operators/throttle.ts @@ -35,7 +35,9 @@ export const defaultThrottleConfig: ThrottleConfig = { * next source value. * * ## Example + * * Emit clicks at a rate of at most one click per second + * * ```ts * import { fromEvent, throttle, interval } from 'rxjs'; * diff --git a/src/internal/operators/throttleTime.ts b/src/internal/operators/throttleTime.ts index cb27cf5278..95ef198899 100644 --- a/src/internal/operators/throttleTime.ts +++ b/src/internal/operators/throttleTime.ts @@ -23,9 +23,10 @@ import { timer } from '../observable/timer'; * * ## Examples * - * #### Limit click rate + * ### Limit click rate * * Emit clicks at a rate of at most one click per second + * * ```ts * import { fromEvent, throttleTime } from 'rxjs'; * @@ -34,7 +35,7 @@ import { timer } from '../observable/timer'; * result.subscribe(x => console.log(x)); * ``` * - * #### Double Click + * ### Double Click * * The following example only emits clicks which happen within a subsequent * delay of 400ms of the previous click. This for example can emulate a double diff --git a/src/internal/operators/throwIfEmpty.ts b/src/internal/operators/throwIfEmpty.ts index 1c383be79e..6d41bfbead 100644 --- a/src/internal/operators/throwIfEmpty.ts +++ b/src/internal/operators/throwIfEmpty.ts @@ -11,6 +11,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ![](throwIfEmpty.png) * * ## Example + * + * Throw an error if the document wasn't clicked within 1 second + * * ```ts * import { fromEvent, takeUntil, timer, throwIfEmpty } from 'rxjs'; * diff --git a/src/internal/operators/timeInterval.ts b/src/internal/operators/timeInterval.ts index 7823128633..b4eaa6947e 100644 --- a/src/internal/operators/timeInterval.ts +++ b/src/internal/operators/timeInterval.ts @@ -19,7 +19,8 @@ import { map } from './map'; * * ![](timeInterval.png) * - * ## Examples + * ## Example + * * Emit interval between current value with the last value * * ```ts diff --git a/src/internal/operators/timeout.ts b/src/internal/operators/timeout.ts index a7309f3c29..fce12d9cb8 100644 --- a/src/internal/operators/timeout.ts +++ b/src/internal/operators/timeout.ts @@ -116,7 +116,7 @@ export const TimeoutError: TimeoutErrorCtor = createErrorClass( * `first` is _not_ provided, the value from `each` will be used to check timeout conditions for the arrival of the first * value and all subsequent values. If `first` _is_ provided, `each` will only be use to check all values after the first. * - * ### Example + * ## Examples * * Emit a custom error if there is too much time between values * @@ -143,8 +143,6 @@ export const TimeoutError: TimeoutErrorCtor = createErrorClass( * }) * ``` * - * ### Example - * * Switch to a faster observable if your source is slow. * * ```ts @@ -198,8 +196,7 @@ export function timeout, M = unknown>( * In this case, you would check the error for `instanceof TimeoutError` to validate that the error was indeed from `timeout`, and * not from some other source. If it's not from `timeout`, you should probably rethrow it if you're in a `catchError`. * - * - * ### Example + * ## Examples * * Emit a {@link TimeoutError} if the first value, and _only_ the first value, does not arrive within 5 seconds * @@ -215,8 +212,6 @@ export function timeout, M = unknown>( * .subscribe(console.log); * ``` * - * ### Example - * * Emit a {@link TimeoutError} if the source waits longer than 5 seconds between any two values or the first value * and subscription. * @@ -236,9 +231,7 @@ export function timeout, M = unknown>( * .subscribe(console.log); * ``` * - * ### Example - * - * Emit a {@link TimeoutError} if the the source does not emit before 7 seconds, _or_ if the source waits longer than + * Emit a {@link TimeoutError} if the source does not emit before 7 seconds, _or_ if the source waits longer than * 5 seconds between any two values after the first. * * ```ts diff --git a/src/internal/operators/timeoutWith.ts b/src/internal/operators/timeoutWith.ts index d3ded16d08..e3c0030748 100644 --- a/src/internal/operators/timeoutWith.ts +++ b/src/internal/operators/timeoutWith.ts @@ -32,7 +32,7 @@ export function timeoutWith(dueBy: Date, switchTo: ObservableInput, sch * - You want to emit a custom error rather than the {@link TimeoutError} emitted * by the default usage of {@link timeout}. * - * ## Example + * ## Examples * * Fallback to a faster observable * @@ -48,8 +48,6 @@ export function timeoutWith(dueBy: Date, switchTo: ObservableInput, sch * .subscribe(console.log) * ``` * - * ### Example - * * Emit your own custom timeout error * * ```ts diff --git a/src/internal/operators/timestamp.ts b/src/internal/operators/timestamp.ts index 5a8a47538f..954ca48db5 100644 --- a/src/internal/operators/timestamp.ts +++ b/src/internal/operators/timestamp.ts @@ -15,7 +15,7 @@ import { map } from './map'; * * ## Example * - * In this example there is a timestamp attached to the documents click event. + * In this example there is a timestamp attached to the document's click events * * ```ts * import { fromEvent, timestamp } from 'rxjs'; @@ -35,5 +35,5 @@ import { map } from './map'; * each item emitted by the source Observable indicating when it was emitted. */ export function timestamp(timestampProvider: TimestampProvider = dateTimestampProvider): OperatorFunction> { - return map((value: T) => ({ value, timestamp: timestampProvider.now()})); + return map((value: T) => ({ value, timestamp: timestampProvider.now() })); } diff --git a/src/internal/operators/toArray.ts b/src/internal/operators/toArray.ts index 36623b55d2..d2f26c2063 100644 --- a/src/internal/operators/toArray.ts +++ b/src/internal/operators/toArray.ts @@ -15,7 +15,8 @@ const arrReducer = (arr: any[], value: any) => (arr.push(value), arr); * the array containing all emissions. When the source Observable errors no * array will be emitted. * - * ## Example + * ## Example + * * ```ts * import { interval, take, toArray } from 'rxjs'; * @@ -38,6 +39,6 @@ export function toArray(): OperatorFunction { // reducer process, we have to escapulate the creation of the initial // array within this `operate` function. return operate((source, subscriber) => { - reduce(arrReducer, [] as T[])(source).subscribe(subscriber) + reduce(arrReducer, [] as T[])(source).subscribe(subscriber); }); } diff --git a/src/internal/operators/window.ts b/src/internal/operators/window.ts index 0d047f61dc..535f806ad6 100644 --- a/src/internal/operators/window.ts +++ b/src/internal/operators/window.ts @@ -21,7 +21,9 @@ import { noop } from '../util/noop'; * Observable, the output is a higher-order Observable. * * ## Example + * * In every window of 1 second each, emit at most 2 click events + * * ```ts * import { fromEvent, interval, window, map, take, mergeAll } from 'rxjs'; * diff --git a/src/internal/operators/windowCount.ts b/src/internal/operators/windowCount.ts index 778ec43cb9..9f2aa886f6 100644 --- a/src/internal/operators/windowCount.ts +++ b/src/internal/operators/windowCount.ts @@ -23,7 +23,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * with size `windowSize`. * * ## Examples + * * Ignore every 3rd click event, starting from the first one + * * ```ts * import { fromEvent, windowCount, map, skip, mergeAll } from 'rxjs'; * @@ -37,6 +39,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ``` * * Ignore every 3rd click event, starting from the third one + * * ```ts * import { fromEvent, windowCount, mergeAll } from 'rxjs'; * diff --git a/src/internal/operators/windowTime.ts b/src/internal/operators/windowTime.ts index 24ded37d0c..ae7ee14b41 100644 --- a/src/internal/operators/windowTime.ts +++ b/src/internal/operators/windowTime.ts @@ -44,7 +44,9 @@ export function windowTime( * `windowTimeSpan` and `windowCreationInterval` arguments. * * ## Examples + * * In every window of 1 second each, emit at most 2 click events + * * ```ts * import { fromEvent, windowTime, map, take, mergeAll } from 'rxjs'; * @@ -58,6 +60,7 @@ export function windowTime( * ``` * * Every 5 seconds start a window 1 second long, and emit at most 2 click events per window + * * ```ts * import { fromEvent, windowTime, map, take, mergeAll } from 'rxjs'; * @@ -70,7 +73,8 @@ export function windowTime( * result.subscribe(x => console.log(x)); * ``` * - * Same as example above but with maxWindowCount instead of take + * Same as example above but with `maxWindowCount` instead of `take` + * * ```ts * import { fromEvent, windowTime, mergeAll } from 'rxjs'; * diff --git a/src/internal/operators/windowToggle.ts b/src/internal/operators/windowToggle.ts index 05f2f30984..eb81cb5124 100644 --- a/src/internal/operators/windowToggle.ts +++ b/src/internal/operators/windowToggle.ts @@ -25,7 +25,9 @@ import { arrRemove } from '../util/arrRemove'; * `closingSelector` emits an item. * * ## Example + * * Every other second, emit the click events from the next 500ms + * * ```ts * import { fromEvent, interval, windowToggle, EMPTY, mergeAll } from 'rxjs'; * diff --git a/src/internal/operators/windowWhen.ts b/src/internal/operators/windowWhen.ts index 3cf8ae35ef..a9f20aa600 100644 --- a/src/internal/operators/windowWhen.ts +++ b/src/internal/operators/windowWhen.ts @@ -23,7 +23,9 @@ import { innerFrom } from '../observable/innerFrom'; * window is opened immediately when subscribing to the output Observable. * * ## Example + * * Emit only the first two clicks events in every window of [1-5] random seconds + * * ```ts * import { fromEvent, windowWhen, interval, map, take, mergeAll } from 'rxjs'; * diff --git a/src/internal/operators/withLatestFrom.ts b/src/internal/operators/withLatestFrom.ts index 97acab7c2b..763410478d 100644 --- a/src/internal/operators/withLatestFrom.ts +++ b/src/internal/operators/withLatestFrom.ts @@ -30,7 +30,9 @@ export function withLatestFrom( * emit at least one value before the output Observable will emit a value. * * ## Example + * * On every click event, emit an array with the latest timer event plus the click event + * * ```ts * import { fromEvent, interval, withLatestFrom } from 'rxjs'; * From 0ae39ab8bf88ab2659132735a7530ddd58a89c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Tue, 7 Dec 2021 11:28:30 +0100 Subject: [PATCH 06/11] docs: fix links and @see links --- src/internal/observable/generate.ts | 1 - src/internal/observable/never.ts | 2 +- src/internal/observable/range.ts | 2 +- src/internal/observable/timer.ts | 2 +- src/internal/operators/debounce.ts | 2 +- src/internal/operators/debounceTime.ts | 1 - src/internal/operators/endWith.ts | 8 ++++---- src/internal/operators/isEmpty.ts | 2 +- src/internal/operators/mergeWith.ts | 3 +++ src/internal/operators/publish.ts | 4 ++++ src/internal/operators/retry.ts | 2 ++ src/internal/operators/retryWhen.ts | 2 ++ src/internal/operators/share.ts | 3 +-- src/internal/operators/skipUntil.ts | 5 +++++ src/internal/operators/timeout.ts | 6 ++++-- src/internal/operators/timeoutWith.ts | 3 +++ 16 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/internal/observable/generate.ts b/src/internal/observable/generate.ts index 767d1fd21c..032f69bfa3 100644 --- a/src/internal/observable/generate.ts +++ b/src/internal/observable/generate.ts @@ -229,7 +229,6 @@ export function generate( * ``` * * @see {@link from} - * @see {@link index/Observable.create} * * @param {S} initialState Initial state. * @param {function (state: S): boolean} condition Condition to terminate generation (upon returning false). diff --git a/src/internal/observable/never.ts b/src/internal/observable/never.ts index c8177a0716..b7b29b106c 100644 --- a/src/internal/observable/never.ts +++ b/src/internal/observable/never.ts @@ -28,7 +28,7 @@ import { noop } from '../util/noop'; * ``` * * @see {@link Observable} - * @see {@link index/EMPTY} + * @see {@link EMPTY} * @see {@link of} * @see {@link throwError} */ diff --git a/src/internal/observable/range.ts b/src/internal/observable/range.ts index df205e9349..0ac22bbb7c 100644 --- a/src/internal/observable/range.ts +++ b/src/internal/observable/range.ts @@ -44,7 +44,7 @@ export function range(start: number, count: number | undefined, scheduler: Sched * ``` * * @see {@link timer} - * @see {@link index/interval} + * @see {@link interval} * * @param {number} [start=0] The value of the first integer in the sequence. * @param {number} count The number of sequential integers to generate. diff --git a/src/internal/observable/timer.ts b/src/internal/observable/timer.ts index 94d93fdc26..40e5fbcb09 100644 --- a/src/internal/observable/timer.ts +++ b/src/internal/observable/timer.ts @@ -95,7 +95,7 @@ export function timer(due: number | Date, scheduler?: SchedulerLike): Observable * * ### Start an interval that starts right away * - * Since {@link index/interval} waits for the passed delay before starting, + * Since {@link interval} waits for the passed delay before starting, * sometimes that's not ideal. You may want to start an interval immediately. * `timer` works well for this. Here we have both side-by-side so you can * see them in comparison. diff --git a/src/internal/operators/debounce.ts b/src/internal/operators/debounce.ts index 191c546376..2ffac323de 100644 --- a/src/internal/operators/debounce.ts +++ b/src/internal/operators/debounce.ts @@ -49,7 +49,7 @@ import { innerFrom } from '../observable/innerFrom'; * * @see {@link audit} * @see {@link auditTime} - * @see {@link debounce} + * @see {@link debounceTime} * @see {@link delay} * @see {@link sample} * @see {@link sampleTime} diff --git a/src/internal/operators/debounceTime.ts b/src/internal/operators/debounceTime.ts index 6b8afb2dae..40f385caad 100644 --- a/src/internal/operators/debounceTime.ts +++ b/src/internal/operators/debounceTime.ts @@ -46,7 +46,6 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * @see {@link audit} * @see {@link auditTime} * @see {@link debounce} - * @see {@link debounceTime} * @see {@link sample} * @see {@link sampleTime} * @see {@link throttle} diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index e3a315f40a..0ce4984610 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -54,14 +54,14 @@ export function endWith(...values: A): OperatorFun * // "interval ended by click" * ``` * + * @see {@link startWith} + * @see {@link concat} + * @see {@link takeUntil} + * * @param values Items you want the modified Observable to emit last. * @return A function that returns an Observable that emits all values from the * source, then synchronously emits the provided value(s) immediately after the * source completes. - * - * @see {@link startWith} - * @see {@link concat} - * @see {@link takeUntil} */ export function endWith(...values: Array): MonoTypeOperatorFunction { return (source: Observable) => concat(source, of(...values)) as Observable; diff --git a/src/internal/operators/isEmpty.ts b/src/internal/operators/isEmpty.ts index 1a8b82c381..5947b2b702 100644 --- a/src/internal/operators/isEmpty.ts +++ b/src/internal/operators/isEmpty.ts @@ -58,7 +58,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ``` * * @see {@link count} - * @see {@link index/EMPTY} + * @see {@link EMPTY} * * @return A function that returns an Observable that emits boolean value * indicating whether the source Observable was empty or not. diff --git a/src/internal/operators/mergeWith.ts b/src/internal/operators/mergeWith.ts index 7cd5126502..776e980b10 100644 --- a/src/internal/operators/mergeWith.ts +++ b/src/internal/operators/mergeWith.ts @@ -36,6 +36,9 @@ import { merge } from './merge'; * // "click" * // "dblclick" * ``` + * + * @see {@link merge} + * * @param otherSources the sources to combine the current source with. * @return A function that returns an Observable that merges the values from * all given Observables. diff --git a/src/internal/operators/publish.ts b/src/internal/operators/publish.ts index ad346ef300..b6f6b495ed 100644 --- a/src/internal/operators/publish.ts +++ b/src/internal/operators/publish.ts @@ -75,6 +75,10 @@ export function publish>(selector: (shared: Ob * // Stream 3: 9 * ``` * + * @see {@link publishLast} + * @see {@link publishReplay} + * @see {@link publishBehavior} + * * @param {Function} [selector] - Optional selector function which can use the multicasted source sequence as many times * as needed, without causing multiple subscriptions to the source sequence. * Subscribers to the given source will receive all notifications of the source from the time of the subscription on. diff --git a/src/internal/operators/retry.ts b/src/internal/operators/retry.ts index a619e486d0..5dd3884781 100644 --- a/src/internal/operators/retry.ts +++ b/src/internal/operators/retry.ts @@ -67,6 +67,8 @@ export interface RetryConfig { * // "Error!: Retried 2 times then quit!" * ``` * + * @see {@link retryWhen} + * * @param count - Number of retry attempts before failing. * @param resetOnSuccess - When set to `true` every successful emission will reset the error count * @return A function that returns an Observable that will resubscribe to the diff --git a/src/internal/operators/retryWhen.ts b/src/internal/operators/retryWhen.ts index 11ddbac4fd..a08abee139 100644 --- a/src/internal/operators/retryWhen.ts +++ b/src/internal/operators/retryWhen.ts @@ -53,6 +53,8 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * // --Wait 5 seconds then repeat * ``` * + * @see {@link retry} + * * @param {function(errors: Observable): Observable} notifier - Receives an Observable of notifications with which a * user can `complete` or `error`, aborting the retry. * @return A function that returns an Observable that mirrors the source diff --git a/src/internal/operators/share.ts b/src/internal/operators/share.ts index dc63b9d2c8..9b75a8dbcf 100644 --- a/src/internal/operators/share.ts +++ b/src/internal/operators/share.ts @@ -129,8 +129,7 @@ export function share(options: ShareConfig): MonoTypeOperatorFunction; * // subscription 3: 2 * ``` * - * @see {@link api/index/function/interval} - * @see {@link map} + * @see {@link shareReplay} * * @return A function that returns an Observable that mirrors the source. */ diff --git a/src/internal/operators/skipUntil.ts b/src/internal/operators/skipUntil.ts index aded4a26f4..0defc487f6 100644 --- a/src/internal/operators/skipUntil.ts +++ b/src/internal/operators/skipUntil.ts @@ -36,6 +36,11 @@ import { noop } from '../util/noop'; * const subscribe = emitAfterClick.subscribe(value => console.log(value)); * ``` * + * @see {@link last} + * @see {@link skip} + * @see {@link skipWhile} + * @see {@link skipLast} + * * @param {Observable} notifier - The second Observable that has to emit an item before the source Observable's elements begin to * be mirrored by the resulting Observable. * @return A function that returns an Observable that skips items from the diff --git a/src/internal/operators/timeout.ts b/src/internal/operators/timeout.ts index fce12d9cb8..41b2d7a2b9 100644 --- a/src/internal/operators/timeout.ts +++ b/src/internal/operators/timeout.ts @@ -74,14 +74,14 @@ export interface TimeoutErrorCtor { } /** - * An error thrown by the {@link operators/timeout} operator. + * An error thrown by the {@link timeout} operator. * * Provided so users can use as a type and do quality comparisons. * We recommend you do not subclass this or create instances of this class directly. * If you have need of a error representing a timeout, you should * create your own error class and use that. * - * @see {@link operators/timeout} + * @see {@link timeout} * * @class TimeoutError */ @@ -288,6 +288,8 @@ export function timeout(each: number, scheduler?: SchedulerLike): MonoTypeOpe * * ![](timeout.png) * + * @see {@link timeoutWith} + * * @return A function that returns an Observable that mirrors behaviour of the * source Observable, unless timeout happens when it throws an error. */ diff --git a/src/internal/operators/timeoutWith.ts b/src/internal/operators/timeoutWith.ts index e3c0030748..e1cc739f3b 100644 --- a/src/internal/operators/timeoutWith.ts +++ b/src/internal/operators/timeoutWith.ts @@ -69,6 +69,9 @@ export function timeoutWith(dueBy: Date, switchTo: ObservableInput, sch * error: console.error * }) * ``` + * + * @see {@link timeout} + * * @param waitFor The time allowed between values from the source before timeout is triggered. * @param switchTo The observable to switch to when timeout occurs. * @param scheduler The scheduler to use with time-related operations within this operator. Defaults to {@link asyncScheduler} From d95fed477d265be802a8894b22bc5eae818606c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Tue, 7 Dec 2021 13:37:15 +0100 Subject: [PATCH 07/11] docs: unify examples Use single quotes, fix whitespace issues, delete trailing commas, remove extra parenthesis, convert to arrow functions, update parameters to non-deprecated version of subscribe, fix grammar. --- src/internal/Observable.ts | 56 +++++++------- src/internal/ajax/ajax.ts | 31 ++++++-- src/internal/firstValueFrom.ts | 4 +- src/internal/lastValueFrom.ts | 4 +- src/internal/observable/combineLatest.ts | 12 +-- src/internal/observable/concat.ts | 17 ++--- src/internal/observable/defer.ts | 2 +- .../observable/dom/WebSocketSubject.ts | 60 +++++++-------- .../observable/dom/animationFrames.ts | 12 +-- src/internal/observable/dom/fetch.ts | 40 +++++----- src/internal/observable/dom/webSocket.ts | 36 ++++----- src/internal/observable/forkJoin.ts | 8 +- src/internal/observable/from.ts | 4 +- src/internal/observable/fromEventPattern.ts | 6 +- src/internal/observable/generate.ts | 24 +++--- src/internal/observable/iif.ts | 36 ++++----- src/internal/observable/merge.ts | 1 + src/internal/observable/never.ts | 12 +-- src/internal/observable/of.ts | 20 ++--- src/internal/observable/onErrorResumeNext.ts | 34 +++++---- src/internal/observable/pairs.ts | 10 +-- src/internal/observable/partition.ts | 2 +- src/internal/observable/range.ts | 6 +- src/internal/observable/throwError.ts | 52 ++++++------- src/internal/observable/timer.ts | 4 +- src/internal/observable/zip.ts | 7 +- src/internal/operators/audit.ts | 1 + src/internal/operators/bufferToggle.ts | 1 - src/internal/operators/bufferWhen.ts | 7 +- src/internal/operators/catchError.ts | 35 +++++---- src/internal/operators/combineLatestAll.ts | 10 +-- src/internal/operators/concatAll.ts | 2 +- src/internal/operators/concatMapTo.ts | 2 +- src/internal/operators/connect.ts | 44 +++++------ src/internal/operators/count.ts | 2 +- src/internal/operators/debounce.ts | 4 +- src/internal/operators/delayWhen.ts | 2 +- src/internal/operators/dematerialize.ts | 5 +- src/internal/operators/distinct.ts | 26 +++---- .../operators/distinctUntilChanged.ts | 29 ++++---- .../operators/distinctUntilKeyChanged.ts | 46 +++++------- src/internal/operators/endWith.ts | 14 ++-- src/internal/operators/every.ts | 7 +- src/internal/operators/exhaustAll.ts | 6 +- src/internal/operators/exhaustMap.ts | 2 +- src/internal/operators/expand.ts | 2 +- src/internal/operators/filter.ts | 4 +- src/internal/operators/finalize.ts | 20 ++--- src/internal/operators/find.ts | 2 +- src/internal/operators/findIndex.ts | 2 +- src/internal/operators/first.ts | 4 +- src/internal/operators/groupBy.ts | 35 ++++----- src/internal/operators/ignoreElements.ts | 19 ++--- src/internal/operators/isEmpty.ts | 6 +- src/internal/operators/last.ts | 18 +++-- src/internal/operators/map.ts | 3 +- src/internal/operators/mapTo.ts | 1 + src/internal/operators/materialize.ts | 11 ++- src/internal/operators/max.ts | 29 ++++---- src/internal/operators/mergeAll.ts | 6 +- src/internal/operators/mergeMap.ts | 5 +- src/internal/operators/mergeMapTo.ts | 1 + src/internal/operators/mergeScan.ts | 5 +- src/internal/operators/mergeWith.ts | 23 +++--- src/internal/operators/min.ts | 30 ++++---- src/internal/operators/observeOn.ts | 9 +-- src/internal/operators/onErrorResumeNext.ts | 32 ++++---- src/internal/operators/pairwise.ts | 15 ++-- src/internal/operators/partition.ts | 9 ++- src/internal/operators/pluck.ts | 1 + src/internal/operators/publish.ts | 7 +- src/internal/operators/publishLast.ts | 46 ++++++------ src/internal/operators/reduce.ts | 7 +- src/internal/operators/refCount.ts | 6 +- src/internal/operators/repeat.ts | 16 ++-- src/internal/operators/repeatWhen.ts | 6 +- src/internal/operators/retry.ts | 26 +++---- src/internal/operators/retryWhen.ts | 32 ++++---- src/internal/operators/sample.ts | 1 + src/internal/operators/sampleTime.ts | 1 + src/internal/operators/scan.ts | 9 +-- src/internal/operators/sequenceEqual.ts | 6 +- src/internal/operators/share.ts | 7 +- src/internal/operators/shareReplay.ts | 34 ++++++++- src/internal/operators/single.ts | 25 +++---- src/internal/operators/skip.ts | 11 +-- src/internal/operators/skipUntil.ts | 4 +- src/internal/operators/skipWhile.ts | 6 +- src/internal/operators/startWith.ts | 4 +- src/internal/operators/subscribeOn.ts | 2 +- src/internal/operators/switchAll.ts | 9 +-- src/internal/operators/switchMap.ts | 10 ++- src/internal/operators/takeWhile.ts | 2 +- src/internal/operators/tap.ts | 26 +++---- src/internal/operators/throttle.ts | 3 +- src/internal/operators/throttleTime.ts | 9 ++- src/internal/operators/throwIfEmpty.ts | 12 +-- src/internal/operators/timeInterval.ts | 21 ++---- src/internal/operators/timeout.ts | 73 ++++++++++--------- src/internal/operators/timeoutWith.ts | 26 +++---- src/internal/operators/timestamp.ts | 4 +- src/internal/operators/toArray.ts | 2 +- src/internal/operators/window.ts | 17 +++-- src/internal/operators/windowCount.ts | 2 +- src/internal/operators/windowTime.ts | 13 ++-- src/internal/operators/windowWhen.ts | 4 +- 106 files changed, 785 insertions(+), 741 deletions(-) diff --git a/src/internal/Observable.ts b/src/internal/Observable.ts index 3fae2dc938..6b3ca75b78 100644 --- a/src/internal/Observable.ts +++ b/src/internal/Observable.ts @@ -1,6 +1,3 @@ -/** - * @prettier - */ import { Operator } from './Operator'; import { SafeSubscriber, Subscriber } from './Subscriber'; import { isSubscription, Subscription } from './Subscription'; @@ -150,10 +147,10 @@ export class Observable implements Subscribable { * .subscribe(sumObserver); * * // Logs: - * // "Adding: 1" - * // "Adding: 2" - * // "Adding: 3" - * // "Sum equals: 6" + * // 'Adding: 1' + * // 'Adding: 2' + * // 'Adding: 3' + * // 'Sum equals: 6' * ``` * * Subscribe with functions ({@link deprecations/subscribe-arguments deprecated}) @@ -173,10 +170,10 @@ export class Observable implements Subscribable { * ); * * // Logs: - * // "Adding: 1" - * // "Adding: 2" - * // "Adding: 3" - * // "Sum equals: 6" + * // 'Adding: 1' + * // 'Adding: 2' + * // 'Adding: 3' + * // 'Sum equals: 6' * ``` * * Cancel a subscription @@ -202,14 +199,14 @@ export class Observable implements Subscribable { * // Logs: * // 0 after 1s * // 1 after 2s - * // "unsubscribed!" after 2.5s + * // 'unsubscribed!' after 2.5s * ``` * * @param {Observer|Function} observerOrNext (optional) Either an observer with methods to be called, - * or the first of three possible handlers, which is the handler for each value emitted from the subscribed - * Observable. + * or the first of three possible handlers, which is the handler for each value emitted from the subscribed + * Observable. * @param {Function} error (optional) A handler for a terminal event resulting from an error. If no error handler is provided, - * the error will be thrown asynchronously as unhandled. + * the error will be thrown asynchronously as unhandled. * @param {Function} complete (optional) A handler for a terminal event resulting from successful completion. * @return {Subscription} a subscription reference to the registered handlers * @method subscribe @@ -272,27 +269,28 @@ export class Observable implements Subscribable { * const source$ = interval(1000).pipe(take(4)); * * async function getTotal() { - * let total = 0; + * let total = 0; * - * await source$.forEach(value => { - * total += value; - * console.log('observable -> ', value); - * }); + * await source$.forEach(value => { + * total += value; + * console.log('observable -> ' + value); + * }); * - * return total; + * return total; * } * * getTotal().then( - * total => console.log('Total:', total) - * ) + * total => console.log('Total: ' + total) + * ); * * // Expected: - * // "observable -> 0" - * // "observable -> 1" - * // "observable -> 2" - * // "observable -> 3" - * // "Total: 6" + * // 'observable -> 0' + * // 'observable -> 1' + * // 'observable -> 2' + * // 'observable -> 3' + * // 'Total: 6' * ``` + * * @param next a handler for each value emitted by the observable * @return a promise that either resolves on observable completion or * rejects with the handled error @@ -435,7 +433,7 @@ export class Observable implements Subscribable { * map(x => x + x), * scan((acc, x) => acc + x) * ) - * .subscribe(x => console.log(x)) + * .subscribe(x => console.log(x)); * ``` */ pipe(...operations: OperatorFunction[]): Observable { diff --git a/src/internal/ajax/ajax.ts b/src/internal/ajax/ajax.ts index 3baf3e4eb9..dc0dad1768 100644 --- a/src/internal/ajax/ajax.ts +++ b/src/internal/ajax/ajax.ts @@ -19,9 +19,9 @@ export interface AjaxCreationMethod { * import { map, catchError, of } from 'rxjs'; * * const obs$ = ajax({ - * method: 'GET', - * url: `https://api.github.com/users?per_page=5`, - * responseType: 'json', + * method: 'GET', + * url: 'https://api.github.com/users?per_page=5', + * responseType: 'json' * }).pipe( * map(userResponse => console.log('users: ', userResponse)), * catchError(error => { @@ -44,7 +44,7 @@ export interface AjaxCreationMethod { * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; * - * const obs$ = ajax(`https://api.github.com/users?per_page=5`).pipe( + * const obs$ = ajax('https://api.github.com/users?per_page=5').pipe( * map(userResponse => console.log('users: ', userResponse)), * catchError(error => { * console.log('error: ', error); @@ -181,13 +181,18 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; * - * const obs$ = ajax(`https://api.github.com/users?per_page=5`).pipe( + * const obs$ = ajax('https://api.github.com/users?per_page=5').pipe( * map(userResponse => console.log('users: ', userResponse)), * catchError(error => { * console.log('error: ', error); * return of(error); * }) * ); + * + * obs$.subscribe({ + * next: value => console.log(value), + * error: err => console.log(err) + * }); * ``` * * Using `ajax.getJSON()` to fetch data from API @@ -196,7 +201,7 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; * - * const obs$ = ajax.getJSON(`https://api.github.com/users?per_page=5`).pipe( + * const obs$ = ajax.getJSON('https://api.github.com/users?per_page=5').pipe( * map(userResponse => console.log('users: ', userResponse)), * catchError(error => { * console.log('error: ', error); @@ -204,6 +209,10 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * }) * ); * + * obs$.subscribe({ + * next: value => console.log(value), + * error: err => console.log(err) + * }); * ``` * * Using `ajax()` with object as argument and method POST with a two seconds delay @@ -230,6 +239,10 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * }) * ); * + * users.subscribe({ + * next: value => console.log(value), + * error: err => console.log(err) + * }); * ``` * * Using `ajax()` to fetch. An error object that is being returned from the request @@ -238,7 +251,7 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * import { ajax } from 'rxjs/ajax'; * import { map, catchError, of } from 'rxjs'; * - * const obs$ = ajax(`https://api.github.com/404`).pipe( + * const obs$ = ajax('https://api.github.com/404').pipe( * map(userResponse => console.log('users: ', userResponse)), * catchError(error => { * console.log('error: ', error); @@ -246,6 +259,10 @@ function ajaxGetJSON(url: string, headers?: Record): Observab * }) * ); * + * obs$.subscribe({ + * next: value => console.log(value), + * error: err => console.log(err) + * }); * ``` */ export const ajax: AjaxCreationMethod = (() => { diff --git a/src/internal/firstValueFrom.ts b/src/internal/firstValueFrom.ts index 54687b1d52..2fc4bcfe43 100644 --- a/src/internal/firstValueFrom.ts +++ b/src/internal/firstValueFrom.ts @@ -39,13 +39,13 @@ export function firstValueFrom(source: Observable): Promise; * async function execute() { * const source$ = interval(2000); * const firstNumber = await firstValueFrom(source$); - * console.log(`The first number is ${firstNumber}`); + * console.log(`The first number is ${ firstNumber }`); * } * * execute(); * * // Expected output: - * // "The first number is 0" + * // 'The first number is 0' * ``` * * @see {@link lastValueFrom} diff --git a/src/internal/lastValueFrom.ts b/src/internal/lastValueFrom.ts index dfa4909930..90fcebfb3e 100644 --- a/src/internal/lastValueFrom.ts +++ b/src/internal/lastValueFrom.ts @@ -37,13 +37,13 @@ export function lastValueFrom(source: Observable): Promise; * async function execute() { * const source$ = interval(2000).pipe(take(10)); * const finalNumber = await lastValueFrom(source$); - * console.log(`The final number is ${finalNumber}`); + * console.log(`The final number is ${ finalNumber }`); * } * * execute(); * * // Expected output: - * // "The final number is 9" + * // 'The final number is 9' * ``` * * @see {@link firstValueFrom} diff --git a/src/internal/observable/combineLatest.ts b/src/internal/observable/combineLatest.ts index 66f1f3a626..f99da47d4d 100644 --- a/src/internal/observable/combineLatest.ts +++ b/src/internal/observable/combineLatest.ts @@ -140,10 +140,10 @@ export function combineLatest>>( * const combined = combineLatest(observables); * combined.subscribe(value => console.log(value)); * // Logs - * // {a: 0, b: 0, c: 0} immediately - * // {a: 1, b: 0, c: 0} after 1s - * // {a: 1, b: 5, c: 0} after 5s - * // {a: 1, b: 5, c: 10} after 10s + * // { a: 0, b: 0, c: 0 } immediately + * // { a: 1, b: 0, c: 0 } after 1s + * // { a: 1, b: 5, c: 0 } after 5s + * // { a: 1, b: 5, c: 10 } after 10s * ``` * * Combine an array of Observables @@ -153,8 +153,8 @@ export function combineLatest>>( * * const observables = [1, 5, 10].map( * n => of(n).pipe( - * delay(n * 1000), // emit 0 and then emit n after n seconds - * startWith(0), + * delay(n * 1000), // emit 0 and then emit n after n seconds + * startWith(0) * ) * ); * const combined = combineLatest(observables); diff --git a/src/internal/observable/concat.ts b/src/internal/observable/concat.ts index fcbe9b642f..75f9722f02 100644 --- a/src/internal/observable/concat.ts +++ b/src/internal/observable/concat.ts @@ -89,18 +89,17 @@ export function concat( * const timer = interval(1000).pipe(take(2)); * * concat(timer, timer) // concatenating the same Observable! - * .subscribe( - * value => console.log(value), - * err => {}, - * () => console.log('...and it is done!') - * ); + * .subscribe({ + * next: value => console.log(value), + * complete: () => console.log('...and it is done!') + * }); * * // Logs: * // 0 after 1s * // 1 after 2s * // 0 after 3s * // 1 after 4s - * // "...and it is done!" also after 4s + * // '...and it is done!' also after 4s * ``` * * @see {@link concatAll} @@ -109,11 +108,7 @@ export function concat( * @see {@link startWith} * @see {@link endWith} * - * @param input1 An input Observable to concatenate with others. - * @param input2 An input Observable to concatenate with others. - * More than one input Observables may be given as argument. - * @param scheduler An optional {@link SchedulerLike} to schedule each - * Observable subscription on. + * @param args Input Observables to concatenate. */ export function concat(...args: any[]): Observable { return concatAll()(from(args, popScheduler(args))); diff --git a/src/internal/observable/defer.ts b/src/internal/observable/defer.ts index d555e05d34..2e54b37246 100644 --- a/src/internal/observable/defer.ts +++ b/src/internal/observable/defer.ts @@ -27,7 +27,7 @@ import { innerFrom } from './innerFrom'; * ```ts * import { defer, fromEvent, interval } from 'rxjs'; * - * const clicksOrInterval = defer(function () { + * const clicksOrInterval = defer(() => { * return Math.random() > 0.5 * ? fromEvent(document, 'click') * : interval(1000); diff --git a/src/internal/observable/dom/WebSocketSubject.ts b/src/internal/observable/dom/WebSocketSubject.ts index 4c6f145a2b..496117dfb3 100644 --- a/src/internal/observable/dom/WebSocketSubject.ts +++ b/src/internal/observable/dom/WebSocketSubject.ts @@ -17,7 +17,7 @@ import { Observer, NextObserver } from '../../types'; * use `openObserver`, when the connection is closed `closeObserver`, if we * are interested in listening for data coming from server: `deserializer`, * which allows us to customize the deserialization strategy of data before passing it - * to the socket client. By default `deserializer` is going to apply `JSON.parse` to each message coming + * to the socket client. By default, `deserializer` is going to apply `JSON.parse` to each message coming * from the Server. * * ## Examples @@ -25,18 +25,19 @@ import { Observer, NextObserver } from '../../types'; * **deserializer**, the default for this property is `JSON.parse` but since there are just two options * for incoming data, either be text or binarydata. We can apply a custom deserialization strategy * or just simply skip the default behaviour. + * * ```ts * import { webSocket } from 'rxjs/webSocket'; * * const wsSubject = webSocket({ - * url: 'ws://localhost:8081', - * //Apply any transformation of your choice. - * deserializer: ({data}) => data + * url: 'ws://localhost:8081', + * //Apply any transformation of your choice. + * deserializer: ({ data }) => data * }); * * wsSubject.subscribe(console.log); * - * // Let's suppose we have this on the Server: ws.send("This is a msg from the server") + * // Let's suppose we have this on the Server: ws.send('This is a msg from the server') * //output * // * // This is a msg from the server @@ -48,17 +49,17 @@ import { Observer, NextObserver } from '../../types'; * import { webSocket } from 'rxjs/webSocket'; * * const wsSubject = webSocket({ - * url: 'ws://localhost:8081', - * //Apply any transformation of your choice. - * serializer: msg => JSON.stringify({channel: "webDevelopment", msg: msg}) + * url: 'ws://localhost:8081', + * // Apply any transformation of your choice. + * serializer: msg => JSON.stringify({ channel: 'webDevelopment', msg: msg }) * }); * - * wsSubject.subscribe(() => subject.next("msg to the server")); + * wsSubject.subscribe(() => subject.next('msg to the server')); * * // Let's suppose we have this on the Server: - * // ws.on("message", msg => console.log); - * // ws.send("This is a msg from the server"); - * //output at server side: + * // ws.on('message', msg => console.log); + * // ws.send('This is a msg from the server'); + * // output at server side: * // * // {"channel":"webDevelopment","msg":"msg to the server"} * ``` @@ -69,36 +70,37 @@ import { Observer, NextObserver } from '../../types'; * import { webSocket } from 'rxjs/webSocket'; * * const wsSubject = webSocket({ - * url: 'ws://localhost:8081', - * closeObserver: { - next(closeEvent) { - const customError = { code: 6666, reason: "Custom evil reason" } - console.log(`code: ${customError.code}, reason: ${customError.reason}`); - } - } + * url: 'ws://localhost:8081', + * closeObserver: { + * next() { + * const customError = { code: 6666, reason: 'Custom evil reason' } + * console.log(`code: ${ customError.code }, reason: ${ customError.reason }`); + * } + * } * }); * - * //output + * // output * // code: 6666, reason: Custom evil reason * ``` * * **openObserver**, Let's say we need to make some kind of init task before sending/receiving msgs to the * webSocket or sending notification that the connection was successful, this is when * openObserver is useful for. + * * ```ts * import { webSocket } from 'rxjs/webSocket'; * * const wsSubject = webSocket({ - * url: 'ws://localhost:8081', - * openObserver: { - * next: () => { - * console.log('connetion ok'); - * } - * }, + * url: 'ws://localhost:8081', + * openObserver: { + * next: () => { + * console.log('Connection ok'); + * } + * } * }); * - * //output - * // connetion ok` + * // output + * // Connection ok * ``` */ export interface WebSocketSubjectConfig { @@ -123,7 +125,7 @@ export interface WebSocketSubjectConfig { */ openObserver?: NextObserver; /** - * An Observer then watches when close events occur on the underlying webSocket + * An Observer that watches when close events occur on the underlying web socket */ closeObserver?: NextObserver; /** diff --git a/src/internal/observable/dom/animationFrames.ts b/src/internal/observable/dom/animationFrames.ts index 64a65cd014..707174f9c0 100644 --- a/src/internal/observable/dom/animationFrames.ts +++ b/src/internal/observable/dom/animationFrames.ts @@ -1,13 +1,13 @@ import { Observable } from '../../Observable'; import { Subscription } from '../../Subscription'; -import { TimestampProvider } from "../../types"; +import { TimestampProvider } from '../../types'; import { performanceTimestampProvider } from '../../scheduler/performanceTimestampProvider'; import { animationFrameProvider } from '../../scheduler/animationFrameProvider'; /** * An observable of animation frames * - * Emits the the amount of time elapsed since subscription and the timestamp on each animation frame. + * Emits the amount of time elapsed since subscription and the timestamp on each animation frame. * Defaults to milliseconds provided to the requestAnimationFrame's callback. Does not end on its own. * * Every subscription will start a separate animation loop. Since animation frames are always scheduled @@ -30,7 +30,7 @@ import { animationFrameProvider } from '../../scheduler/animationFrameProvider'; * const diff = end - start; * return animationFrames().pipe( * // Figure out what percentage of time has passed - * map(({elapsed}) => elapsed / duration), + * map(({ elapsed }) => elapsed / duration), * // Take the vector while less than 100% * takeWhile(v => v < 1), * // Finish with 100% @@ -50,7 +50,7 @@ import { animationFrameProvider } from '../../scheduler/animationFrameProvider'; * div.style.transform = 'translate3d(10px, 0, 0)'; * * tween(10, 200, 4000).subscribe(x => { - * div.style.transform = `translate3d(${x}px, 0, 0)`; + * div.style.transform = `translate3d(${ x }px, 0, 0)`; * }); * ``` * @@ -83,7 +83,7 @@ export function animationFrames(timestampProvider?: TimestampProvider) { */ function animationFramesFactory(timestampProvider?: TimestampProvider) { const { schedule } = animationFrameProvider; - return new Observable<{ timestamp: number, elapsed: number }>(subscriber => { + return new Observable<{ timestamp: number; elapsed: number }>((subscriber) => { const subscription = new Subscription(); // If no timestamp provider is specified, use performance.now() - as it // will return timestamps 'compatible' with those passed to the run @@ -105,7 +105,7 @@ function animationFramesFactory(timestampProvider?: TimestampProvider) { const now = provider.now(); subscriber.next({ timestamp: timestampProvider ? now : timestamp, - elapsed: now - start + elapsed: now - start, }); if (!subscriber.closed) { subscription.add(schedule(run)); diff --git a/src/internal/observable/dom/fetch.ts b/src/internal/observable/dom/fetch.ts index 202c93c622..a2a01359f6 100644 --- a/src/internal/observable/dom/fetch.ts +++ b/src/internal/observable/dom/fetch.ts @@ -35,25 +35,25 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab * import { switchMap, of, catchError } from 'rxjs'; * * const data$ = fromFetch('https://api.github.com/users?per_page=5').pipe( - * switchMap(response => { - * if (response.ok) { - * // OK return data - * return response.json(); - * } else { - * // Server is returning a status requiring the client to try something else. - * return of({ error: true, message: `Error ${response.status}` }); - * } - * }), - * catchError(err => { - * // Network or other error, handle appropriately - * console.error(err); - * return of({ error: true, message: err.message }) - * }) + * switchMap(response => { + * if (response.ok) { + * // OK return data + * return response.json(); + * } else { + * // Server is returning a status requiring the client to try something else. + * return of({ error: true, message: `Error ${ response.status }` }); + * } + * }), + * catchError(err => { + * // Network or other error, handle appropriately + * console.error(err); + * return of({ error: true, message: err.message }) + * }) * ); * * data$.subscribe({ - * next: result => console.log(result), - * complete: () => console.log('done') + * next: result => console.log(result), + * complete: () => console.log('done') * }); * ``` * @@ -81,16 +81,16 @@ export function fromFetch(input: string | Request, init?: RequestInit): Observab * }); * * data$.subscribe({ - * next: result => console.log(result), - * complete: () => console.log('done') + * next: result => console.log(result), + * complete: () => console.log('done') * }); * ``` * * @param input The resource you would like to fetch. Can be a url or a request object. * @param initWithSelector A configuration object for the fetch. * [See MDN for more details](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) - * @returns An Observable, that when subscribed to performs an HTTP request using the native `fetch` - * function. The {@link Subscription} is tied to an `AbortController` for the the fetch. + * @returns An Observable, that when subscribed to, performs an HTTP request using the native `fetch` + * function. The {@link Subscription} is tied to an `AbortController` for the fetch. */ export function fromFetch( input: string | Request, diff --git a/src/internal/observable/dom/webSocket.ts b/src/internal/observable/dom/webSocket.ts index bb8d9115cb..d642f0b4b3 100644 --- a/src/internal/observable/dom/webSocket.ts +++ b/src/internal/observable/dom/webSocket.ts @@ -87,50 +87,53 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject'; * Listening for messages from the server * * ```ts - * import { webSocket } from "rxjs/webSocket"; - * const subject = webSocket("ws://localhost:8081"); - * - * subject.subscribe( - * msg => console.log('message received: ' + msg), // Called whenever there is a message from the server. - * err => console.log(err), // Called if at any point WebSocket API signals some kind of error. - * () => console.log('complete') // Called when connection is closed (for whatever reason). - * ); + * import { webSocket } from 'rxjs/webSocket'; + * + * const subject = webSocket('ws://localhost:8081'); + * + * subject.subscribe({ + * next: msg => console.log('message received: ' + msg), // Called whenever there is a message from the server. + * error: err => console.log(err), // Called if at any point WebSocket API signals some kind of error. + * complete: () => console.log('complete') // Called when connection is closed (for whatever reason). + * }); * ``` * * Pushing messages to the server * * ```ts - * import { webSocket } from "rxjs/webSocket"; + * import { webSocket } from 'rxjs/webSocket'; + * * const subject = webSocket('ws://localhost:8081'); * * subject.subscribe(); * // Note that at least one consumer has to subscribe to the created subject - otherwise "nexted" values will be just buffered and not sent, * // since no connection was established! * - * subject.next({message: 'some message'}); + * subject.next({ message: 'some message' }); * // This will send a message to the server once a connection is made. Remember value is serialized with JSON.stringify by default! * * subject.complete(); // Closes the connection. * - * subject.error({code: 4000, reason: 'I think our app just broke!'}); + * subject.error({ code: 4000, reason: 'I think our app just broke!' }); * // Also closes the connection, but let's the server know that this closing is caused by some error. * ``` * * Multiplexing WebSocket * * ```ts - * import { webSocket } from "rxjs/webSocket"; + * import { webSocket } from 'rxjs/webSocket'; + * * const subject = webSocket('ws://localhost:8081'); * * const observableA = subject.multiplex( - * () => ({subscribe: 'A'}), // When server gets this message, it will start sending messages for 'A'... - * () => ({unsubscribe: 'A'}), // ...and when gets this one, it will stop. + * () => ({ subscribe: 'A' }), // When server gets this message, it will start sending messages for 'A'... + * () => ({ unsubscribe: 'A' }), // ...and when gets this one, it will stop. * message => message.type === 'A' // If the function returns `true` message is passed down the stream. Skipped if the function returns false. * ); * * const observableB = subject.multiplex( // And the same goes for 'B'. - * () => ({subscribe: 'B'}), - * () => ({unsubscribe: 'B'}), + * () => ({ subscribe: 'B' }), + * () => ({ unsubscribe: 'B' }), * message => message.type === 'B' * ); * @@ -150,7 +153,6 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject'; * // socket connection closes. * ``` * - * * @param {string|WebSocketSubjectConfig} urlConfigOrSource The WebSocket endpoint as an url or an object with * configuration and additional Observers. * @return {WebSocketSubject} Subject which allows to both send and receive messages via WebSocket connection. diff --git a/src/internal/observable/forkJoin.ts b/src/internal/observable/forkJoin.ts index f0b1d351dd..23f4d76026 100644 --- a/src/internal/observable/forkJoin.ts +++ b/src/internal/observable/forkJoin.ts @@ -102,7 +102,7 @@ export function forkJoin>>( * const observable = forkJoin({ * foo: of(1, 2, 3, 4), * bar: Promise.resolve(8), - * baz: timer(4000), + * baz: timer(4000) * }); * observable.subscribe({ * next: value => console.log(value), @@ -111,7 +111,7 @@ export function forkJoin>>( * * // Logs: * // { foo: 4, bar: 8, baz: 0 } after 4 seconds - * // "This is how it ends!" immediately after + * // 'This is how it ends!' immediately after * ``` * * Use `forkJoin` with an array of observable inputs @@ -122,7 +122,7 @@ export function forkJoin>>( * const observable = forkJoin([ * of(1, 2, 3, 4), * Promise.resolve(8), - * timer(4000), + * timer(4000) * ]); * observable.subscribe({ * next: value => console.log(value), @@ -131,7 +131,7 @@ export function forkJoin>>( * * // Logs: * // [4, 8, 0] after 4 seconds - * // "This is how it ends!" immediately after + * // 'This is how it ends!' immediately after * ``` * * @see {@link combineLatest} diff --git a/src/internal/observable/from.ts b/src/internal/observable/from.ts index 88b988724a..834bb22852 100644 --- a/src/internal/observable/from.ts +++ b/src/internal/observable/from.ts @@ -84,8 +84,8 @@ export function from>(input: O, scheduler: Schedu * console.log('end'); * * // Logs: - * // start - * // end + * // 'start' + * // 'end' * // 10 * // 20 * // 30 diff --git a/src/internal/observable/fromEventPattern.ts b/src/internal/observable/fromEventPattern.ts index 7545d9a99b..fee384765f 100644 --- a/src/internal/observable/fromEventPattern.ts +++ b/src/internal/observable/fromEventPattern.ts @@ -106,19 +106,19 @@ export function fromEventPattern( * import { fromEventPattern } from 'rxjs'; * * someAPI.registerEventHandler((eventType, eventMessage) => { - * console.log(eventType, eventMessage); // Logs "EVENT_TYPE" "EVENT_MESSAGE" to console. + * console.log(eventType, eventMessage); // Logs 'EVENT_TYPE' 'EVENT_MESSAGE' to console. * }); * * const someAPIObservable = fromEventPattern( * handler => someAPI.registerEventHandler(handler), * handler => someAPI.unregisterEventHandler(handler) - * (eventType, eventMessage) => eventType + " --- " + eventMessage // without that function only "EVENT_TYPE" + * (eventType, eventMessage) => eventType + ' --- ' + eventMessage // without that function only 'EVENT_TYPE' * ); // would be emitted by the Observable * * someAPIObservable.subscribe(value => console.log(value)); * * // Logs: - * // "EVENT_TYPE --- EVENT_MESSAGE" + * // 'EVENT_TYPE --- EVENT_MESSAGE' * ``` * * @see {@link fromEvent} diff --git a/src/internal/observable/generate.ts b/src/internal/observable/generate.ts index 032f69bfa3..e8af3036fd 100644 --- a/src/internal/observable/generate.ts +++ b/src/internal/observable/generate.ts @@ -158,7 +158,7 @@ export function generate( * // 0 * // 1 * // 2 - * // "Complete!" + * // 'Complete!' * ``` * * Use with condition, iterate and resultSelector functions @@ -170,14 +170,14 @@ export function generate( * * result.subscribe({ * next: value => console.log(value), - * complete: () => console.log('complete!') + * complete: () => console.log('Complete!') * }); * * // Logs: * // 0 * // 1000 * // 2000 - * // "complete!" + * // 'Complete!' * ``` * * Use with options object @@ -194,14 +194,14 @@ export function generate( * * result.subscribe({ * next: value => console.log(value), - * complete: () => console.log('complete!') + * complete: () => console.log('Complete!') * }); * * // Logs: * // 0 * // 1000 * // 2000 - * // "Complete!" + * // 'Complete!' * ``` * * Use options object without condition function @@ -217,7 +217,7 @@ export function generate( * * result.subscribe({ * next: value => console.log(value), - * complete: () => console.log('complete!') // This will never run + * complete: () => console.log('Complete!') // This will never run * }); * * // Logs: @@ -264,19 +264,19 @@ export function generate( * const result = generate({ * initialState: 0, * condition: x => x < 3, - * iterate: x => x + 1, + * iterate: x => x + 1 * }); * * result.subscribe({ * next: value => console.log(value), - * complete: () => console.log('complete!') + * complete: () => console.log('Complete!') * }); * * // Logs: * // 0 * // 1 * // 2 - * // "Complete!". + * // 'Complete!' * ``` * * @see {@link from} @@ -307,19 +307,19 @@ export function generate(options: GenerateBaseOptions): Observable; * initialState: 0, * condition: x => x < 3, * iterate: x => x + 1, - * resultSelector: x => x, + * resultSelector: x => x * }); * * result.subscribe({ * next: value => console.log(value), - * complete: () => console.log('complete!') + * complete: () => console.log('Complete!') * }); * * // Logs: * // 0 * // 1 * // 2 - * // "Complete!". + * // 'Complete!' * ``` * * @see {@link from} diff --git a/src/internal/observable/iif.ts b/src/internal/observable/iif.ts index e23026f1e9..56ede0c250 100644 --- a/src/internal/observable/iif.ts +++ b/src/internal/observable/iif.ts @@ -25,52 +25,52 @@ import { ObservableInput } from '../types'; * const firstOrSecond = iif( * () => subscribeToFirst, * of('first'), - * of('second'), + * of('second') * ); * * subscribeToFirst = true; * firstOrSecond.subscribe(value => console.log(value)); * * // Logs: - * // "first" + * // 'first' * * subscribeToFirst = false; * firstOrSecond.subscribe(value => console.log(value)); * * // Logs: - * // "second" - * + * // 'second' * ``` * * Control access to an Observable * * ```ts + * import { iif, of, EMPTY } from 'rxjs'; + * * let accessGranted; * const observableIfYouHaveAccess = iif( * () => accessGranted, - * of('It seems you have an access...'), // Note that only one Observable is passed to the operator. + * of('It seems you have an access...'), + * EMPTY * ); * * accessGranted = true; - * observableIfYouHaveAccess.subscribe( - * value => console.log(value), - * err => {}, - * () => console.log('The end'), - * ); + * observableIfYouHaveAccess.subscribe({ + * next: value => console.log(value), + * complete: () => console.log('The end') + * }); * * // Logs: - * // "It seems you have an access..." - * // "The end" + * // 'It seems you have an access...' + * // 'The end' * * accessGranted = false; - * observableIfYouHaveAccess.subscribe( - * value => console.log(value), - * err => {}, - * () => console.log('The end'), - * ); + * observableIfYouHaveAccess.subscribe({ + * next: value => console.log(value), + * complete: () => console.log('The end') + * }); * * // Logs: - * // "The end" + * // 'The end' * ``` * * @see {@link defer} diff --git a/src/internal/observable/merge.ts b/src/internal/observable/merge.ts index 9953d0cd3e..38adf345dc 100644 --- a/src/internal/observable/merge.ts +++ b/src/internal/observable/merge.ts @@ -59,6 +59,7 @@ export function merge( * const timer1 = interval(1000).pipe(take(10)); * const timer2 = interval(2000).pipe(take(6)); * const timer3 = interval(500).pipe(take(10)); + * * const concurrent = 2; // the argument * const merged = merge(timer1, timer2, timer3, concurrent); * merged.subscribe(x => console.log(x)); diff --git a/src/internal/observable/never.ts b/src/internal/observable/never.ts index b7b29b106c..cfbec7de94 100644 --- a/src/internal/observable/never.ts +++ b/src/internal/observable/never.ts @@ -19,12 +19,14 @@ import { noop } from '../util/noop'; * ```ts * import { NEVER, startWith } from 'rxjs'; * - * function info() { - * console.log('Will not be called'); - * } - * const result = NEVER.pipe(startWith(7)); - * result.subscribe(x => console.log(x), info, info); + * const info = () => console.log('Will not be called'); * + * const result = NEVER.pipe(startWith(7)); + * result.subscribe({ + * next: x => console.log(x), + * error: info, + * complete: info + * }); * ``` * * @see {@link Observable} diff --git a/src/internal/observable/of.ts b/src/internal/observable/of.ts index 7f9fe21380..dc0c918236 100644 --- a/src/internal/observable/of.ts +++ b/src/internal/observable/of.ts @@ -40,11 +40,11 @@ export function of(...values: A): Observable console.log('next:', next), - * err => console.log('error:', err), - * () => console.log('the end'), - * ); + * .subscribe({ + * next: value => console.log('next:', value), + * error: err => console.log('error:', err), + * complete: () => console.log('the end'), + * }); * * // Outputs * // next: 10 @@ -59,11 +59,11 @@ export function of(...values: A): Observable console.log('next:', next), - * err => console.log('error:', err), - * () => console.log('the end'), - * ); + * .subscribe({ + * next: value => console.log('next:', value), + * error: err => console.log('error:', err), + * complete: () => console.log('the end'), + * }); * * // Outputs * // next: [1, 2, 3] diff --git a/src/internal/observable/onErrorResumeNext.ts b/src/internal/observable/onErrorResumeNext.ts index 6cb016ff6a..60fbceca39 100644 --- a/src/internal/observable/onErrorResumeNext.ts +++ b/src/internal/observable/onErrorResumeNext.ts @@ -11,18 +11,18 @@ export function onErrorResumeNext(...sources: [... /* tslint:enable:max-line-length */ /** - * When any of the provided Observable emits an complete or error notification, it immediately subscribes to the next one + * When any of the provided Observable emits a complete or an error notification, it immediately subscribes to the next one * that was passed. * * Execute series of Observables no matter what, even if it means swallowing errors. * * ![](onErrorResumeNext.png) * - * `onErrorResumeNext` Will subscribe to each observable source it is provided, in order. + * `onErrorResumeNext` will subscribe to each observable source it is provided, in order. * If the source it's subscribed to emits an error or completes, it will move to the next source * without error. * - * If `onErrorResumeNext` is provided no arguments, or a single, empty array, it will return {@link index/EMPTY}. + * If `onErrorResumeNext` is provided no arguments, or a single, empty array, it will return {@link EMPTY}. * * `onErrorResumeNext` is basically {@link concat}, only it will continue, even if one of its * sources emits an error. @@ -39,19 +39,21 @@ export function onErrorResumeNext(...sources: [... * import { onErrorResumeNext, of, map } from 'rxjs'; * * onErrorResumeNext( - * of(1, 2, 3, 0).pipe( - * map(x => { - * if (x === 0) throw Error(); - * return 10 / x; - * }) - * ), - * of(1, 2, 3), + * of(1, 2, 3, 0).pipe( + * map(x => { + * if (x === 0) { + * throw Error(); + * } + * return 10 / x; + * }) + * ), + * of(1, 2, 3) * ) - * .subscribe( - * val => console.log(val), - * err => console.log(err), // Will never be called. - * () => console.log('done'), - * ); + * .subscribe({ + * next: value => console.log(value), + * error: err => console.log(err), // Will never be called. + * complete: () => console.log('done') + * }); * * // Logs: * // 10 @@ -60,7 +62,7 @@ export function onErrorResumeNext(...sources: [... * // 1 * // 2 * // 3 - * // "done" + * // 'done' * ``` * * @see {@link concat} diff --git a/src/internal/observable/pairs.ts b/src/internal/observable/pairs.ts index 2e0caa8b79..4dafb9ffb8 100644 --- a/src/internal/observable/pairs.ts +++ b/src/internal/observable/pairs.ts @@ -36,7 +36,7 @@ export function pairs( * enumerable keys that are present on an object directly - not ones inherited * via prototype chain. * - * By default these arrays are emitted synchronously. To change that you can + * By default, these arrays are emitted synchronously. To change that you can * pass a {@link SchedulerLike} as a second argument to `pairs`. * * ## Example @@ -58,10 +58,10 @@ export function pairs( * }); * * // Logs: - * // ["foo", 42], - * // ["bar", 56], - * // ["baz", 78], - * // "Complete!" + * // ['foo', 42] + * // ['bar', 56] + * // ['baz', 78] + * // 'Complete!' * ``` * * ### Object.entries required diff --git a/src/internal/observable/partition.ts b/src/internal/observable/partition.ts index e2f741deb6..d69db663f5 100644 --- a/src/internal/observable/partition.ts +++ b/src/internal/observable/partition.ts @@ -48,7 +48,7 @@ export function partition(source: ObservableInput, predicate: (value: T, i * import { of, partition } from 'rxjs'; * * const observableValues = of(1, 2, 3, 4, 5, 6); - * const [evens$, odds$] = partition(observableValues, (value, index) => value % 2 === 0); + * const [evens$, odds$] = partition(observableValues, value => value % 2 === 0); * * odds$.subscribe(x => console.log('odds', x)); * evens$.subscribe(x => console.log('evens', x)); diff --git a/src/internal/observable/range.ts b/src/internal/observable/range.ts index 0ac22bbb7c..314ac1bed6 100644 --- a/src/internal/observable/range.ts +++ b/src/internal/observable/range.ts @@ -32,15 +32,15 @@ export function range(start: number, count: number | undefined, scheduler: Sched * const numbers = range(1, 3); * * numbers.subscribe({ - * next: value => { console.log(value) }, - * complete: () => { console.log('Complete!') } + * next: value => console.log(value), + * complete: () => console.log('Complete!') * }); * * // Logs: * // 1 * // 2 * // 3 - * // "Complete!" + * // 'Complete!' * ``` * * @see {@link timer} diff --git a/src/internal/observable/throwError.ts b/src/internal/observable/throwError.ts index aeed06c01c..a307f5ad95 100644 --- a/src/internal/observable/throwError.ts +++ b/src/internal/observable/throwError.ts @@ -28,20 +28,20 @@ import { isFunction } from '../util/isFunction'; * let errorCount = 0; * * const errorWithTimestamp$ = throwError(() => { - * const error: any = new Error(`This is error number ${++errorCount}`); - * error.timestamp = Date.now(); - * return error; + * const error: any = new Error(`This is error number ${ ++errorCount }`); + * error.timestamp = Date.now(); + * return error; * }); * * errorWithTimestamp$.subscribe({ - * error: err => console.log(err.timestamp, err.message) + * error: err => console.log(err.timestamp, err.message) * }); * * errorWithTimestamp$.subscribe({ - * error: err => console.log(err.timestamp, err.message) + * error: err => console.log(err.timestamp, err.message) * }); * - * // Logs the timestamp and a new error message each subscription; + * // Logs the timestamp and a new error message for each subscription * ``` * * ### Unnecessary usage @@ -55,18 +55,18 @@ import { isFunction } from '../util/isFunction'; * const delays$ = of(1000, 2000, Infinity, 3000); * * delays$.pipe( - * concatMap(ms => { - * if (ms < 10000) { - * return timer(ms); - * } else { - * // This is probably overkill. - * return throwError(() => new Error(`Invalid time ${ms}`)); - * } - * }) + * concatMap(ms => { + * if (ms < 10000) { + * return timer(ms); + * } else { + * // This is probably overkill. + * return throwError(() => new Error(`Invalid time ${ ms }`)); + * } + * }) * ) * .subscribe({ - * next: console.log, - * error: console.error + * next: console.log, + * error: console.error * }); * ``` * @@ -78,18 +78,18 @@ import { isFunction } from '../util/isFunction'; * const delays$ = of(1000, 2000, Infinity, 3000); * * delays$.pipe( - * concatMap(ms => { - * if (ms < 10000) { - * return timer(ms); - * } else { - * // Cleaner and easier to read for most folks. - * throw new Error(`Invalid time ${ms}`); - * } - * }) + * concatMap(ms => { + * if (ms < 10000) { + * return timer(ms); + * } else { + * // Cleaner and easier to read for most folks. + * throw new Error(`Invalid time ${ ms }`); + * } + * }) * ) * .subscribe({ - * next: console.log, - * error: console.error + * next: console.log, + * error: console.error * }); * ``` * diff --git a/src/internal/observable/timer.ts b/src/internal/observable/timer.ts index 40e5fbcb09..243d7d868f 100644 --- a/src/internal/observable/timer.ts +++ b/src/internal/observable/timer.ts @@ -56,8 +56,8 @@ import { isValidDate } from '../util/isDate'; * currentDate.getMonth(), * currentDate.getDate(), * currentDate.getHours(), - * currentDate.getMinutes() + 1, - * ) + * currentDate.getMinutes() + 1 + * ); * * // This could be any observable stream * const source = interval(1000); diff --git a/src/internal/observable/zip.ts b/src/internal/observable/zip.ts index 16aa4bbbbf..df46590e0b 100644 --- a/src/internal/observable/zip.ts +++ b/src/internal/observable/zip.ts @@ -30,9 +30,9 @@ export function zip( * ```ts * import { of, zip, map } from 'rxjs'; * - * let age$ = of(27, 25, 29); - * let name$ = of('Foo', 'Bar', 'Beer'); - * let isDev$ = of(true, true, false); + * const age$ = of(27, 25, 29); + * const name$ = of('Foo', 'Bar', 'Beer'); + * const isDev$ = of(true, true, false); * * zip(age$, name$, isDev$).pipe( * map(([age, name, isDev]) => ({ age, name, isDev })) @@ -44,6 +44,7 @@ export function zip( * // { age: 25, name: 'Bar', isDev: true } * // { age: 29, name: 'Beer', isDev: false } * ``` + * * @param sources * @return {Observable} */ diff --git a/src/internal/operators/audit.ts b/src/internal/operators/audit.ts index 4f109a9f5f..eb8c376f73 100644 --- a/src/internal/operators/audit.ts +++ b/src/internal/operators/audit.ts @@ -37,6 +37,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * const result = clicks.pipe(audit(ev => interval(1000))); * result.subscribe(x => console.log(x)); * ``` + * * @see {@link auditTime} * @see {@link debounce} * @see {@link delayWhen} diff --git a/src/internal/operators/bufferToggle.ts b/src/internal/operators/bufferToggle.ts index 41f6a2c804..c69cd7b802 100644 --- a/src/internal/operators/bufferToggle.ts +++ b/src/internal/operators/bufferToggle.ts @@ -20,7 +20,6 @@ import { arrRemove } from '../util/arrRemove'; * Observable provided to `openings`, and closing and sending the buffers when * a Subscribable or Promise returned by the `closingSelector` function emits. * - * * ## Example * * Every other second, emit the click events from the next 500ms diff --git a/src/internal/operators/bufferWhen.ts b/src/internal/operators/bufferWhen.ts index ce12509b64..6311091305 100644 --- a/src/internal/operators/bufferWhen.ts +++ b/src/internal/operators/bufferWhen.ts @@ -27,13 +27,12 @@ import { innerFrom } from '../observable/innerFrom'; * import { fromEvent, bufferWhen, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); - * const buffered = clicks.pipe(bufferWhen(() => - * interval(1000 + Math.random() * 4000) - * )); + * const buffered = clicks.pipe( + * bufferWhen(() => interval(1000 + Math.random() * 4000)) + * ); * buffered.subscribe(x => console.log(x)); * ``` * - * * @see {@link buffer} * @see {@link bufferCount} * @see {@link bufferTime} diff --git a/src/internal/operators/catchError.ts b/src/internal/operators/catchError.ts index 325581d7c9..574a6c62ea 100644 --- a/src/internal/operators/catchError.ts +++ b/src/internal/operators/catchError.ts @@ -34,14 +34,15 @@ export function catchError>( * ```ts * import { of, map, catchError } from 'rxjs'; * - * of(1, 2, 3, 4, 5).pipe( + * of(1, 2, 3, 4, 5) + * .pipe( * map(n => { - * if (n === 4) { - * throw 'four!'; + * if (n === 4) { + * throw 'four!'; * } - * return n; + * return n; * }), - * catchError(err => of('I', 'II', 'III', 'IV', 'V')), + * catchError(err => of('I', 'II', 'III', 'IV', 'V')) * ) * .subscribe(x => console.log(x)); * // 1, 2, 3, I, II, III, IV, V @@ -52,15 +53,16 @@ export function catchError>( * ```ts * import { of, map, catchError, take } from 'rxjs'; * - * of(1, 2, 3, 4, 5).pipe( + * of(1, 2, 3, 4, 5) + * .pipe( * map(n => { - * if (n === 4) { - * throw 'four!'; + * if (n === 4) { + * throw 'four!'; * } - * return n; + * return n; * }), * catchError((err, caught) => caught), - * take(30), + * take(30) * ) * .subscribe(x => console.log(x)); * // 1, 2, 3, 1, 2, 3, ... @@ -71,7 +73,8 @@ export function catchError>( * ```ts * import { of, map, catchError } from 'rxjs'; * - * of(1, 2, 3, 4, 5).pipe( + * of(1, 2, 3, 4, 5) + * .pipe( * map(n => { * if (n === 4) { * throw 'four!'; @@ -80,12 +83,12 @@ export function catchError>( * }), * catchError(err => { * throw 'error in source. Details: ' + err; - * }), + * }) * ) - * .subscribe( - * x => console.log(x), - * err => console.log(err) - * ); + * .subscribe({ + * next: x => console.log(x), + * error: err => console.log(err) + * }); * // 1, 2, 3, error in source. Details: four! * ``` * diff --git a/src/internal/operators/combineLatestAll.ts b/src/internal/operators/combineLatestAll.ts index b0b390ac96..25569a9e81 100644 --- a/src/internal/operators/combineLatestAll.ts +++ b/src/internal/operators/combineLatestAll.ts @@ -13,7 +13,7 @@ export function combineLatestAll(project: (...values: Array) => R): Oper * ![](combineLatestAll.png) * * `combineLatestAll` takes an Observable of Observables, and collects all Observables from it. Once the outer Observable completes, - * it subscribes to all collected Observables and combines their values using the {@link combineLatest} strategy, such that: + * it subscribes to all collected Observables and combines their values using the {@link combineLatest} strategy, such that: * * * Every time an inner Observable emits, the output Observable emits * * When the returned observable emits, it emits all of the latest values by: @@ -30,14 +30,10 @@ export function combineLatestAll(project: (...values: Array) => R): Oper * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe( - * map(ev => - * interval(Math.random() * 2000).pipe(take(3)) - * ), + * map(() => interval(Math.random() * 2000).pipe(take(3))), * take(2) * ); - * const result = higherOrder.pipe( - * combineLatestAll() - * ); + * const result = higherOrder.pipe(combineLatestAll()); * * result.subscribe(x => console.log(x)); * ``` diff --git a/src/internal/operators/concatAll.ts b/src/internal/operators/concatAll.ts index 9ff80a0891..05be4fc9c9 100644 --- a/src/internal/operators/concatAll.ts +++ b/src/internal/operators/concatAll.ts @@ -32,7 +32,7 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe( - * map(ev => interval(1000).pipe(take(4))), + * map(() => interval(1000).pipe(take(4))) * ); * const firstOrder = higherOrder.pipe(concatAll()); * firstOrder.subscribe(x => console.log(x)); diff --git a/src/internal/operators/concatMapTo.ts b/src/internal/operators/concatMapTo.ts index 6b179064ef..0fd8b253a9 100644 --- a/src/internal/operators/concatMapTo.ts +++ b/src/internal/operators/concatMapTo.ts @@ -48,7 +48,7 @@ export function concatMapTo>( * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( - * concatMapTo(interval(1000).pipe(take(4))), + * concatMapTo(interval(1000).pipe(take(4))) * ); * result.subscribe(x => console.log(x)); * diff --git a/src/internal/operators/connect.ts b/src/internal/operators/connect.ts index 9908fbbfda..8c324e580b 100644 --- a/src/internal/operators/connect.ts +++ b/src/internal/operators/connect.ts @@ -8,7 +8,7 @@ import { fromSubscribable } from '../observable/fromSubscribable'; export interface ConnectConfig { /** * A factory function used to create the Subject through which the source - * is multicast. By default this creates a {@link Subject}. + * is multicast. By default, this creates a {@link Subject}. */ connector: () => SubjectLike; } @@ -59,38 +59,38 @@ const DEFAULT_CONFIG: ConnectConfig = { * * source$.pipe( * // Notice in here we're merging 3 subscriptions to `shared$`. - * connect((shared$) => merge( - * shared$.pipe(map(n => `all ${n}`)), - * shared$.pipe(filter(n => n % 2 === 0), map(n => `even ${n}`)), - * shared$.pipe(filter(n => n % 2 === 1), map(n => `odd ${n}`)), + * connect(shared$ => merge( + * shared$.pipe(map(n => `all ${ n }`)), + * shared$.pipe(filter(n => n % 2 === 0), map(n => `even ${ n }`)), + * shared$.pipe(filter(n => n % 2 === 1), map(n => `odd ${ n }`)) * )) * ) * .subscribe(console.log); * * // Expected output: (notice only one subscription) - * "subscription started" - * "source emitted 1" - * "all 1" - * "odd 1" - * "source emitted 2" - * "all 2" - * "even 2" - * "source emitted 3" - * "all 3" - * "odd 3" - * "source emitted 4" - * "all 4" - * "even 4" - * "source emitted 5" - * "all 5" - * "odd 5" + * 'subscription started' + * 'source emitted 1' + * 'all 1' + * 'odd 1' + * 'source emitted 2' + * 'all 2' + * 'even 2' + * 'source emitted 3' + * 'all 3' + * 'odd 3' + * 'source emitted 4' + * 'all 4' + * 'even 4' + * 'source emitted 5' + * 'all 5' + * 'odd 5' * ``` * * @param selector A function used to set up the multicast. Gives you a multicast observable * that is not yet connected. With that, you're expected to create and return * and Observable, that when subscribed to, will utilize the multicast observable. * After this function is executed -- and its return value subscribed to -- the - * the operator will subscribe to the source, and the connection will be made. + * operator will subscribe to the source, and the connection will be made. * @param config The configuration object for `connect`. */ export function connect>( diff --git a/src/internal/operators/count.ts b/src/internal/operators/count.ts index 09e26969f6..8b764f8332 100644 --- a/src/internal/operators/count.ts +++ b/src/internal/operators/count.ts @@ -1,5 +1,6 @@ import { OperatorFunction } from '../types'; import { reduce } from './reduce'; + /** * Counts the number of emissions on the source and emits that number when the * source completes. @@ -55,7 +56,6 @@ import { reduce } from './reduce'; * @return A function that returns an Observable that emits one number that * represents the count of emissions. */ - export function count(predicate?: (value: T, index: number) => boolean): OperatorFunction { return reduce((total, value, i) => (!predicate || predicate(value, i) ? total + 1 : total), 0); } diff --git a/src/internal/operators/debounce.ts b/src/internal/operators/debounce.ts index 2ffac323de..05cf58e4d4 100644 --- a/src/internal/operators/debounce.ts +++ b/src/internal/operators/debounce.ts @@ -41,8 +41,8 @@ import { innerFrom } from '../observable/innerFrom'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( - * scan((i) => ++i, 1), - * debounce((i) => interval(200 * i)) + * scan(i => ++i, 1), + * debounce(i => interval(200 * i)) * ); * result.subscribe(x => console.log(x)); * ``` diff --git a/src/internal/operators/delayWhen.ts b/src/internal/operators/delayWhen.ts index c2a0546980..3d350735a4 100644 --- a/src/internal/operators/delayWhen.ts +++ b/src/internal/operators/delayWhen.ts @@ -47,7 +47,7 @@ export function delayWhen(delayDurationSelector: (value: T, index: number) => * * const clicks = fromEvent(document, 'click'); * const delayedClicks = clicks.pipe( - * delayWhen(event => interval(Math.random() * 5000)), + * delayWhen(() => interval(Math.random() * 5000)) * ); * delayedClicks.subscribe(x => console.log(x)); * ``` diff --git a/src/internal/operators/dematerialize.ts b/src/internal/operators/dematerialize.ts index 798ddaf9e1..116b60bfd6 100644 --- a/src/internal/operators/dematerialize.ts +++ b/src/internal/operators/dematerialize.ts @@ -35,8 +35,8 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * const upperCase = materialized.pipe(dematerialize()); * upperCase.subscribe({ - * next: x => console.log(x), - * error: e => console.error(e) + * next: x => console.log(x), + * error: e => console.error(e) * }); * * // Results in: @@ -44,6 +44,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * // B * // TypeError: x.toUpperCase is not a function * ``` + * * @see {@link materialize} * * @return A function that returns an Observable that emits items and diff --git a/src/internal/operators/distinct.ts b/src/internal/operators/distinct.ts index bc266420a7..75eca965e7 100644 --- a/src/internal/operators/distinct.ts +++ b/src/internal/operators/distinct.ts @@ -7,8 +7,8 @@ import { noop } from '../util/noop'; /** * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items. * - * If a keySelector function is provided, then it will project each value from the source observable into a new value that it will - * check for equality with previously projected values. If a keySelector function is not provided, it will use each value from the + * If a `keySelector` function is provided, then it will project each value from the source observable into a new value that it will + * check for equality with previously projected values. If the `keySelector` function is not provided, it will use each value from the * source observable directly with an equality check against previous values. * * In JavaScript runtimes that support `Set`, this operator will use a `Set` to improve performance of the distinct value checking. @@ -26,9 +26,7 @@ import { noop } from '../util/noop'; * import { of, distinct } from 'rxjs'; * * of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1) - * .pipe( - * distinct() - * ) + * .pipe(distinct()) * .subscribe(x => console.log(x)); * * // Outputs @@ -43,19 +41,13 @@ import { noop } from '../util/noop'; * ```ts * import { of, distinct } from 'rxjs'; * - * interface Person { - * age: number, - * name: string - * } - * * of( - * { age: 4, name: 'Foo'}, - * { age: 7, name: 'Bar'}, - * { age: 5, name: 'Foo'} - * ).pipe( - * distinct((p: Person) => p.name) - * ) - * .subscribe(x => console.log(x)); + * { age: 4, name: 'Foo'}, + * { age: 7, name: 'Bar'}, + * { age: 5, name: 'Foo'} + * ) + * .pipe(distinct(({ name }) => name)) + * .subscribe(x => console.log(x)); * * // Outputs * // { age: 4, name: 'Foo' } diff --git a/src/internal/operators/distinctUntilChanged.ts b/src/internal/operators/distinctUntilChanged.ts index 53432d1304..e7d2f46048 100644 --- a/src/internal/operators/distinctUntilChanged.ts +++ b/src/internal/operators/distinctUntilChanged.ts @@ -22,10 +22,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ```ts * import { of, distinctUntilChanged } from 'rxjs'; * - * of(1, 1, 1, 2, 2, 2, 1, 1, 3, 3).pipe( - * distinctUntilChanged() - * ) - * .subscribe(console.log); + * of(1, 1, 1, 2, 2, 2, 1, 1, 3, 3) + * .pipe(distinctUntilChanged()) + * .subscribe(console.log); * // Logs: 1, 2, 1, 3 * ``` * @@ -54,9 +53,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * totallyDifferentBuilds$.subscribe(console.log); * * // Logs: - * // {engineVersion: "1.1.0", transmissionVersion: "1.2.0"} - * // {engineVersion: "1.3.0", transmissionVersion: "1.4.0"} - * // {engineVersion: "2.0.0", transmissionVersion: "1.5.0"} + * // { engineVersion: '1.1.0', transmissionVersion: '1.2.0' } + * // { engineVersion: '1.3.0', transmissionVersion: '1.4.0' } + * // { engineVersion: '2.0.0', transmissionVersion: '1.5.0' } * ``` * * You can also provide a custom `comparator` to check that emitted @@ -109,11 +108,11 @@ export function distinctUntilChanged(comparator?: (previous: T, current: T) = * * // A stream of updates to a given account * const accountUpdates$ = of( - * { updatedBy: "blesh", data: [] }, - * { updatedBy: "blesh", data: [] }, - * { updatedBy: "ncjamieson", data: [] }, - * { updatedBy: "ncjamieson", data: [] }, - * { updatedBy: "blesh", data: [] } + * { updatedBy: 'blesh', data: [] }, + * { updatedBy: 'blesh', data: [] }, + * { updatedBy: 'ncjamieson', data: [] }, + * { updatedBy: 'ncjamieson', data: [] }, + * { updatedBy: 'blesh', data: [] } * ); * * // We only want the events where it changed hands @@ -123,9 +122,9 @@ export function distinctUntilChanged(comparator?: (previous: T, current: T) = * * changedHands$.subscribe(console.log); * // Logs: - * // {updatedBy: "blesh", data: Array[0]} - * // {updatedBy: "ncjamieson", data: Array[0]} - * // {updatedBy: "blesh", data: Array[0]} + * // { updatedBy: 'blesh', data: Array[0] } + * // { updatedBy: 'ncjamieson', data: Array[0] } + * // { updatedBy: 'blesh', data: Array[0] } * ``` * * @param comparator A function used to compare the previous and current keys for diff --git a/src/internal/operators/distinctUntilKeyChanged.ts b/src/internal/operators/distinctUntilKeyChanged.ts index 3bfbc07b30..0f67082601 100644 --- a/src/internal/operators/distinctUntilKeyChanged.ts +++ b/src/internal/operators/distinctUntilKeyChanged.ts @@ -21,20 +21,15 @@ export function distinctUntilKeyChanged(key: K, compare: ( * ```ts * import { of, distinctUntilKeyChanged } from 'rxjs'; * - * interface Person { - * age: number, - * name: string - * } - * - *of( - * { age: 4, name: 'Foo'}, - * { age: 7, name: 'Bar'}, - * { age: 5, name: 'Foo'}, - * { age: 6, name: 'Foo'}, - * ).pipe( - * distinctUntilKeyChanged('name'), - * ) - * .subscribe(x => console.log(x)); + * of( + * { age: 4, name: 'Foo' }, + * { age: 7, name: 'Bar' }, + * { age: 5, name: 'Foo' }, + * { age: 6, name: 'Foo' } + * ).pipe( + * distinctUntilKeyChanged('name') + * ) + * .subscribe(x => console.log(x)); * * // displays: * // { age: 4, name: 'Foo' } @@ -47,20 +42,15 @@ export function distinctUntilKeyChanged(key: K, compare: ( * ```ts * import { of, distinctUntilKeyChanged } from 'rxjs'; * - * interface Person { - * age: number, - * name: string - * } - * - *of( - * { age: 4, name: 'Foo1'}, - * { age: 7, name: 'Bar'}, - * { age: 5, name: 'Foo2'}, - * { age: 6, name: 'Foo3'}, - * ).pipe( - * distinctUntilKeyChanged('name', (x: string, y: string) => x.substring(0, 3) === y.substring(0, 3)), - * ) - * .subscribe(x => console.log(x)); + * of( + * { age: 4, name: 'Foo1' }, + * { age: 7, name: 'Bar' }, + * { age: 5, name: 'Foo2' }, + * { age: 6, name: 'Foo3' } + * ).pipe( + * distinctUntilKeyChanged('name', (x, y) => x.substring(0, 3) === y.substring(0, 3)) + * ) + * .subscribe(x => console.log(x)); * * // displays: * // { age: 4, name: 'Foo1' } diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index 0ce4984610..436e5b301a 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -34,7 +34,7 @@ export function endWith(...values: A): OperatorFun * import { interval, map, fromEvent, startWith, takeUntil, endWith } from 'rxjs'; * * const ticker$ = interval(5000).pipe( - * map(() => 'tick'), + * map(() => 'tick') * ); * * const documentClicks$ = fromEvent(document, 'click'); @@ -42,16 +42,16 @@ export function endWith(...values: A): OperatorFun * ticker$.pipe( * startWith('interval started'), * takeUntil(documentClicks$), - * endWith('interval ended by click'), + * endWith('interval ended by click') * ) * .subscribe(x => console.log(x)); * * // Result (assuming a user clicks after 15 seconds) - * // "interval started" - * // "tick" - * // "tick" - * // "tick" - * // "interval ended by click" + * // 'interval started' + * // 'tick' + * // 'tick' + * // 'tick' + * // 'interval ended by click' * ``` * * @see {@link startWith} diff --git a/src/internal/operators/every.ts b/src/internal/operators/every.ts index 036ce82e96..aa07bee306 100644 --- a/src/internal/operators/every.ts +++ b/src/internal/operators/every.ts @@ -31,10 +31,9 @@ export function every(predicate: (value: T, index: number, source: Observable * ```ts * import { of, every } from 'rxjs'; * - * of(1, 2, 3, 4, 5, 6).pipe( - * every(x => x < 5), - * ) - * .subscribe(x => console.log(x)); // -> false + * of(1, 2, 3, 4, 5, 6) + * .pipe(every(x => x < 5)) + * .subscribe(x => console.log(x)); // -> false * ``` * * @param {function} predicate A function for determining if an item meets a specified condition. diff --git a/src/internal/operators/exhaustAll.ts b/src/internal/operators/exhaustAll.ts index eca72e979b..ac30d6d1d0 100644 --- a/src/internal/operators/exhaustAll.ts +++ b/src/internal/operators/exhaustAll.ts @@ -13,11 +13,11 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * ![](exhaust.png) * - * `exhaust` subscribes to an Observable that emits Observables, also known as a + * `exhaustAll` subscribes to an Observable that emits Observables, also known as a * higher-order Observable. Each time it observes one of these emitted inner * Observables, the output Observable begins emitting the items emitted by that * inner Observable. So far, it behaves like {@link mergeAll}. However, - * `exhaust` ignores every new inner Observable if the previous Observable has + * `exhaustAll` ignores every new inner Observable if the previous Observable has * not yet completed. Once that one completes, it will accept and flatten the * next inner Observable and repeat this process. * @@ -30,7 +30,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe( - * map((ev) => interval(1000).pipe(take(5))), + * map(() => interval(1000).pipe(take(5))) * ); * const result = higherOrder.pipe(exhaustAll()); * result.subscribe(x => console.log(x)); diff --git a/src/internal/operators/exhaustMap.ts b/src/internal/operators/exhaustMap.ts index c016745687..523266bb4e 100644 --- a/src/internal/operators/exhaustMap.ts +++ b/src/internal/operators/exhaustMap.ts @@ -49,7 +49,7 @@ export function exhaustMap( * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( - * exhaustMap(ev => interval(1000).pipe(take(5))) + * exhaustMap(() => interval(1000).pipe(take(5))) * ); * result.subscribe(x => console.log(x)); * ``` diff --git a/src/internal/operators/expand.ts b/src/internal/operators/expand.ts index 8dbb08172e..77afcc2d32 100644 --- a/src/internal/operators/expand.ts +++ b/src/internal/operators/expand.ts @@ -51,7 +51,7 @@ export function expand>( * const powersOfTwo = clicks.pipe( * mapTo(1), * expand(x => of(2 * x).pipe(delay(1000))), - * take(10), + * take(10) * ); * powersOfTwo.subscribe(x => console.log(x)); * ``` diff --git a/src/internal/operators/filter.ts b/src/internal/operators/filter.ts index ec41fd17cf..35a3a0aa00 100644 --- a/src/internal/operators/filter.ts +++ b/src/internal/operators/filter.ts @@ -32,11 +32,11 @@ export function filter(predicate: (value: T, index: number) => boolean): Mono * import { fromEvent, filter } from 'rxjs'; * * const div = document.createElement('div'); - * div.style.cssText = `width: 200px;height: 200px;background: #09c;`; + * div.style.cssText = 'width: 200px; height: 200px; background: #09c;'; * document.body.appendChild(div); * * const clicks = fromEvent(document, 'click'); - * const clicksOnDivs = clicks.pipe(filter(ev => ev.target.tagName === 'DIV')); + * const clicksOnDivs = clicks.pipe(filter(ev => (ev.target).tagName === 'DIV')); * clicksOnDivs.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/finalize.ts b/src/internal/operators/finalize.ts index 70a9194552..7ab08b239c 100644 --- a/src/internal/operators/finalize.ts +++ b/src/internal/operators/finalize.ts @@ -18,16 +18,16 @@ import { operate } from '../util/lift'; * const example = source.pipe( * take(5), //take only the first 5 values * finalize(() => console.log('Sequence complete')) // Execute when the observable completes - * ) + * ); * const subscribe = example.subscribe(val => console.log(val)); * * // results: - * // 0 - * // 1 - * // 2 - * // 3 - * // 4 - * // 'Sequence complete' + * // 0 + * // 1 + * // 2 + * // 3 + * // 4 + * // 'Sequence complete' * ``` * * Execute callback function when the subscriber explicitly unsubscribes @@ -53,9 +53,9 @@ import { operate } from '../util/lift'; * timer(150).subscribe(() => sub.unsubscribe()); * * // results: - * // '[next] Called' - * // 0 - * // '[finalize] Called' + * // '[next] Called' + * // 0 + * // '[finalize] Called' * ``` * * @param {function} callback Function to be called when source terminates. diff --git a/src/internal/operators/find.ts b/src/internal/operators/find.ts index 6099a84426..049ef4c932 100644 --- a/src/internal/operators/find.ts +++ b/src/internal/operators/find.ts @@ -46,7 +46,7 @@ export function find(predicate: (value: T, index: number, source: Observable< * document.body.appendChild(div); * * const clicks = fromEvent(document, 'click'); - * const result = clicks.pipe(find(ev => ev.target.tagName === 'DIV')); + * const result = clicks.pipe(find(ev => (ev.target).tagName === 'DIV')); * result.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/findIndex.ts b/src/internal/operators/findIndex.ts index 666cedc430..7a9d943cbc 100644 --- a/src/internal/operators/findIndex.ts +++ b/src/internal/operators/findIndex.ts @@ -40,7 +40,7 @@ export function findIndex(predicate: (value: T, index: number, source: Observ * document.body.appendChild(div); * * const clicks = fromEvent(document, 'click'); - * const result = clicks.pipe(findIndex(ev => ev.target.tagName === 'DIV')); + * const result = clicks.pipe(findIndex(ev => (ev.target).tagName === 'DIV')); * result.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/first.ts b/src/internal/operators/first.ts index 1f53ae9fab..b3ca1f8e46 100644 --- a/src/internal/operators/first.ts +++ b/src/internal/operators/first.ts @@ -59,7 +59,7 @@ export function first( * document.body.appendChild(div); * * const clicks = fromEvent(document, 'click'); - * const result = clicks.pipe(first(ev => ev.target.tagName === 'DIV')); + * const result = clicks.pipe(first(ev => (ev.target).tagName === 'DIV')); * result.subscribe(x => console.log(x)); * ``` * @@ -73,7 +73,7 @@ export function first( * * @param {function(value: T, index: number, source: Observable): boolean} [predicate] * An optional function called with each item to test for condition matching. - * @param {R} [defaultValue] The default value emitted in case no valid value + * @param {D} [defaultValue] The default value emitted in case no valid value * was found on the source. * @return A function that returns an Observable that emits the first item that * matches the condition. diff --git a/src/internal/operators/groupBy.ts b/src/internal/operators/groupBy.ts index 835e3d59fa..2b760f70e4 100644 --- a/src/internal/operators/groupBy.ts +++ b/src/internal/operators/groupBy.ts @@ -74,25 +74,21 @@ export function groupBy( * import { of, groupBy, mergeMap, reduce } from 'rxjs'; * * of( - * {id: 1, name: 'JavaScript'}, - * {id: 2, name: 'Parcel'}, - * {id: 2, name: 'webpack'}, - * {id: 1, name: 'TypeScript'}, - * {id: 3, name: 'TSLint'} + * { id: 1, name: 'JavaScript' }, + * { id: 2, name: 'Parcel' }, + * { id: 2, name: 'webpack' }, + * { id: 1, name: 'TypeScript' }, + * { id: 3, name: 'TSLint' } * ).pipe( * groupBy(p => p.id), - * mergeMap((group$) => group$.pipe(reduce((acc, cur) => [...acc, cur], []))) + * mergeMap(group$ => group$.pipe(reduce((acc, cur) => [...acc, cur], []))) * ) * .subscribe(p => console.log(p)); * * // displays: - * // [ { id: 1, name: 'JavaScript'}, - * // { id: 1, name: 'TypeScript'} ] - * // - * // [ { id: 2, name: 'Parcel'}, - * // { id: 2, name: 'webpack'} ] - * // - * // [ { id: 3, name: 'TSLint'} ] + * // [{ id: 1, name: 'JavaScript' }, { id: 1, name: 'TypeScript'}] + * // [{ id: 2, name: 'Parcel' }, { id: 2, name: 'webpack'}] + * // [{ id: 3, name: 'TSLint' }] * ``` * * Pivot data on the `id` field @@ -106,15 +102,12 @@ export function groupBy( * { id: 2, name: 'webpack' }, * { id: 1, name: 'TypeScript' }, * { id: 3, name: 'TSLint' } + * ).pipe( + * groupBy(p => p.id, { element: p => p.name }), + * mergeMap(group$ => group$.pipe(reduce((acc, cur) => [...acc, cur], [`${ group$.key }`]))), + * map(arr => ({ id: parseInt(arr[0], 10), values: arr.slice(1) })) * ) - * .pipe( - * groupBy(p => p.id, { element: p => p.name }), - * mergeMap(group$ => - * group$.pipe(reduce((acc, cur) => [...acc, cur], [`${group$.key}`])) - * ), - * map(arr => ({ id: parseInt(arr[0], 10), values: arr.slice(1) })) - * ) - * .subscribe(p => console.log(p)); + * .subscribe(p => console.log(p)); * * // displays: * // { id: 1, values: [ 'JavaScript', 'TypeScript' ] } diff --git a/src/internal/operators/ignoreElements.ts b/src/internal/operators/ignoreElements.ts index 2fb7cc1179..4b85c9c27d 100644 --- a/src/internal/operators/ignoreElements.ts +++ b/src/internal/operators/ignoreElements.ts @@ -8,7 +8,7 @@ import { noop } from '../util/noop'; * * ![](ignoreElements.png) * - * The _IgnoreElements_ operator suppresses all of the items emitted by the source Observable, + * The `ignoreElements` operator suppresses all items emitted by the source Observable, * but allows its termination notification (either `error` or `complete`) to pass through unchanged. * * If you do not care about the items being emitted by an Observable, but you do want to be notified @@ -22,17 +22,18 @@ import { noop } from '../util/noop'; * ```ts * import { of, ignoreElements } from 'rxjs'; * - * of('you', 'talking', 'to', 'me').pipe( - * ignoreElements(), - * ) - * .subscribe({ - * next: word => console.log(word), - * error: err => console.log('error:', err), - * complete: () => console.log('the end'), - * }); + * of('you', 'talking', 'to', 'me') + * .pipe(ignoreElements()) + * .subscribe({ + * next: word => console.log(word), + * error: err => console.log('error:', err), + * complete: () => console.log('the end'), + * }); + * * // result: * // 'the end' * ``` + * * @return A function that returns an empty Observable that only calls * `complete` or `error`, based on which one is called by the source * Observable. diff --git a/src/internal/operators/isEmpty.ts b/src/internal/operators/isEmpty.ts index 5947b2b702..ea730a4cab 100644 --- a/src/internal/operators/isEmpty.ts +++ b/src/internal/operators/isEmpty.ts @@ -39,10 +39,10 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * source.complete(); * * // Outputs - * // a + * // 'a' * // false - * // b - * // c + * // 'b' + * // 'c' * ``` * * Emit `true` for an empty Observable diff --git a/src/internal/operators/last.ts b/src/internal/operators/last.ts index 58f77f7d48..a046922f87 100644 --- a/src/internal/operators/last.ts +++ b/src/internal/operators/last.ts @@ -39,9 +39,12 @@ export function last( * import { from, last } from 'rxjs'; * * const source = from(['x', 'y', 'z']); - * const example = source.pipe(last()); - * //output: "Last alphabet: z" - * example.subscribe(val => console.log(`Last alphabet: ${val}`)); + * const result = source.pipe(last()); + * + * result.subscribe(value => console.log(`Last alphabet: ${ value }`)); + * + * // Outputs + * // Last alphabet: z * ``` * * Default value when the value in the predicate is not matched @@ -50,9 +53,12 @@ export function last( * import { from, last } from 'rxjs'; * * const source = from(['x', 'y', 'z']); - * const example = source.pipe(last(char => char === 'a','not exist')); - * //output: "'a' is not exist." - * example.subscribe(val => console.log(`'a' is ${val}.`)); + * const result = source.pipe(last(char => char === 'a', 'not found')); + * + * result.subscribe(value => console.log(`'a' is ${ value }.`)); + * + * // Outputs + * // 'a' is not found. * ``` * * @see {@link skip} diff --git a/src/internal/operators/map.ts b/src/internal/operators/map.ts index 14aaa99837..59a3377371 100644 --- a/src/internal/operators/map.ts +++ b/src/internal/operators/map.ts @@ -27,8 +27,9 @@ export function map(project: (this: A, value: T, index: number) => R, t * ```ts * import { fromEvent, map } from 'rxjs'; * - * const clicks = fromEvent(document, 'click'); + * const clicks = fromEvent(document, 'click'); * const positions = clicks.pipe(map(ev => ev.clientX)); + * * positions.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/mapTo.ts b/src/internal/operators/mapTo.ts index 90b1823832..0f8c72a1ec 100644 --- a/src/internal/operators/mapTo.ts +++ b/src/internal/operators/mapTo.ts @@ -27,6 +27,7 @@ export function mapTo(value: R): OperatorFunction; * * const clicks = fromEvent(document, 'click'); * const greetings = clicks.pipe(mapTo('Hi')); + * * greetings.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/materialize.ts b/src/internal/operators/materialize.ts index 570c04d26d..b7f094d835 100644 --- a/src/internal/operators/materialize.ts +++ b/src/internal/operators/materialize.ts @@ -33,16 +33,15 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * import { of, materialize, map } from 'rxjs'; * * const letters = of('a', 'b', 13, 'd'); - * const upperCase = letters.pipe(map(x => x.toUpperCase())); + * const upperCase = letters.pipe(map((x: any) => x.toUpperCase())); * const materialized = upperCase.pipe(materialize()); + * * materialized.subscribe(x => console.log(x)); * * // Results in the following: - * // - Notification {kind: "N", value: "A", error: undefined, hasValue: true} - * // - Notification {kind: "N", value: "B", error: undefined, hasValue: true} - * // - Notification {kind: "E", value: undefined, error: TypeError: - * // x.toUpperCase is not a function at MapSubscriber.letters.map.x - * // [as project] (http://1…, hasValue: false} + * // - Notification { kind: 'N', value: 'A', error: undefined, hasValue: true } + * // - Notification { kind: 'N', value: 'B', error: undefined, hasValue: true } + * // - Notification { kind: 'E', value: undefined, error: TypeError { message: x.toUpperCase is not a function }, hasValue: false } * ``` * * @see {@link Notification} diff --git a/src/internal/operators/max.ts b/src/internal/operators/max.ts index ebb241ca3f..b3c5fcbc77 100644 --- a/src/internal/operators/max.ts +++ b/src/internal/operators/max.ts @@ -15,10 +15,12 @@ import { isFunction } from '../util/isFunction'; * ```ts * import { of, max } from 'rxjs'; * - * of(5, 4, 7, 2, 8).pipe( - * max(), - * ) - * .subscribe(x => console.log(x)); // -> 8 + * of(5, 4, 7, 2, 8) + * .pipe(max()) + * .subscribe(x => console.log(x)); + * + * // Outputs + * // 8 * ``` * * Use a comparer function to get the maximal item @@ -26,18 +28,17 @@ import { isFunction } from '../util/isFunction'; * ```ts * import { of, max } from 'rxjs'; * - * interface Person { - * age: number, - * name: string - * } - *of( - * {age: 7, name: 'Foo'}, - * {age: 5, name: 'Bar'}, - * {age: 9, name: 'Beer'}, + * of( + * { age: 7, name: 'Foo' }, + * { age: 5, name: 'Bar' }, + * { age: 9, name: 'Beer' } * ).pipe( - * max((a: Person, b: Person) => a.age < b.age ? -1 : 1), + * max((a, b) => a.age < b.age ? -1 : 1) * ) - * .subscribe((x: Person) => console.log(x.name)); // -> 'Beer' + * .subscribe(x => console.log(x.name)); + * + * // Outputs + * // 'Beer' * ``` * * @see {@link min} diff --git a/src/internal/operators/mergeAll.ts b/src/internal/operators/mergeAll.ts index 8807374740..9183badacb 100644 --- a/src/internal/operators/mergeAll.ts +++ b/src/internal/operators/mergeAll.ts @@ -25,8 +25,9 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * import { fromEvent, map, interval, mergeAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); - * const higherOrder = clicks.pipe(map((ev) => interval(1000))); + * const higherOrder = clicks.pipe(map(() => interval(1000))); * const firstOrder = higherOrder.pipe(mergeAll()); + * * firstOrder.subscribe(x => console.log(x)); * ``` * @@ -37,9 +38,10 @@ import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; * * const clicks = fromEvent(document, 'click'); * const higherOrder = clicks.pipe( - * map((ev) => interval(1000).pipe(take(10))), + * map(() => interval(1000).pipe(take(10))) * ); * const firstOrder = higherOrder.pipe(mergeAll(2)); + * * firstOrder.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/mergeMap.ts b/src/internal/operators/mergeMap.ts index e8ae950f5d..6a8807618f 100644 --- a/src/internal/operators/mergeMap.ts +++ b/src/internal/operators/mergeMap.ts @@ -47,8 +47,9 @@ export function mergeMap>( * * const letters = of('a', 'b', 'c'); * const result = letters.pipe( - * mergeMap(x => interval(1000).pipe(map(i => x+i))), + * mergeMap(x => interval(1000).pipe(map(i => x + i))) * ); + * * result.subscribe(x => console.log(x)); * * // Results in the following: @@ -58,7 +59,7 @@ export function mergeMap>( * // a1 * // b1 * // c1 - * // continues to list a,b,c with respective ascending integers + * // continues to list a, b, c every second with respective ascending integers * ``` * * @see {@link concatMap} diff --git a/src/internal/operators/mergeMapTo.ts b/src/internal/operators/mergeMapTo.ts index f64d60c2d8..28849a2669 100644 --- a/src/internal/operators/mergeMapTo.ts +++ b/src/internal/operators/mergeMapTo.ts @@ -37,6 +37,7 @@ export function mergeMapTo>( * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(mergeMapTo(interval(1000))); + * * result.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/mergeScan.ts b/src/internal/operators/mergeScan.ts index c0987fb8be..87ea467bba 100644 --- a/src/internal/operators/mergeScan.ts +++ b/src/internal/operators/mergeScan.ts @@ -31,7 +31,7 @@ import { mergeInternals } from './mergeInternals'; * current emission by the source Observable. It starts with 0. * * The last parameter to the `mergeScan` is the `concurrent` value which defaults - * to Infinity. It represent the maximum number of inner Observable subscriptions + * to Infinity. It represents the maximum number of inner Observable subscriptions * at a time. * * ## Example @@ -45,8 +45,9 @@ import { mergeInternals } from './mergeInternals'; * const one$ = click$.pipe(mapTo(1)); * const seed = 0; * const count$ = one$.pipe( - * mergeScan((acc, one) => of(acc + one), seed), + * mergeScan((acc, one) => of(acc + one), seed) * ); + * * count$.subscribe(x => console.log(x)); * * // Results: diff --git a/src/internal/operators/mergeWith.ts b/src/internal/operators/mergeWith.ts index 776e980b10..b0c81426fb 100644 --- a/src/internal/operators/mergeWith.ts +++ b/src/internal/operators/mergeWith.ts @@ -2,7 +2,7 @@ import { ObservableInputTuple, OperatorFunction } from '../types'; import { merge } from './merge'; /** - * Merge the values from all observables to an single observable result. + * Merge the values from all observables to a single observable result. * * Creates an observable, that when subscribed to, subscribes to the source * observable, and all other sources provided as arguments. All values from @@ -10,7 +10,7 @@ import { merge } from './merge'; * * When all sources complete, the resulting observable will complete. * - * When any one source errors, the resulting observable will error. + * When any source errors, the resulting observable will error. * * ## Example * @@ -23,18 +23,17 @@ import { merge } from './merge'; * const mousemoves$ = fromEvent(document, 'mousemove').pipe(map(() => 'mousemove')); * const dblclicks$ = fromEvent(document, 'dblclick').pipe(map(() => 'dblclick')); * - * mousemoves$.pipe( - * mergeWith(clicks$, dblclicks$), - * ) - * .subscribe(x => console.log(x)); + * mousemoves$ + * .pipe(mergeWith(clicks$, dblclicks$)) + * .subscribe(x => console.log(x)); * * // result (assuming user interactions) - * // "mousemove" - * // "mousemove" - * // "mousemove" - * // "click" - * // "click" - * // "dblclick" + * // 'mousemove' + * // 'mousemove' + * // 'mousemove' + * // 'click' + * // 'click' + * // 'dblclick' * ``` * * @see {@link merge} diff --git a/src/internal/operators/min.ts b/src/internal/operators/min.ts index 218256f91f..bef78d1c50 100644 --- a/src/internal/operators/min.ts +++ b/src/internal/operators/min.ts @@ -15,10 +15,12 @@ import { isFunction } from '../util/isFunction'; * ```ts * import { of, min } from 'rxjs'; * - * of(5, 4, 7, 2, 8).pipe( - * min(), - * ) - * .subscribe(x => console.log(x)); // -> 2 + * of(5, 4, 7, 2, 8) + * .pipe(min()) + * .subscribe(x => console.log(x)); + * + * // Outputs + * // 2 * ``` * * Use a comparer function to get the minimal item @@ -26,19 +28,19 @@ import { isFunction } from '../util/isFunction'; * ```ts * import { of, min } from 'rxjs'; * - * interface Person { - * age: number, - * name: string - * } - *of( - * {age: 7, name: 'Foo'}, - * {age: 5, name: 'Bar'}, - * {age: 9, name: 'Beer'}, + * of( + * { age: 7, name: 'Foo' }, + * { age: 5, name: 'Bar' }, + * { age: 9, name: 'Beer' } * ).pipe( - * min( (a: Person, b: Person) => a.age < b.age ? -1 : 1), + * min((a, b) => a.age < b.age ? -1 : 1) * ) - * .subscribe((x: Person) => console.log(x.name)); // -> 'Bar' + * .subscribe(x => console.log(x.name)); + * + * // Outputs + * // 'Bar' * ``` + * * @see {@link max} * * @param {Function} [comparer] - Optional comparer function that it will use instead of its default to compare the diff --git a/src/internal/operators/observeOn.ts b/src/internal/operators/observeOn.ts index 21867ae4db..1e4e87e5e9 100644 --- a/src/internal/operators/observeOn.ts +++ b/src/internal/operators/observeOn.ts @@ -5,7 +5,6 @@ import { operate } from '../util/lift'; import { OperatorSubscriber } from './OperatorSubscriber'; /** - * * Re-emits all notifications from source Observable with specified scheduler. * * Ensure a specific scheduler is used, from outside of an Observable. @@ -40,11 +39,11 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * const someDiv = document.createElement('div'); * someDiv.style.cssText = 'width: 200px;background: #09c'; * document.body.appendChild(someDiv); - * const intervals = interval(10); // Intervals are scheduled - * // with async scheduler by default... + * const intervals = interval(10); // Intervals are scheduled + * // with async scheduler by default... * intervals.pipe( - * observeOn(animationFrameScheduler), // ...but we will observe on animationFrame - * ) // scheduler to ensure smooth animation. + * observeOn(animationFrameScheduler) // ...but we will observe on animationFrame + * ) // scheduler to ensure smooth animation. * .subscribe(val => { * someDiv.style.height = val + 'px'; * }); diff --git a/src/internal/operators/onErrorResumeNext.ts b/src/internal/operators/onErrorResumeNext.ts index cfab3aa5a2..18ccd07ee6 100644 --- a/src/internal/operators/onErrorResumeNext.ts +++ b/src/internal/operators/onErrorResumeNext.ts @@ -50,18 +50,22 @@ export function onErrorResumeNext( * ```ts * import { of, onErrorResumeNext, map } from 'rxjs'; * - * of(1, 2, 3, 0).pipe( - * map(x => { - * if (x === 0) { throw Error(); } - * return 10 / x; - * }), - * onErrorResumeNext(of(1, 2, 3)), - * ) - * .subscribe( - * val => console.log(val), - * err => console.log(err), // Will never be called. - * () => console.log('that\'s it!') - * ); + * of(1, 2, 3, 0) + * .pipe( + * map(x => { + * if (x === 0) { + * throw Error(); + * } + * + * return 10 / x; + * }), + * onErrorResumeNext(of(1, 2, 3)) + * ) + * .subscribe({ + * next: val => console.log(val), + * error: err => console.log(err), // Will never be called. + * complete: () => console.log('that\'s it!') + * }); * * // Logs: * // 10 @@ -70,13 +74,13 @@ export function onErrorResumeNext( * // 1 * // 2 * // 3 - * // "that's it!" + * // 'that's it!' * ``` * * @see {@link concat} * @see {@link catchError} * - * @param {...ObservableInput} nextSources Observables passed either directly or as an array. + * @param {...ObservableInput} sources Observables passed either directly or as an array. * @return A function that returns an Observable that emits values from source * Observable, but - if it errors - subscribes to the next passed Observable * and so on, until it completes or runs out of Observables. diff --git a/src/internal/operators/pairwise.ts b/src/internal/operators/pairwise.ts index 3476b08250..59b68180f7 100644 --- a/src/internal/operators/pairwise.ts +++ b/src/internal/operators/pairwise.ts @@ -24,17 +24,18 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * ```ts * import { fromEvent, pairwise, map } from 'rxjs'; * - * const clicks = fromEvent(document, 'click'); + * const clicks = fromEvent(document, 'click'); * const pairs = clicks.pipe(pairwise()); * const distance = pairs.pipe( - * map(pair => { - * const x0 = pair[0].clientX; - * const y0 = pair[0].clientY; - * const x1 = pair[1].clientX; - * const y1 = pair[1].clientY; + * map(([first, second]) => { + * const x0 = first.clientX; + * const y0 = first.clientY; + * const x1 = second.clientX; + * const y1 = second.clientY; * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2)); - * }), + * }) * ); + * * distance.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/partition.ts b/src/internal/operators/partition.ts index 7acef8405f..9b02a0c0b9 100644 --- a/src/internal/operators/partition.ts +++ b/src/internal/operators/partition.ts @@ -28,10 +28,13 @@ import { UnaryFunction } from '../types'; * import { fromEvent } from 'rxjs'; * import { partition } from 'rxjs/operators'; * + * const div = document.createElement('div'); + * div.style.cssText = 'width: 200px; height: 200px; background: #09c;'; + * document.body.appendChild(div); + * * const clicks = fromEvent(document, 'click'); - * const parts = clicks.pipe(partition(ev => ev.target.tagName === 'DIV')); - * const clicksOnDivs = parts[0]; - * const clicksElsewhere = parts[1]; + * const [clicksOnDivs, clicksElsewhere] = clicks.pipe(partition(ev => (ev.target).tagName === 'DIV')); + * * clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x)); * clicksElsewhere.subscribe(x => console.log('Other clicked: ', x)); * ``` diff --git a/src/internal/operators/pluck.ts b/src/internal/operators/pluck.ts index 27dadb1332..8825089d38 100644 --- a/src/internal/operators/pluck.ts +++ b/src/internal/operators/pluck.ts @@ -66,6 +66,7 @@ export function pluck(...properties: string[]): OperatorFunction; * * const clicks = fromEvent(document, 'click'); * const tagNames = clicks.pipe(pluck('target', 'tagName')); + * * tagNames.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/publish.ts b/src/internal/operators/publish.ts index b6f6b495ed..105cd36729 100644 --- a/src/internal/operators/publish.ts +++ b/src/internal/operators/publish.ts @@ -49,9 +49,8 @@ export function publish>(selector: (shared: Ob * ```ts * import { zip, interval, of, map, publish, merge, tap } from 'rxjs'; * - * const source$ = zip(interval(2000), of(1, 2, 3, 4, 5, 6, 7, 8, 9)).pipe( - * map(values => values[1]) - * ); + * const source$ = zip(interval(2000), of(1, 2, 3, 4, 5, 6, 7, 8, 9)) + * .pipe(map(([, number]) => number)); * * source$ * .pipe( @@ -59,7 +58,7 @@ export function publish>(selector: (shared: Ob * merge( * multicasted$.pipe(tap(x => console.log('Stream 1:', x))), * multicasted$.pipe(tap(x => console.log('Stream 2:', x))), - * multicasted$.pipe(tap(x => console.log('Stream 3:', x))), + * multicasted$.pipe(tap(x => console.log('Stream 3:', x))) * ) * ) * ) diff --git a/src/internal/operators/publishLast.ts b/src/internal/operators/publishLast.ts index fa6d0d3c7e..ded47fb523 100644 --- a/src/internal/operators/publishLast.ts +++ b/src/internal/operators/publishLast.ts @@ -18,35 +18,37 @@ import { UnaryFunction } from '../types'; * ## Example * * ```ts - * import { interval, publishLast, tap, take } from 'rxjs'; + * import { ConnectableObservable, interval, publishLast, tap, take } from 'rxjs'; * - * const connectable = - * interval(1000) - * .pipe( - * tap(x => console.log("side effect", x)), - * take(3), - * publishLast()); + * const connectable = >interval(1000) + * .pipe( + * tap(x => console.log('side effect', x)), + * take(3), + * publishLast() + * ); * - * connectable.subscribe( - * x => console.log( "Sub. A", x), - * err => console.log("Sub. A Error", err), - * () => console.log( "Sub. A Complete")); + * connectable.subscribe({ + * next: x => console.log('Sub. A', x), + * error: err => console.log('Sub. A Error', err), + * complete: () => console.log('Sub. A Complete') + * }); * - * connectable.subscribe( - * x => console.log( "Sub. B", x), - * err => console.log("Sub. B Error", err), - * () => console.log( "Sub. B Complete")); + * connectable.subscribe({ + * next: x => console.log('Sub. B', x), + * error: err => console.log('Sub. B Error', err), + * complete: () => console.log('Sub. B Complete') + * }); * * connectable.connect(); * * // Results: - * // "side effect 0" - * // "side effect 1" - * // "side effect 2" - * // "Sub. A 2" - * // "Sub. B 2" - * // "Sub. A Complete" - * // "Sub. B Complete" + * // 'side effect 0' - after one second + * // 'side effect 1' - after two seconds + * // 'side effect 2' - after three seconds + * // 'Sub. A 2' - immediately after 'side effect 2' + * // 'Sub. B 2' + * // 'Sub. A Complete' + * // 'Sub. B Complete' * ``` * * @see {@link ConnectableObservable} diff --git a/src/internal/operators/reduce.ts b/src/internal/operators/reduce.ts index 43ba65b891..603ce0f611 100644 --- a/src/internal/operators/reduce.ts +++ b/src/internal/operators/reduce.ts @@ -36,12 +36,13 @@ export function reduce(accumulator: (acc: A | S, value: V, index: n * ```ts * import { fromEvent, takeUntil, interval, mapTo, reduce } from 'rxjs'; * - * const clicksInFiveSeconds = fromEvent(document, 'click').pipe( - * takeUntil(interval(5000)), - * ); + * const clicksInFiveSeconds = fromEvent(document, 'click') + * .pipe(takeUntil(interval(5000))); + * * const ones = clicksInFiveSeconds.pipe(mapTo(1)); * const seed = 0; * const count = ones.pipe(reduce((acc, one) => acc + one, seed)); + * * count.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/refCount.ts b/src/internal/operators/refCount.ts index 1b4f6baeb4..222a180fca 100644 --- a/src/internal/operators/refCount.ts +++ b/src/internal/operators/refCount.ts @@ -31,13 +31,13 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * // Turn the interval observable into a ConnectableObservable (hot) * const refCountInterval = interval(400).pipe( - * tap((num) => console.log(`refCount ${num}`)), + * tap(num => console.log(`refCount ${ num }`)), * publish(), * refCount() * ); * * const publishedInterval = interval(400).pipe( - * tap((num) => console.log(`publish ${num}`)), + * tap(num => console.log(`publish ${ num }`)), * publish() * ); * @@ -45,7 +45,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * refCountInterval.subscribe(); * // 'refCount 0' -----> 'refCount 1' -----> etc * // All subscriptions will receive the same value and the tap (and - * // every other operator) before the publish operator will be executed + * // every other operator) before the `publish` operator will be executed * // only once per event independently of the number of subscriptions. * * publishedInterval.subscribe(); diff --git a/src/internal/operators/repeat.ts b/src/internal/operators/repeat.ts index 519174b926..4786d40b3f 100644 --- a/src/internal/operators/repeat.ts +++ b/src/internal/operators/repeat.ts @@ -24,13 +24,14 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * import { of, repeat } from 'rxjs'; * * const source = of('Repeat message'); - * const example = source.pipe(repeat(3)); - * example.subscribe(x => console.log(x)); + * const result = source.pipe(repeat(3)); + * + * result.subscribe(x => console.log(x)); * * // Results - * // Repeat message - * // Repeat message - * // Repeat message + * // 'Repeat message' + * // 'Repeat message' + * // 'Repeat message' * ``` * * Repeat 3 values, 2 times @@ -39,8 +40,9 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * import { interval, take, repeat } from 'rxjs'; * * const source = interval(1000); - * const example = source.pipe(take(3), repeat(2)); - * example.subscribe(x => console.log(x)); + * const result = source.pipe(take(3), repeat(2)); + * + * result.subscribe(x => console.log(x)); * * // Results every second * // 0 diff --git a/src/internal/operators/repeatWhen.ts b/src/internal/operators/repeatWhen.ts index 7962e585dc..dadc7bb406 100644 --- a/src/internal/operators/repeatWhen.ts +++ b/src/internal/operators/repeatWhen.ts @@ -24,9 +24,11 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * const source = of('Repeat message'); * const documentClick$ = fromEvent(document, 'click'); * - * source.pipe(repeatWhen(() => documentClick$) - * ).subscribe(data => console.log(data)) + * const result = source.pipe(repeatWhen(() => documentClick$)); + * + * result.subscribe(data => console.log(data)) * ``` + * * @see {@link repeat} * @see {@link retry} * @see {@link retryWhen} diff --git a/src/internal/operators/retry.ts b/src/internal/operators/retry.ts index 5dd3884781..9b5012cfcf 100644 --- a/src/internal/operators/retry.ts +++ b/src/internal/operators/retry.ts @@ -34,9 +34,9 @@ export interface RetryConfig { * ![](retry.png) * * Any and all items emitted by the source Observable will be emitted by the resulting Observable, even those emitted - * during failed subscriptions. For example, if an Observable fails at first but emits [1, 2] then succeeds the second - * time and emits: [1, 2, 3, 4, 5] then the complete stream of emissions and notifications - * would be: [1, 2, 1, 2, 3, 4, 5, `complete`]. + * during failed subscriptions. For example, if an Observable fails at first but emits `[1, 2]` then succeeds the second + * time and emits: `[1, 2, 3, 4, 5]` then the complete stream of emissions and notifications + * would be: `[1, 2, 1, 2, 3, 4, 5, complete]`. * * ## Example * @@ -44,27 +44,21 @@ export interface RetryConfig { * import { interval, mergeMap, throwError, of, retry } from 'rxjs'; * * const source = interval(1000); - * const example = source.pipe( - * mergeMap(val => { - * if(val > 5){ - * return throwError('Error!'); - * } - * return of(val); - * }), - * //retry 2 times on error - * retry(2) + * const result = source.pipe( + * mergeMap(val => val > 5 ? throwError(() => 'Error!') : of(val)), + * retry(2) // retry 2 times on error * ); * - * const subscribe = example.subscribe({ - * next: val => console.log(val), - * error: val => console.log(`${val}: Retried 2 times then quit!`) + * result.subscribe({ + * next: value => console.log(value), + * error: err => console.log(`${ err }: Retried 2 times then quit!`) * }); * * // Output: * // 0..1..2..3..4..5.. * // 0..1..2..3..4..5.. * // 0..1..2..3..4..5.. - * // "Error!: Retried 2 times then quit!" + * // 'Error!: Retried 2 times then quit!' * ``` * * @see {@link retryWhen} diff --git a/src/internal/operators/retryWhen.ts b/src/internal/operators/retryWhen.ts index a08abee139..042ef3c7ce 100644 --- a/src/internal/operators/retryWhen.ts +++ b/src/internal/operators/retryWhen.ts @@ -22,35 +22,35 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * import { interval, map, retryWhen, tap, delayWhen, timer } from 'rxjs'; * * const source = interval(1000); - * const example = source.pipe( - * map(val => { - * if (val > 5) { + * const result = source.pipe( + * map(value => { + * if (value > 5) { * // error will be picked up by retryWhen - * throw val; + * throw value; * } - * return val; + * return value; * }), * retryWhen(errors => * errors.pipe( * // log error message - * tap(val => console.log(`Value ${val} was too high!`)), + * tap(value => console.log(`Value ${ value } was too high!`)), * // restart in 5 seconds - * delayWhen(val => timer(val * 1000)) + * delayWhen(value => timer(value * 1000)) * ) * ) * ); * - * const subscribe = example.subscribe(val => console.log(val)); + * result.subscribe(value => console.log(value)); * * // results: - * // 0 - * // 1 - * // 2 - * // 3 - * // 4 - * // 5 - * // "Value 6 was too high!" - * // --Wait 5 seconds then repeat + * // 0 + * // 1 + * // 2 + * // 3 + * // 4 + * // 5 + * // 'Value 6 was too high!' + * // - Wait 5 seconds then repeat * ``` * * @see {@link retry} diff --git a/src/internal/operators/sample.ts b/src/internal/operators/sample.ts index bd90127531..446bdccd3d 100644 --- a/src/internal/operators/sample.ts +++ b/src/internal/operators/sample.ts @@ -29,6 +29,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * const seconds = interval(1000); * const clicks = fromEvent(document, 'click'); * const result = seconds.pipe(sample(clicks)); + * * result.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/sampleTime.ts b/src/internal/operators/sampleTime.ts index f36ece8dca..6558fa03ab 100644 --- a/src/internal/operators/sampleTime.ts +++ b/src/internal/operators/sampleTime.ts @@ -28,6 +28,7 @@ import { interval } from '../observable/interval'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(sampleTime(1000)); + * * result.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/scan.ts b/src/internal/operators/scan.ts index 8b548ab2ea..e97e967e59 100644 --- a/src/internal/operators/scan.ts +++ b/src/internal/operators/scan.ts @@ -59,9 +59,9 @@ export function scan(accumulator: (acc: A | S, value: V, index: number) * import { interval, scan, map, startWith } from 'rxjs'; * * const firstTwoFibs = [0, 1]; - * // An endless stream of Fibonnaci numbers. - * const fibonnaci$ = interval(1000).pipe( - * // Scan to get the fibonnaci numbers (after 0, 1) + * // An endless stream of Fibonacci numbers. + * const fibonacci$ = interval(1000).pipe( + * // Scan to get the fibonacci numbers (after 0, 1) * scan(([a, b]) => [b, a + b], firstTwoFibs), * // Get the second number in the tuple, it's the one you calculated * map(([, n]) => n), @@ -69,10 +69,9 @@ export function scan(accumulator: (acc: A | S, value: V, index: number) * startWith(...firstTwoFibs) * ); * - * fibonnaci$.subscribe(console.log); + * fibonacci$.subscribe(console.log); * ``` * - * * @see {@link expand} * @see {@link mergeScan} * @see {@link reduce} diff --git a/src/internal/operators/sequenceEqual.ts b/src/internal/operators/sequenceEqual.ts index a34a4bcc71..e9d035094f 100644 --- a/src/internal/operators/sequenceEqual.ts +++ b/src/internal/operators/sequenceEqual.ts @@ -41,12 +41,10 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * 'Enter', // no start key, clearly. * ]); * - * const keys = fromEvent(document, 'keyup').pipe(map(e => e.code)); + * const keys = fromEvent(document, 'keyup').pipe(map(e => e.code)); * const matches = keys.pipe( * bufferCount(11, 1), - * mergeMap( - * last11 => from(last11).pipe(sequenceEqual(codes)), - * ), + * mergeMap(last11 => from(last11).pipe(sequenceEqual(codes))) * ); * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched)); * ``` diff --git a/src/internal/operators/share.ts b/src/internal/operators/share.ts index 9b75a8dbcf..cef095eb58 100644 --- a/src/internal/operators/share.ts +++ b/src/internal/operators/share.ts @@ -107,7 +107,12 @@ export function share(options: ShareConfig): MonoTypeOperatorFunction; * ```ts * import { interval, take, share, timer } from 'rxjs'; * - * const source = interval(1000).pipe(take(3), share({ resetOnRefCountZero: () => timer(1000) })); + * const source = interval(1000).pipe( + * take(3), + * share({ + * resetOnRefCountZero: () => timer(1000) + * }) + * ); * * const subscriptionOne = source.subscribe(x => console.log('subscription 1: ', x)); * setTimeout(() => subscriptionOne.unsubscribe(), 1300); diff --git a/src/internal/operators/shareReplay.ts b/src/internal/operators/shareReplay.ts index 8f20e922d8..efb144240b 100644 --- a/src/internal/operators/shareReplay.ts +++ b/src/internal/operators/shareReplay.ts @@ -45,14 +45,42 @@ export function shareReplay(bufferSize?: number, windowTime?: number, schedul * ```ts * import { interval, take, shareReplay } from 'rxjs'; * - * const obs$ = interval(1000); - * const shared$ = obs$.pipe( - * take(4), + * const shared$ = interval(2000).pipe( + * take(6), * shareReplay(3) * ); + * * shared$.subscribe(x => console.log('sub A: ', x)); * shared$.subscribe(y => console.log('sub B: ', y)); * + * setTimeout(() => { + * shared$.subscribe(y => console.log('sub C: ', y)); + * }, 11000); + * + * // Logs: + * // (after ~2000 ms) + * // sub A: 0 + * // sub B: 0 + * // (after ~4000 ms) + * // sub A: 1 + * // sub B: 1 + * // (after ~6000 ms) + * // sub A: 2 + * // sub B: 2 + * // (after ~8000 ms) + * // sub A: 3 + * // sub B: 3 + * // (after ~10000 ms) + * // sub A: 4 + * // sub B: 4 + * // (after ~11000 ms, sub C gets the last 3 values) + * // sub C: 2 + * // sub C: 3 + * // sub C: 4 + * // (after ~12000 ms) + * // sub A: 5 + * // sub B: 5 + * // sub C: 5 * ``` * * Example for `refCount` usage diff --git a/src/internal/operators/single.ts b/src/internal/operators/single.ts index 7f13eb2d6f..a17dfefae0 100644 --- a/src/internal/operators/single.ts +++ b/src/internal/operators/single.ts @@ -40,11 +40,10 @@ export function single(predicate?: (value: T, index: number, source: Observab * { name: 'Lily' } * ); * - * source1.pipe( - * single(x => x.name.startsWith('B')) - * ) - * .subscribe(x => console.log(x)); - * // Emits "Ben" + * source1 + * .pipe(single(x => x.name.startsWith('B'))) + * .subscribe(x => console.log(x)); + * // Emits 'Ben' * * * const source2 = of( @@ -54,10 +53,9 @@ export function single(predicate?: (value: T, index: number, source: Observab * { name: 'Lincoln' } * ); * - * source2.pipe( - * single(x => x.name.startsWith('B')) - * ) - * .subscribe(x => console.log(x)); + * source2 + * .pipe(single(x => x.name.startsWith('B'))) + * .subscribe({ error: err => console.error(err) }); * // Error emitted: SequenceError('Too many values match') * * @@ -68,10 +66,9 @@ export function single(predicate?: (value: T, index: number, source: Observab * { name: 'Lincoln' } * ); * - * source3.pipe( - * single(x => x.name.startsWith('B')) - * ) - * .subscribe(x => console.log(x)); + * source3 + * .pipe(single(x => x.name.startsWith('B'))) + * .subscribe({ error: err => console.error(err) }); * // Error emitted: NotFoundError('No values match') * ``` * @@ -84,7 +81,7 @@ export function single(predicate?: (value: T, index: number, source: Observab * callback if the Observable completes before any `next` notification was sent. * @throws {SequenceError} Delivers a SequenceError if more than one value is emitted that matches the * provided predicate. If no predicate is provided, will deliver a SequenceError if more - * that one value comes from the source + * than one value comes from the source * @param {Function} predicate - A predicate function to evaluate items emitted by the source Observable. * @return A function that returns an Observable that emits the single item * emitted by the source Observable that matches the predicate. diff --git a/src/internal/operators/skip.ts b/src/internal/operators/skip.ts index 928ca760d3..76e3eff2df 100644 --- a/src/internal/operators/skip.ts +++ b/src/internal/operators/skip.ts @@ -16,12 +16,13 @@ import { filter } from './filter'; * ```ts * import { interval, skip } from 'rxjs'; * - * //emit every half second + * // emit every half second * const source = interval(500); - * //skip the first 10 emitted values - * const example = source.pipe(skip(10)); - * //output: 10...11...12...13........ - * const subscribe = example.subscribe(val => console.log(val)); + * // skip the first 10 emitted values + * const result = source.pipe(skip(10)); + * + * result.subscribe(value => console.log(value)); + * // output: 10...11...12...13... * ``` * * @see {@link last} diff --git a/src/internal/operators/skipUntil.ts b/src/internal/operators/skipUntil.ts index 0defc487f6..c693f83ede 100644 --- a/src/internal/operators/skipUntil.ts +++ b/src/internal/operators/skipUntil.ts @@ -8,7 +8,7 @@ import { noop } from '../util/noop'; /** * Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item. * - * The `skipUntil` operator causes the observable stream to skip the emission of values ​​until the passed in observable emits the first value. + * The `skipUntil` operator causes the observable stream to skip the emission of values until the passed in observable emits the first value. * This can be particularly useful in combination with user interactions, responses of http requests or waiting for specific times to pass by. * * ![](skipUntil.png) @@ -33,7 +33,7 @@ import { noop } from '../util/noop'; * ); * // clicked at 4.6s. output: 5...6...7...8........ or * // clicked at 7.3s. output: 8...9...10..11....... - * const subscribe = emitAfterClick.subscribe(value => console.log(value)); + * emitAfterClick.subscribe(value => console.log(value)); * ``` * * @see {@link last} diff --git a/src/internal/operators/skipWhile.ts b/src/internal/operators/skipWhile.ts index 5973bce763..e9323fe8bd 100644 --- a/src/internal/operators/skipWhile.ts +++ b/src/internal/operators/skipWhile.ts @@ -24,9 +24,9 @@ export function skipWhile(predicate: (value: T, index: number) => boolean): M * * const source = from(['Green Arrow', 'SuperMan', 'Flash', 'SuperGirl', 'Black Canary']) * // Skip the heroes until SuperGirl - * const example = source.pipe(skipWhile((hero) => hero !== 'SuperGirl')); + * const example = source.pipe(skipWhile(hero => hero !== 'SuperGirl')); * // output: SuperGirl, Black Canary - * example.subscribe((femaleHero) => console.log(femaleHero)); + * example.subscribe(femaleHero => console.log(femaleHero)); * ``` * * Skip values from the array until index 5 @@ -37,7 +37,7 @@ export function skipWhile(predicate: (value: T, index: number) => boolean): M * const source = from([1, 2, 3, 4, 5, 6, 7, 9, 10]); * const example = source.pipe(skipWhile((_, i) => i !== 5)); * // output: 6, 7, 9, 10 - * example.subscribe((val) => console.log(val)); + * example.subscribe(value => console.log(value)); * ``` * * @see {@link last} diff --git a/src/internal/operators/startWith.ts b/src/internal/operators/startWith.ts index 09ce423b8a..8c11ddb52b 100644 --- a/src/internal/operators/startWith.ts +++ b/src/internal/operators/startWith.ts @@ -44,8 +44,8 @@ export function startWith(...values: A): * .subscribe(x => console.log(x)); * * // results: - * // "timer start" - * // "timer emit" + * // 'timer start' + * // 'timer emit' * ``` * * @param values Items you want the modified Observable to emit first. diff --git a/src/internal/operators/subscribeOn.ts b/src/internal/operators/subscribeOn.ts index 8f50fd3bd7..17240d0488 100644 --- a/src/internal/operators/subscribeOn.ts +++ b/src/internal/operators/subscribeOn.ts @@ -33,7 +33,7 @@ import { operate } from '../util/lift'; * * Both Observable `a` and `b` will emit their values directly and synchronously once they are subscribed to. * - * If we instead use the `subscribeOn` operator declaring that we want to use the {@link asyncScheduler} for values emited by Observable `a`: + * If we instead use the `subscribeOn` operator declaring that we want to use the {@link asyncScheduler} for values emitted by Observable `a`: * * ```ts * import { of, subscribeOn, asyncScheduler, merge } from 'rxjs'; diff --git a/src/internal/operators/switchAll.ts b/src/internal/operators/switchAll.ts index c20ec4274b..69e9cbb3a7 100644 --- a/src/internal/operators/switchAll.ts +++ b/src/internal/operators/switchAll.ts @@ -27,11 +27,11 @@ import { identity } from '../util/identity'; * import { fromEvent, tap, map, interval, switchAll } from 'rxjs'; * * const clicks = fromEvent(document, 'click').pipe(tap(() => console.log('click'))); - * const source = clicks.pipe(map((ev) => interval(1000))); + * const source = clicks.pipe(map(() => interval(1000))); * - * source.pipe( - * switchAll() - * ).subscribe(x => console.log(x)); + * source + * .pipe(switchAll()) + * .subscribe(x => console.log(x)); * * // Output * // click @@ -60,7 +60,6 @@ import { identity } from '../util/identity'; * Observable into a first-order Observable producing values only from the most * recent Observable sequence. */ - export function switchAll>(): OperatorFunction> { return switchMap(identity); } diff --git a/src/internal/operators/switchMap.ts b/src/internal/operators/switchMap.ts index c59748e6e1..37ece8b2d2 100644 --- a/src/internal/operators/switchMap.ts +++ b/src/internal/operators/switchMap.ts @@ -45,7 +45,7 @@ export function switchMap>( * ```ts * import { of, switchMap } from 'rxjs'; * - * const switched = of(1, 2, 3).pipe(switchMap((x: number) => of(x, x ** 2, x ** 3))); + * const switched = of(1, 2, 3).pipe(switchMap(x => of(x, x ** 2, x ** 3))); * switched.subscribe(x => console.log(x)); * // outputs * // 1 @@ -54,7 +54,9 @@ export function switchMap>( * // 2 * // 4 * // 8 - * // ... and so on + * // 3 + * // 9 + * // 27 * ``` * * Restart an interval Observable on every click event @@ -63,7 +65,7 @@ export function switchMap>( * import { fromEvent, switchMap, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); - * const result = clicks.pipe(switchMap((ev) => interval(1000))); + * const result = clicks.pipe(switchMap(() => interval(1000))); * result.subscribe(x => console.log(x)); * ``` * @@ -73,7 +75,7 @@ export function switchMap>( * @see {@link switchAll} * @see {@link switchMapTo} * - * @param {function(value: T, ?index: number): ObservableInput} project A function + * @param {function(value: T, index: number): ObservableInput} project A function * that, when applied to an item emitted by the source Observable, returns an * Observable. * @return A function that returns an Observable that emits the result of diff --git a/src/internal/operators/takeWhile.ts b/src/internal/operators/takeWhile.ts index 5a06e2af30..e42f621d35 100644 --- a/src/internal/operators/takeWhile.ts +++ b/src/internal/operators/takeWhile.ts @@ -36,7 +36,7 @@ export function takeWhile(predicate: (value: T, index: number) => boolean, in * ```ts * import { fromEvent, takeWhile } from 'rxjs'; * - * const clicks = fromEvent(document, 'click'); + * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(takeWhile(ev => ev.clientX > 200)); * result.subscribe(x => console.log(x)); * ``` diff --git a/src/internal/operators/tap.ts b/src/internal/operators/tap.ts index f4a9143d51..890d9bcbca 100644 --- a/src/internal/operators/tap.ts +++ b/src/internal/operators/tap.ts @@ -65,16 +65,16 @@ export function tap( * ```ts * import { of, tap } from 'rxjs'; * - * const source = of(1, 2, 3, 4, 5) + * const source = of(1, 2, 3, 4, 5); * * source.pipe( - * tap(n => { - * if (n > 3) { - * throw new TypeError(`Value ${n} is greater than 3`) - * } - * }) + * tap(n => { + * if (n > 3) { + * throw new TypeError(`Value ${ n } is greater than 3`); + * } + * }) * ) - * .subscribe(console.log); + * .subscribe({ next: console.log, error: err => console.log(err.message) }); * ``` * * We want to know when an observable completes before moving on to the next observable. The system @@ -86,13 +86,11 @@ export function tap( * import { of, concatMap, interval, take, map, tap } from 'rxjs'; * * of(1, 2, 3).pipe( - * concatMap(n => interval(1000).pipe( - * take(Math.round(Math.random() * 10)), - * map(() => 'X'), - * tap({ - * complete: () => console.log(`Done with ${n}`) - * }) - * )) + * concatMap(n => interval(1000).pipe( + * take(Math.round(Math.random() * 10)), + * map(() => 'X'), + * tap({ complete: () => console.log(`Done with ${ n }`) }) + * )) * ) * .subscribe(console.log); * ``` diff --git a/src/internal/operators/throttle.ts b/src/internal/operators/throttle.ts index 978727c006..8dd60ae9aa 100644 --- a/src/internal/operators/throttle.ts +++ b/src/internal/operators/throttle.ts @@ -42,7 +42,8 @@ export const defaultThrottleConfig: ThrottleConfig = { * import { fromEvent, throttle, interval } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); - * const result = clicks.pipe(throttle(ev => interval(1000))); + * const result = clicks.pipe(throttle(() => interval(1000))); + * * result.subscribe(x => console.log(x)); * ``` * diff --git a/src/internal/operators/throttleTime.ts b/src/internal/operators/throttleTime.ts index 95ef198899..54461bf6a1 100644 --- a/src/internal/operators/throttleTime.ts +++ b/src/internal/operators/throttleTime.ts @@ -32,6 +32,7 @@ import { timer } from '../observable/timer'; * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(throttleTime(1000)); + * * result.subscribe(x => console.log(x)); * ``` * @@ -44,19 +45,19 @@ import { timer } from '../observable/timer'; * ```ts * import { fromEvent, throttleTime, asyncScheduler } from 'rxjs'; * - * // defaultThottleConfig = { leading: true, trailing: false } + * // defaultThrottleConfig = { leading: true, trailing: false }; * const throttleConfig = { * leading: false, * trailing: true - * } + * }; * * const click = fromEvent(document, 'click'); * const doubleClick = click.pipe( * throttleTime(400, asyncScheduler, throttleConfig) * ); * - * doubleClick.subscribe((throttleValue: Event) => { - * console.log(`Double-clicked! Timestamp: ${throttleValue.timeStamp}`); + * doubleClick.subscribe(event => { + * console.log(`Double-clicked! Timestamp: ${ event.timeStamp }`); * }); * ``` * diff --git a/src/internal/operators/throwIfEmpty.ts b/src/internal/operators/throwIfEmpty.ts index 6d41bfbead..5075d66446 100644 --- a/src/internal/operators/throwIfEmpty.ts +++ b/src/internal/operators/throwIfEmpty.ts @@ -21,13 +21,15 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * * click$.pipe( * takeUntil(timer(1000)), - * throwIfEmpty( - * () => new Error('the document was not clicked within 1 second') - * ), + * throwIfEmpty(() => new Error('The document was not clicked within 1 second')) * ) * .subscribe({ - * next() { console.log('The button was clicked'); }, - * error(err) { console.error(err); } + * next() { + * console.log('The document was clicked'); + * }, + * error(err) { + * console.error(err.message); + * } * }); * ``` * diff --git a/src/internal/operators/timeInterval.ts b/src/internal/operators/timeInterval.ts index b4eaa6947e..9becdc79dd 100644 --- a/src/internal/operators/timeInterval.ts +++ b/src/internal/operators/timeInterval.ts @@ -6,7 +6,6 @@ import { defer } from '../observable/defer'; import { map } from './map'; /** - * * Emits an object containing the current value, and the time that has * passed between emitting the current value and the previous value, which is * calculated by using the provided `scheduler`'s `now()` method to retrieve @@ -28,25 +27,17 @@ import { map } from './map'; * * const seconds = interval(1000); * - * seconds.pipe(timeInterval()) - * .subscribe({ - * next: value => console.log(value), - * error: err => console.log(err), - * }); - * - * seconds.pipe(timeout(900)) - * .subscribe({ - * next: value => console.log(value), - * error: err => console.log(err), - * }); + * seconds + * .pipe(timeInterval()) + * .subscribe(value => console.log(value)); * * // NOTE: The values will never be this precise, * // intervals created with `interval` or `setInterval` * // are non-deterministic. * - * // {value: 0, interval: 1000} - * // {value: 1, interval: 1000} - * // {value: 2, interval: 1000} + * // { value: 0, interval: 1000 } + * // { value: 1, interval: 1000 } + * // { value: 2, interval: 1000 } * ``` * * @param {SchedulerLike} [scheduler] Scheduler used to get the current time. diff --git a/src/internal/operators/timeout.ts b/src/internal/operators/timeout.ts index 41b2d7a2b9..ea67cd1300 100644 --- a/src/internal/operators/timeout.ts +++ b/src/internal/operators/timeout.ts @@ -125,22 +125,22 @@ export const TimeoutError: TimeoutErrorCtor = createErrorClass( * * class CustomTimeoutError extends Error { * constructor() { - * super('It was too slow'); - * this.name = 'CustomTimeoutError'; + * super('It was too slow'); + * this.name = 'CustomTimeoutError'; * } * } * * const slow$ = interval(900); * * slow$.pipe( - * timeout({ - * each: 1000, - * with: () => throwError(new CustomTimeoutError()) - * }) + * timeout({ + * each: 1000, + * with: () => throwError(() => new CustomTimeoutError()) + * }) * ) * .subscribe({ - * error: console.error - * }) + * error: console.error + * }); * ``` * * Switch to a faster observable if your source is slow. @@ -152,12 +152,12 @@ export const TimeoutError: TimeoutErrorCtor = createErrorClass( * const fast$ = interval(500); * * slow$.pipe( - * timeout({ - * each: 1000, - * with: () => fast$, - * }) + * timeout({ + * each: 1000, + * with: () => fast$, + * }) * ) - * .subscribe(console.log) + * .subscribe(console.log); * ``` * @param config The configuration for the timeout. */ @@ -204,12 +204,15 @@ export function timeout, M = unknown>( * import { interval, timeout } from 'rxjs'; * * // A random interval that lasts between 0 and 10 seconds per tick - * const source$ = interval(Math.round(Math.random() * 10000)); + * const source$ = interval(Math.round(Math.random() * 10_000)); * * source$.pipe( - * timeout({ first: 5000 }) + * timeout({ first: 5_000 }) * ) - * .subscribe(console.log); + * .subscribe({ + * next: console.log, + * error: console.error + * }); * ``` * * Emit a {@link TimeoutError} if the source waits longer than 5 seconds between any two values or the first value @@ -218,17 +221,18 @@ export function timeout, M = unknown>( * ```ts * import { timer, timeout, expand } from 'rxjs'; * - * const getRandomTime = () => Math.round(Math.random() * 10000); + * const getRandomTime = () => Math.round(Math.random() * 10_000); * * // An observable that waits a random amount of time between each delivered value - * const source$ = timer(getRandomTime()).pipe( - * expand(() => timer(getRandomTime())) - * ) - * - * source$.pipe( - * timeout({ each: 5000 }) - * ) - * .subscribe(console.log); + * const source$ = timer(getRandomTime()) + * .pipe(expand(() => timer(getRandomTime()))); + * + * source$ + * .pipe(timeout({ each: 5_000 })) + * .subscribe({ + * next: console.log, + * error: console.error + * }); * ``` * * Emit a {@link TimeoutError} if the source does not emit before 7 seconds, _or_ if the source waits longer than @@ -237,17 +241,18 @@ export function timeout, M = unknown>( * ```ts * import { timer, timeout, expand } from 'rxjs'; * - * const getRandomTime = () => Math.round(Math.random() * 10000); + * const getRandomTime = () => Math.round(Math.random() * 10_000); * * // An observable that waits a random amount of time between each delivered value - * const source$ = timer(getRandomTime()).pipe( - * expand(() => timer(getRandomTime())) - * ) - * - * source$.pipe( - * timeout({ first: 7000, each: 5000 }) - * ) - * .subscribe(console.log); + * const source$ = timer(getRandomTime()) + * .pipe(expand(() => timer(getRandomTime()))); + * + * source$ + * .pipe(timeout({ first: 7_000, each: 5_000 })) + * .subscribe({ + * next: console.log, + * error: console.error + * }); * ``` */ export function timeout(config: Omit, 'with'>): OperatorFunction; diff --git a/src/internal/operators/timeoutWith.ts b/src/internal/operators/timeoutWith.ts index e1cc739f3b..7f9078f301 100644 --- a/src/internal/operators/timeoutWith.ts +++ b/src/internal/operators/timeoutWith.ts @@ -20,7 +20,7 @@ import { timeout } from './timeout'; export function timeoutWith(dueBy: Date, switchTo: ObservableInput, scheduler?: SchedulerLike): OperatorFunction; /** - * When the passed timespan ellapses before the source emits any given value, it will unsubscribe from the source, + * When the passed timespan elapses before the source emits any given value, it will unsubscribe from the source, * and switch the subscription to another observable. * * Used to switch to a different observable if your source is being slow @@ -42,10 +42,9 @@ export function timeoutWith(dueBy: Date, switchTo: ObservableInput, sch * const slow$ = interval(1000); * const faster$ = interval(500); * - * slow$.pipe( - * timeoutWith(900, faster$) - * ) - * .subscribe(console.log) + * slow$ + * .pipe(timeoutWith(900, faster$)) + * .subscribe(console.log); * ``` * * Emit your own custom timeout error @@ -55,19 +54,18 @@ export function timeoutWith(dueBy: Date, switchTo: ObservableInput, sch * * class CustomTimeoutError extends Error { * constructor() { - * super('It was too slow'); - * this.name = 'CustomTimeoutError'; + * super('It was too slow'); + * this.name = 'CustomTimeoutError'; * } * } * - * const slow = interval(1000); + * const slow$ = interval(1000); * - * slow$.pipe( - * timeoutWith(900, throwError(new CustomTimeoutError())) - * ) - * .subscribe({ - * error: console.error - * }) + * slow$ + * .pipe(timeoutWith(900, throwError(() => new CustomTimeoutError()))) + * .subscribe({ + * error: err => console.error(err.message) + * }); * ``` * * @see {@link timeout} diff --git a/src/internal/operators/timestamp.ts b/src/internal/operators/timestamp.ts index 954ca48db5..bb388de0de 100644 --- a/src/internal/operators/timestamp.ts +++ b/src/internal/operators/timestamp.ts @@ -8,7 +8,7 @@ import { map } from './map'; * The `timestamp` operator maps the *source* observable stream to an object of type * `{value: T, timestamp: R}`. The properties are generically typed. The `value` property contains the value * and type of the *source* observable. The `timestamp` is generated by the schedulers `now` function. By - * default it uses the *async* scheduler which simply returns `Date.now()` (milliseconds since 1970/01/01 + * default, it uses the `asyncScheduler` which simply returns `Date.now()` (milliseconds since 1970/01/01 * 00:00:00:000) and therefore is of type `number`. * * ![](timestamp.png) @@ -24,7 +24,7 @@ import { map } from './map'; * timestamp() * ); * - * // Emits data of type {value: MouseEvent, timestamp: number} + * // Emits data of type { value: PointerEvent, timestamp: number } * clickWithTimestamp.subscribe(data => { * console.log(data); * }); diff --git a/src/internal/operators/toArray.ts b/src/internal/operators/toArray.ts index d2f26c2063..8c60aced2b 100644 --- a/src/internal/operators/toArray.ts +++ b/src/internal/operators/toArray.ts @@ -26,7 +26,7 @@ const arrReducer = (arr: any[], value: any) => (arr.push(value), arr); * toArray() * ); * - * const subscribe = example.subscribe(val => console.log(val)); + * example.subscribe(value => console.log(value)); * * // output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] * ``` diff --git a/src/internal/operators/window.ts b/src/internal/operators/window.ts index 535f806ad6..c379ba4c2d 100644 --- a/src/internal/operators/window.ts +++ b/src/internal/operators/window.ts @@ -27,15 +27,16 @@ import { noop } from '../util/noop'; * ```ts * import { fromEvent, interval, window, map, take, mergeAll } from 'rxjs'; * - * const clicks = fromEvent(document, 'click'); - * const sec = interval(1000); - * const result = clicks.pipe( - * window(sec), - * map(win => win.pipe(take(2))), // each window has at most 2 emissions - * mergeAll(), // flatten the Observable-of-Observables - * ); - * result.subscribe(x => console.log(x)); + * const clicks = fromEvent(document, 'click'); + * const sec = interval(1000); + * const result = clicks.pipe( + * window(sec), + * map(win => win.pipe(take(2))), // take at most 2 emissions from each window + * mergeAll() // flatten the Observable-of-Observables + * ); + * result.subscribe(x => console.log(x)); * ``` + * * @see {@link windowCount} * @see {@link windowTime} * @see {@link windowToggle} diff --git a/src/internal/operators/windowCount.ts b/src/internal/operators/windowCount.ts index 9f2aa886f6..65df25bd73 100644 --- a/src/internal/operators/windowCount.ts +++ b/src/internal/operators/windowCount.ts @@ -46,7 +46,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( * windowCount(2, 3), - * mergeAll(), // flatten the Observable-of-Observables + * mergeAll() // flatten the Observable-of-Observables * ); * result.subscribe(x => console.log(x)); * ``` diff --git a/src/internal/operators/windowTime.ts b/src/internal/operators/windowTime.ts index ae7ee14b41..7c119b8b43 100644 --- a/src/internal/operators/windowTime.ts +++ b/src/internal/operators/windowTime.ts @@ -21,6 +21,7 @@ export function windowTime( maxWindowSize: number, scheduler?: SchedulerLike ): OperatorFunction>; + /** * Branch out the source Observable values as a nested Observable periodically * in time. @@ -53,8 +54,8 @@ export function windowTime( * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( * windowTime(1000), - * map(win => win.pipe(take(2))), // each window has at most 2 emissions - * mergeAll(), // flatten the Observable-of-Observables + * map(win => win.pipe(take(2))), // take at most 2 emissions from each window + * mergeAll() // flatten the Observable-of-Observables * ); * result.subscribe(x => console.log(x)); * ``` @@ -67,8 +68,8 @@ export function windowTime( * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( * windowTime(1000, 5000), - * map(win => win.pipe(take(2))), // each window has at most 2 emissions - * mergeAll(), // flatten the Observable-of-Observables + * map(win => win.pipe(take(2))), // take at most 2 emissions from each window + * mergeAll() // flatten the Observable-of-Observables * ); * result.subscribe(x => console.log(x)); * ``` @@ -80,8 +81,8 @@ export function windowTime( * * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( - * windowTime(1000, 5000, 2), // each window has still at most 2 emissions - * mergeAll(), // flatten the Observable-of-Observables + * windowTime(1000, 5000, 2), // take at most 2 emissions from each window + * mergeAll() // flatten the Observable-of-Observables * ); * result.subscribe(x => console.log(x)); * ``` diff --git a/src/internal/operators/windowWhen.ts b/src/internal/operators/windowWhen.ts index a9f20aa600..3d8161af5b 100644 --- a/src/internal/operators/windowWhen.ts +++ b/src/internal/operators/windowWhen.ts @@ -32,8 +32,8 @@ import { innerFrom } from '../observable/innerFrom'; * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe( * windowWhen(() => interval(1000 + Math.random() * 4000)), - * map(win => win.pipe(take(2))), // each window has at most 2 emissions - * mergeAll() // flatten the Observable-of-Observables + * map(win => win.pipe(take(2))), // take at most 2 emissions from each window + * mergeAll() // flatten the Observable-of-Observables * ); * result.subscribe(x => console.log(x)); * ``` From 7ca231a1e9d8a877947403006809f9a6c74e2545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Tue, 7 Dec 2021 19:44:41 +0100 Subject: [PATCH 08/11] docs: use map and concatMap instead of mapTo and concatMapTo in examples --- src/internal/observable/race.ts | 14 ++++++-------- src/internal/observable/timer.ts | 9 ++++----- src/internal/operators/expand.ts | 4 ++-- src/internal/operators/mergeScan.ts | 4 ++-- src/internal/operators/raceWith.ts | 17 +++++++---------- src/internal/operators/reduce.ts | 4 ++-- 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/internal/observable/race.ts b/src/internal/observable/race.ts index 26e56d0ac2..adb02c0088 100644 --- a/src/internal/observable/race.ts +++ b/src/internal/observable/race.ts @@ -32,16 +32,14 @@ export function race(...inputs: [...ObservableInpu * Subscribes to the observable that was the first to start emitting. * * ```ts - * import { interval, mapTo, race } from 'rxjs'; + * import { interval, map, race } from 'rxjs'; * - * const obs1 = interval(1000).pipe(mapTo('fast one')); - * const obs2 = interval(3000).pipe(mapTo('medium one')); - * const obs3 = interval(5000).pipe(mapTo('slow one')); + * const obs1 = interval(7000).pipe(map(() => 'slow one')); + * const obs2 = interval(3000).pipe(map(() => 'fast one')); + * const obs3 = interval(5000).pipe(map(() => 'medium one')); * - * race(obs3, obs1, obs2) - * .subscribe( - * winner => console.log(winner) - * ); + * race(obs1, obs2, obs3) + * .subscribe(winner => console.log(winner)); * * // Outputs * // a series of 'fast one' diff --git a/src/internal/observable/timer.ts b/src/internal/observable/timer.ts index 243d7d868f..dcc2745811 100644 --- a/src/internal/observable/timer.ts +++ b/src/internal/observable/timer.ts @@ -26,15 +26,14 @@ import { isValidDate } from '../util/isDate'; * a few seconds and start a subscription to a source. * * ```ts - * import { of, timer, concatMapTo } from 'rxjs'; + * import { of, timer, concatMap } from 'rxjs'; * * // This could be any observable * const source = of(1, 2, 3); * - * const result = timer(3000).pipe( - * concatMapTo(source) - * ) - * .subscribe(console.log); + * timer(3000) + * .pipe(concatMap(() => source)) + * .subscribe(console.log); * ``` * * Take all values until the start of the next minute diff --git a/src/internal/operators/expand.ts b/src/internal/operators/expand.ts index 77afcc2d32..84b7e347a6 100644 --- a/src/internal/operators/expand.ts +++ b/src/internal/operators/expand.ts @@ -45,11 +45,11 @@ export function expand>( * Start emitting the powers of two on every click, at most 10 of them * * ```ts - * import { fromEvent, mapTo, expand, of, delay, take } from 'rxjs'; + * import { fromEvent, map, expand, of, delay, take } from 'rxjs'; * * const clicks = fromEvent(document, 'click'); * const powersOfTwo = clicks.pipe( - * mapTo(1), + * map(() => 1), * expand(x => of(2 * x).pipe(delay(1000))), * take(10) * ); diff --git a/src/internal/operators/mergeScan.ts b/src/internal/operators/mergeScan.ts index 87ea467bba..6e1e37c9ce 100644 --- a/src/internal/operators/mergeScan.ts +++ b/src/internal/operators/mergeScan.ts @@ -39,10 +39,10 @@ import { mergeInternals } from './mergeInternals'; * Count the number of click events * * ```ts - * import { fromEvent, mapTo, mergeScan, of } from 'rxjs'; + * import { fromEvent, map, mergeScan, of } from 'rxjs'; * * const click$ = fromEvent(document, 'click'); - * const one$ = click$.pipe(mapTo(1)); + * const one$ = click$.pipe(map(() => 1)); * const seed = 0; * const count$ = one$.pipe( * mergeScan((acc, one) => of(acc + one), seed) diff --git a/src/internal/operators/raceWith.ts b/src/internal/operators/raceWith.ts index 58663ff9ef..6e7292982e 100644 --- a/src/internal/operators/raceWith.ts +++ b/src/internal/operators/raceWith.ts @@ -11,17 +11,15 @@ import { identity } from '../util/identity'; * ## Example * * ```ts - * import { interval, mapTo, raceWith } from 'rxjs'; + * import { interval, map, raceWith } from 'rxjs'; * - * const obs1 = interval(1000).pipe(mapTo('fast one')); - * const obs2 = interval(3000).pipe(mapTo('medium one')); - * const obs3 = interval(5000).pipe(mapTo('slow one')); + * const obs1 = interval(7000).pipe(map(() => 'slow one')); + * const obs2 = interval(3000).pipe(map(() => 'fast one')); + * const obs3 = interval(5000).pipe(map(() => 'medium one')); * - * obs2.pipe( - * raceWith(obs3, obs1) - * ).subscribe( - * winner => console.log(winner) - * ); + * obs1 + * .pipe(raceWith(obs2, obs3)) + * .subscribe(winner => console.log(winner)); * * // Outputs * // a series of 'fast one' @@ -31,7 +29,6 @@ import { identity } from '../util/identity'; * @return A function that returns an Observable that mirrors the output of the * first Observable to emit an item. */ - export function raceWith( ...otherSources: [...ObservableInputTuple] ): OperatorFunction { diff --git a/src/internal/operators/reduce.ts b/src/internal/operators/reduce.ts index 603ce0f611..c9bdda0543 100644 --- a/src/internal/operators/reduce.ts +++ b/src/internal/operators/reduce.ts @@ -34,12 +34,12 @@ export function reduce(accumulator: (acc: A | S, value: V, index: n * Count the number of click events that happened in 5 seconds * * ```ts - * import { fromEvent, takeUntil, interval, mapTo, reduce } from 'rxjs'; + * import { fromEvent, takeUntil, interval, map, reduce } from 'rxjs'; * * const clicksInFiveSeconds = fromEvent(document, 'click') * .pipe(takeUntil(interval(5000))); * - * const ones = clicksInFiveSeconds.pipe(mapTo(1)); + * const ones = clicksInFiveSeconds.pipe(map(() => 1)); * const seed = 0; * const count = ones.pipe(reduce((acc, one) => acc + one, seed)); * From 7ebbbfa015d1dc2a9d5706a25cc7edbf3eda959f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Tue, 7 Dec 2021 19:51:48 +0100 Subject: [PATCH 09/11] docs: use tap's new callback functions to avoid using defer and finalize --- src/internal/operators/connect.ts | 14 ++++----- src/internal/operators/shareReplay.ts | 42 +++++++++++++-------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/internal/operators/connect.ts b/src/internal/operators/connect.ts index 8c324e580b..e97155d17c 100644 --- a/src/internal/operators/connect.ts +++ b/src/internal/operators/connect.ts @@ -48,14 +48,14 @@ const DEFAULT_CONFIG: ConnectConfig = { * Sharing a totally synchronous observable * * ```ts - * import { defer, of, tap, connect, merge, map, filter } from 'rxjs'; + * import { of, tap, connect, merge, map, filter } from 'rxjs'; * - * const source$ = defer(() => { - * console.log('subscription started'); - * return of(1, 2, 3, 4, 5).pipe( - * tap(n => console.log(`source emitted ${n}`)) - * ); - * }); + * const source$ = of(1, 2, 3, 4, 5).pipe( + * tap({ + * subscribe: () => console.log('subscription started'), + * next: n => console.log(`source emitted ${ n }`) + * }) + * ); * * source$.pipe( * // Notice in here we're merging 3 subscriptions to `shared$`. diff --git a/src/internal/operators/shareReplay.ts b/src/internal/operators/shareReplay.ts index efb144240b..f99215f9cd 100644 --- a/src/internal/operators/shareReplay.ts +++ b/src/internal/operators/shareReplay.ts @@ -86,25 +86,23 @@ export function shareReplay(bufferSize?: number, windowTime?: number, schedul * Example for `refCount` usage * * ```ts - * import { Observable, defer, tap, finalize, interval, shareReplay, take } from 'rxjs'; - * - * const log = (source: Observable, name: string) => defer(() => { - * console.log(`${name}: subscribed`); - * return source.pipe( - * tap({ - * next: value => console.log(`${name}: ${value}`), - * complete: () => console.log(`${name}: complete`) - * }), - * finalize(() => console.log(`${name}: unsubscribed`)) - * ); - * }); - * - * const obs$ = log(interval(1000), 'source'); - * - * const shared$ = log(obs$.pipe( - * shareReplay({bufferSize: 1, refCount: true }), - * take(2), - * ), 'shared'); + * import { Observable, tap, interval, shareReplay, take } from 'rxjs'; + * + * const log = (name: string, source: Observable) => source.pipe( + * tap({ + * subscribe: () => console.log(`${ name }: subscribed`), + * next: value => console.log(`${ name }: ${ value }`), + * complete: () => console.log(`${ name }: completed`), + * finalize: () => console.log(`${ name }: unsubscribed`) + * }) + * ); + * + * const obs$ = log('source', interval(1000)); + * + * const shared$ = log('shared', obs$.pipe( + * shareReplay({ bufferSize: 1, refCount: true }), + * take(2) + * )); * * shared$.subscribe(x => console.log('sub A: ', x)); * shared$.subscribe(y => console.log('sub B: ', y)); @@ -121,11 +119,11 @@ export function shareReplay(bufferSize?: number, windowTime?: number, schedul * // source: 1 * // shared: 1 * // sub A: 1 - * // shared: complete <-- take(2) completes the subscription for sub A + * // shared: completed <-- take(2) completes the subscription for sub A * // shared: unsubscribed <-- reference count = 1 * // shared: 1 * // sub B: 1 - * // shared: complete <-- take(2) completes the subscription for sub B + * // shared: completed <-- take(2) completes the subscription for sub B * // shared: unsubscribed <-- reference count = 0 * // source: unsubscribed <-- replaySubject unsubscribes from source observable because the reference count dropped to 0 and refCount is true * @@ -168,6 +166,6 @@ export function shareReplay( connector: () => new ReplaySubject(bufferSize, windowTime, scheduler), resetOnError: true, resetOnComplete: false, - resetOnRefCountZero: refCount + resetOnRefCountZero: refCount, }); } From df209affa10acdd7c48d5366f7566cfdc2688b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Tue, 7 Dec 2021 19:54:00 +0100 Subject: [PATCH 10/11] docs(share): use tap for logging in share example --- src/internal/operators/share.ts | 45 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/internal/operators/share.ts b/src/internal/operators/share.ts index cef095eb58..cbed063b80 100644 --- a/src/internal/operators/share.ts +++ b/src/internal/operators/share.ts @@ -72,34 +72,37 @@ export function share(options: ShareConfig): MonoTypeOperatorFunction; * Generate new multicast Observable from the `source` Observable value * * ```ts - * import { interval, map, share } from 'rxjs'; + * import { interval, tap, map, take, share } from 'rxjs'; * - * const source = interval(1000) - * .pipe( - * map((x: number) => { - * console.log('Processing: ', x); - * return x*x; - * }), - * share() + * const source = interval(1000).pipe( + * tap(x => console.log('Processing: ', x)), + * map(x => x * x), + * take(6), + * share() * ); * * source.subscribe(x => console.log('subscription 1: ', x)); * source.subscribe(x => console.log('subscription 2: ', x)); * * // Logs: - * // Processing: 0 - * // subscription 1: 0 - * // subscription 2: 0 - * // Processing: 1 - * // subscription 1: 1 - * // subscription 2: 1 - * // Processing: 2 - * // subscription 1: 4 - * // subscription 2: 4 - * // Processing: 3 - * // subscription 1: 9 - * // subscription 2: 9 - * // ... and so on + * // Processing: 0 + * // subscription 1: 0 + * // subscription 2: 0 + * // Processing: 1 + * // subscription 1: 1 + * // subscription 2: 1 + * // Processing: 2 + * // subscription 1: 4 + * // subscription 2: 4 + * // Processing: 3 + * // subscription 1: 9 + * // subscription 2: 9 + * // Processing: 4 + * // subscription 1: 16 + * // subscription 2: 16 + * // Processing: 5 + * // subscription 1: 25 + * // subscription 2: 25 * ``` * * ## Example with notifier factory: Delayed reset From fb9a0f7e0b49e612ad608d2cea7ebd657cb2e6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jakovljevi=C4=87?= Date: Tue, 7 Dec 2021 19:54:51 +0100 Subject: [PATCH 11/11] docs(dematerialize): fix TS errors in dematerialize example --- src/internal/operators/dematerialize.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internal/operators/dematerialize.ts b/src/internal/operators/dematerialize.ts index 116b60bfd6..28c2c867f2 100644 --- a/src/internal/operators/dematerialize.ts +++ b/src/internal/operators/dematerialize.ts @@ -25,11 +25,11 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Convert an Observable of Notifications to an actual Observable * * ```ts - * import { of, dematerialize } from 'rxjs'; + * import { NextNotification, ErrorNotification, of, dematerialize } from 'rxjs'; * - * const notifA = { kind: 'N', value: 'A' }; - * const notifB = { kind: 'N', value: 'B' }; - * const notifE = { kind: 'E', error: new TypeError('x.toUpperCase is not a function') } + * const notifA = >{ kind: 'N', value: 'A' }; + * const notifB = >{ kind: 'N', value: 'B' }; + * const notifE = { kind: 'E', error: new TypeError('x.toUpperCase is not a function') }; * * const materialized = of(notifA, notifB, notifE); *