From 813741c3701c956bafb3b7c2ac1b1636c8a39744 Mon Sep 17 00:00:00 2001 From: diye Date: Sun, 22 Aug 2021 22:42:32 +0800 Subject: [PATCH 1/6] docs(operators): fix code example --- src/internal/operators/combineLatestWith.ts | 5 ++++- src/internal/operators/connect.ts | 18 +++++++++++------- src/internal/operators/endWith.ts | 2 +- src/internal/operators/filter.ts | 4 ++++ src/internal/operators/finalize.ts | 14 ++++++++++---- src/internal/operators/find.ts | 4 ++++ src/internal/operators/findIndex.ts | 4 ++++ src/internal/operators/first.ts | 4 ++++ src/internal/operators/groupBy.ts | 2 +- src/internal/operators/ignoreElements.ts | 10 +++++----- src/internal/operators/observeOn.ts | 12 +++++++----- src/internal/operators/repeat.ts | 2 +- src/internal/operators/switchAll.ts | 4 ++-- src/internal/operators/timeInterval.ts | 19 +++++++++++-------- 14 files changed, 69 insertions(+), 35 deletions(-) diff --git a/src/internal/operators/combineLatestWith.ts b/src/internal/operators/combineLatestWith.ts index 3d96e5d43d..7a6b177dad 100644 --- a/src/internal/operators/combineLatestWith.ts +++ b/src/internal/operators/combineLatestWith.ts @@ -16,7 +16,10 @@ import { combineLatest } from './combineLatest'; * * Simple calculation from two inputs. * - * ``` + * ```ts + * import { fromEvent } from 'rxjs'; + * import { map, combineLatestWith } from 'rxjs/operators'; + * * // Setup: Add two inputs to the page * const input1 = document.createElement('input'); * document.body.appendChild(input1); diff --git a/src/internal/operators/connect.ts b/src/internal/operators/connect.ts index 3c666d6932..040cca6502 100644 --- a/src/internal/operators/connect.ts +++ b/src/internal/operators/connect.ts @@ -49,7 +49,7 @@ const DEFAULT_CONFIG: ConnectConfig = { * * ```ts * import { defer, of } from 'rxjs'; - * import { tap, connect } from 'rxjs/operators'; + * import { tap, connect, filter, map, mergeWith } from 'rxjs/operators'; * * const source$ = defer(() => { * console.log('subscription started'); @@ -59,12 +59,16 @@ 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}`)), - * )) + * // Notice in here we're merging 3 subscriptions to `shared$`. + * connect((shared$) => + * shared$.pipe( + * map(n => `all ${n}`), + * mergeWith( + * 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); * diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index 34a6911c1a..eeb7b758f9 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -46,7 +46,7 @@ export function endWith(...values: A): OperatorFun * endWith('interval ended by click'), * ) * .subscribe( - * x = console.log(x); + * x => console.log(x) * ) * * // Result (assuming a user clicks after 15 seconds) diff --git a/src/internal/operators/filter.ts b/src/internal/operators/filter.ts index 420e98f8e1..97d5e8b62d 100644 --- a/src/internal/operators/filter.ts +++ b/src/internal/operators/filter.ts @@ -30,6 +30,10 @@ export function filter(predicate: (value: T, index: number) => boolean): Mono * import { fromEvent } from 'rxjs'; * import { filter } 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 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 22141f8ca7..aa4575be35 100644 --- a/src/internal/operators/finalize.ts +++ b/src/internal/operators/finalize.ts @@ -38,12 +38,18 @@ import { operate } from '../util/lift'; * * const source = interval(100).pipe( * finalize(() => console.log('[finalize] Called')), - * tap(() => console.log('[next] Called'), - * () => console.log('[error] Not called'), - * () => console.log('[tap] Not called')), + * tap({ + * next: () => console.log('[next] Called'), + * error: () => console.log('[error] Not called'), + * complete: () => console.log('[tap complete] Not called') + * }) * ); * - * const sub = source.subscribe(x => console.log(x), noop, () => console.log('[complete] Not called')); + * const sub = source.subscribe({ + * next: x => console.log(x), + * error: noop, + * complete: () => console.log('[complete] Not called') + * }); * * timer(150).subscribe(() => sub.unsubscribe()); * diff --git a/src/internal/operators/find.ts b/src/internal/operators/find.ts index 2d186a5bf6..88ee4427df 100644 --- a/src/internal/operators/find.ts +++ b/src/internal/operators/find.ts @@ -40,6 +40,10 @@ export function find(predicate: (value: T, index: number, source: Observable< * import { fromEvent } from 'rxjs'; * import { find } 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 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 52a0f23893..0f1f86805d 100644 --- a/src/internal/operators/findIndex.ts +++ b/src/internal/operators/findIndex.ts @@ -34,6 +34,10 @@ export function findIndex(predicate: (value: T, index: number, source: Observ * import { fromEvent } from 'rxjs'; * import { findIndex } 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 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 e96bd7337a..69ba9dea79 100644 --- a/src/internal/operators/first.ts +++ b/src/internal/operators/first.ts @@ -53,6 +53,10 @@ export function first( * import { fromEvent } from 'rxjs'; * import { first } 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 result = clicks.pipe(first(ev => ev.target.tagName === 'DIV')); * result.subscribe(x => console.log(x)); diff --git a/src/internal/operators/groupBy.ts b/src/internal/operators/groupBy.ts index f31b495849..c79df357b6 100644 --- a/src/internal/operators/groupBy.ts +++ b/src/internal/operators/groupBy.ts @@ -110,7 +110,7 @@ export function groupBy( * { id: 3, name: 'TSLint' } * ) * .pipe( - * groupBy(p => p.id, p => p.name), + * groupBy(p => p.id, { element: p => p.name }), * mergeMap(group$ => * group$.pipe(reduce((acc, cur) => [...acc, cur], [`${group$.key}`])) * ), diff --git a/src/internal/operators/ignoreElements.ts b/src/internal/operators/ignoreElements.ts index d270749c4f..8df5dd0ec6 100644 --- a/src/internal/operators/ignoreElements.ts +++ b/src/internal/operators/ignoreElements.ts @@ -23,11 +23,11 @@ import { noop } from '../util/noop'; * of('you', 'talking', 'to', 'me').pipe( * ignoreElements(), * ) - * .subscribe( - * word => console.log(word), - * err => console.log('error:', err), - * () => console.log('the end'), - * ); + * .subscribe({ + * next: word => console.log(word), + * error: err => console.log('error:', err), + * complete: () => console.log('the end'), + * }); * // result: * // 'the end' * ``` diff --git a/src/internal/operators/observeOn.ts b/src/internal/operators/observeOn.ts index 2c27dbcec9..8f0b23c038 100644 --- a/src/internal/operators/observeOn.ts +++ b/src/internal/operators/observeOn.ts @@ -38,12 +38,14 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * import { interval, animationFrameScheduler } from 'rxjs'; * import { observeOn } from 'rxjs/operators'; * - * const someDiv = document.querySelector("#someDiv"); - * const intervals = interval(10); // Intervals are scheduled - * // with async scheduler by default... + * 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... * 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/repeat.ts b/src/internal/operators/repeat.ts index a365c6a521..09da1190e8 100644 --- a/src/internal/operators/repeat.ts +++ b/src/internal/operators/repeat.ts @@ -20,7 +20,7 @@ import { OperatorSubscriber } from './OperatorSubscriber'; * Repeat a message stream * ```ts * import { of } from 'rxjs'; - * import { repeat, delay } from 'rxjs/operators'; + * import { repeat } from 'rxjs/operators'; * * const source = of('Repeat message'); * const example = source.pipe(repeat(3)); diff --git a/src/internal/operators/switchAll.ts b/src/internal/operators/switchAll.ts index 7ab8fd020e..9e854dda6a 100644 --- a/src/internal/operators/switchAll.ts +++ b/src/internal/operators/switchAll.ts @@ -35,15 +35,15 @@ import { identity } from '../util/identity'; * * // Output * // click + * // 0 * // 1 * // 2 * // 3 - * // 4 * // ... * // click + * // 0 * // 1 * // 2 - * // 3 * // ... * // click * // ... diff --git a/src/internal/operators/timeInterval.ts b/src/internal/operators/timeInterval.ts index fa616f3fba..8fa26950b6 100644 --- a/src/internal/operators/timeInterval.ts +++ b/src/internal/operators/timeInterval.ts @@ -23,19 +23,22 @@ import { map } from './map'; * Emit interval between current value with the last value * * ```ts + * import { interval } from "rxjs"; + * import { timeInterval, timeout } from "rxjs/operators"; + * * const seconds = interval(1000); * * seconds.pipe(timeInterval()) - * .subscribe( - * value => console.log(value), - * err => console.log(err), - * ); + * .subscribe({ + * next: value => console.log(value), + * error: err => console.log(err), + * }); * * seconds.pipe(timeout(900)) - * .subscribe( - * value => console.log(value), - * err => console.log(err), - * ); + * .subscribe({ + * next: value => console.log(value), + * error: err => console.log(err), + * }); * * // NOTE: The values will never be this precise, * // intervals created with `interval` or `setInterval` From 3e75d9cdefec17466312cb15fa785f4eb79a041f Mon Sep 17 00:00:00 2001 From: diye Date: Mon, 23 Aug 2021 22:59:30 +0800 Subject: [PATCH 2/6] docs(operators): format `endWith` code example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mladen Jakovljević --- src/internal/operators/endWith.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/internal/operators/endWith.ts b/src/internal/operators/endWith.ts index eeb7b758f9..ed5e0985c1 100644 --- a/src/internal/operators/endWith.ts +++ b/src/internal/operators/endWith.ts @@ -45,9 +45,7 @@ export function endWith(...values: A): OperatorFun * takeUntil(documentClicks$), * endWith('interval ended by click'), * ) - * .subscribe( - * x => console.log(x) - * ) + * .subscribe(x => console.log(x)); * * // Result (assuming a user clicks after 15 seconds) * // "interval started" From 4d568122f673fab81b04be196d9c6da5c1d98d43 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 31 Aug 2021 09:36:11 -0500 Subject: [PATCH 3/6] chore: minor tweak to example code. --- src/internal/operators/find.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/operators/find.ts b/src/internal/operators/find.ts index 88ee4427df..89952ce621 100644 --- a/src/internal/operators/find.ts +++ b/src/internal/operators/find.ts @@ -41,7 +41,7 @@ export function find(predicate: (value: T, index: number, source: Observable< * import { find } from 'rxjs/operators'; * * 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'); From b4432232664b2950caa097862ce53f3e060289e3 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 31 Aug 2021 09:38:34 -0500 Subject: [PATCH 4/6] chore: minor tweak to example code. --- src/internal/operators/findIndex.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/operators/findIndex.ts b/src/internal/operators/findIndex.ts index 0f1f86805d..6016493f90 100644 --- a/src/internal/operators/findIndex.ts +++ b/src/internal/operators/findIndex.ts @@ -35,7 +35,7 @@ export function findIndex(predicate: (value: T, index: number, source: Observ * import { findIndex } from 'rxjs/operators'; * * 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'); From 714362469013bbd1edb9e700dc02c9e8fda8f360 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 31 Aug 2021 09:38:40 -0500 Subject: [PATCH 5/6] chore: minor tweak to example code. --- src/internal/operators/first.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/operators/first.ts b/src/internal/operators/first.ts index 69ba9dea79..4339bd8c34 100644 --- a/src/internal/operators/first.ts +++ b/src/internal/operators/first.ts @@ -54,7 +54,7 @@ export function first( * import { first } from 'rxjs/operators'; * * 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'); From cba7480d9961c40f17749a2b88142ba48489a63f Mon Sep 17 00:00:00 2001 From: diye Date: Wed, 1 Sep 2021 20:14:37 +0800 Subject: [PATCH 6/6] docs(operators): fix code example --- src/internal/operators/connect.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/internal/operators/connect.ts b/src/internal/operators/connect.ts index 040cca6502..0bc14cb9e2 100644 --- a/src/internal/operators/connect.ts +++ b/src/internal/operators/connect.ts @@ -48,8 +48,8 @@ const DEFAULT_CONFIG: ConnectConfig = { * Sharing a totally synchronous observable * * ```ts - * import { defer, of } from 'rxjs'; - * import { tap, connect, filter, map, mergeWith } from 'rxjs/operators'; + * import { defer, merge, of } from 'rxjs'; + * import { tap, connect, filter, map } from 'rxjs/operators'; * * const source$ = defer(() => { * console.log('subscription started'); @@ -60,15 +60,11 @@ const DEFAULT_CONFIG: ConnectConfig = { * * source$.pipe( * // Notice in here we're merging 3 subscriptions to `shared$`. - * connect((shared$) => - * shared$.pipe( - * map(n => `all ${n}`), - * mergeWith( - * 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); *