From cfbe5beff83076f5ce110b6f5b412d93d2719606 Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Thu, 14 Dec 2017 22:20:28 +0530 Subject: [PATCH 1/8] docs(operators): add documentation for sample --- src/operator-docs/filtering/sample.ts | 51 +++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/filtering/sample.ts b/src/operator-docs/filtering/sample.ts index eaeff413..12f49868 100644 --- a/src/operator-docs/filtering/sample.ts +++ b/src/operator-docs/filtering/sample.ts @@ -1,6 +1,53 @@ import { OperatorDoc } from '../operator.model'; export const sample: OperatorDoc = { - 'name': 'sample', - 'operatorType': 'filtering' + name: 'sample', + operatorType: 'filtering', + signature: 'public sample(notifier: Observable): Observable', + marbleUrl: 'http://reactivex.io/rxjs/img/sample.png', + parameters: [ + { + name: 'notifier', + type: 'Observable', + attribute: '', + description: `The Observable to use for sampling the source Observable.` + } + ], + shortDescription: { + description: `Emits the most recently emitted value from the source Observable whenever another Observable, the notifier, emits.`, + extras: [ + { + type: 'Tip', + text: `It's like sampleTime, but samples whenever the notifier Observable emits something.` + } + ] + }, + walkthrough: { + description: ` +

+ Whenever the notifier Observable emits a value or completes, + sample looks at the source Observable and emits whichever value + it has most recently emitted since the previous sampling, + unless the source has not emitted anything since the previous sampling. + The notifier is subscribed to as soon as the output Observable is subscribed. +

+ ` + }, + examples: [ + { + name: 'On every click, sample the most recent "seconds" timer', + code: ` + var seconds = Rx.Observable.interval(1000); + var clicks = Rx.Observable.fromEvent(document, 'click'); + var result = seconds.sample(clicks); + result.subscribe(x => console.log(x)); + `, + externalLink: { + platform: 'JSBin', + url: 'http://jsbin.com/xapiviz/edit?js,console,output' + } + } + ], + relatedOperators: ['audit', 'debounce', 'sampleTime', 'throttle'], + additionalResources: [] }; From cc7666ca7ec460367452a3c585d9ef7f70d0ac6c Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Thu, 14 Dec 2017 22:42:19 +0530 Subject: [PATCH 2/8] fix(operators): add markdown code to highlight keyword and replace var to const --- src/operator-docs/filtering/sample.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/operator-docs/filtering/sample.ts b/src/operator-docs/filtering/sample.ts index 12f49868..b7f34921 100644 --- a/src/operator-docs/filtering/sample.ts +++ b/src/operator-docs/filtering/sample.ts @@ -14,7 +14,10 @@ export const sample: OperatorDoc = { } ], shortDescription: { - description: `Emits the most recently emitted value from the source Observable whenever another Observable, the notifier, emits.`, + description: ` + Emits the most recently emitted value from the source Observable + whenever another Observable, the notifier, emits. + `, extras: [ { type: 'Tip', @@ -25,11 +28,11 @@ export const sample: OperatorDoc = { walkthrough: { description: `

- Whenever the notifier Observable emits a value or completes, - sample looks at the source Observable and emits whichever value + Whenever the notifier Observable emits a value or completes, + sample looks at the source Observable and emits whichever value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling. - The notifier is subscribed to as soon as the output Observable is subscribed. + The notifier is subscribed to as soon as the output Observable is subscribed.

` }, @@ -37,10 +40,10 @@ export const sample: OperatorDoc = { { name: 'On every click, sample the most recent "seconds" timer', code: ` - var seconds = Rx.Observable.interval(1000); - var clicks = Rx.Observable.fromEvent(document, 'click'); - var result = seconds.sample(clicks); - result.subscribe(x => console.log(x)); + const seconds = Rx.Observable.interval(1000); + const clicks = Rx.Observable.fromEvent(document, 'click'); + const result = seconds.sample(clicks); + result.subscribe(x => console.log(x)) `, externalLink: { platform: 'JSBin', From cdee0d0c9dfbe0cdab3b6ceed55c29ad34bef658 Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Thu, 14 Dec 2017 22:52:27 +0530 Subject: [PATCH 3/8] docs(operators): add documentation for sampleTime --- src/operator-docs/filtering/index.ts | 2 + src/operator-docs/filtering/sampleTime.ts | 66 +++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/operator-docs/filtering/sampleTime.ts diff --git a/src/operator-docs/filtering/index.ts b/src/operator-docs/filtering/index.ts index 93d93239..c891a1d4 100644 --- a/src/operator-docs/filtering/index.ts +++ b/src/operator-docs/filtering/index.ts @@ -6,6 +6,7 @@ import { first } from './first'; import { ignoreElements } from './ignoreElements'; import { last } from './last'; import { sample } from './sample'; +import { sampleTime } from './sampleTime'; import { single } from './single'; import { skip } from './skip'; import { skipUntil } from './skipUntil'; @@ -25,6 +26,7 @@ export const FILTERING_OPERATORS = [ ignoreElements, last, sample, + sampleTime, single, skip, skipUntil, diff --git a/src/operator-docs/filtering/sampleTime.ts b/src/operator-docs/filtering/sampleTime.ts new file mode 100644 index 00000000..2be2289c --- /dev/null +++ b/src/operator-docs/filtering/sampleTime.ts @@ -0,0 +1,66 @@ +import { OperatorDoc } from '../operator.model'; + +export const sampleTime: OperatorDoc = { + name: 'sampleTime', + operatorType: 'filtering', + signature: + 'public sampleTime(period: number, scheduler: Scheduler): Observable', + marbleUrl: 'http://reactivex.io/rxjs/img/sampleTime.png', + parameters: [ + { + name: 'period', + type: 'number', + attribute: '', + description: `The sampling period expressed in milliseconds or the time unit determined internally by the optional scheduler.` + }, + { + name: 'scheduler', + type: 'Scheduler', + attribute: 'optional default: async', + description: `The IScheduler to use for managing the timers that handle the sampling.` + } + ], + shortDescription: { + description: `Emits the most recently emitted value from the source Observable within periodic time intervals.`, + extras: [ + { + type: 'Tip', + text: `Samples the source Observable at periodic time intervals, emitting what it samples.` + } + ] + }, + walkthrough: { + description: ` +

+ sampleTime periodically looks at the source + Observable and emits whichever value it has most recently emitted since the previous + sampling, unless the source has not emitted anything since the previous sampling. + The sampling happens periodically in time every period + milliseconds (or the time unit defined by the optional scheduler argument). + The sampling starts as soon as the output Observable is subscribed. +

+ ` + }, + examples: [ + { + name: 'Every second, emit the most recent click at most once', + code: ` + const clicks = Rx.Observable.fromEvent(document, 'click'); + const result = clicks.sampleTime(1000); + result.subscribe(x => console.log(x)); + `, + externalLink: { + platform: 'JSBin', + url: 'http://jsbin.com/hohulon/edit?js,console,output' + } + } + ], + relatedOperators: [ + 'auditTime', + 'debounceTime', + 'delay', + 'sample', + 'throttleTime' + ], + additionalResources: [] +}; From 17e6cb812cbc682430591bf456d276af476a2cbf Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Sat, 16 Dec 2017 19:44:17 +0530 Subject: [PATCH 4/8] fix(operators): update code snippets --- src/operator-docs/filtering/sample.ts | 2 +- src/operator-docs/filtering/sampleTime.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/filtering/sample.ts b/src/operator-docs/filtering/sample.ts index b7f34921..6ba4d0ef 100644 --- a/src/operator-docs/filtering/sample.ts +++ b/src/operator-docs/filtering/sample.ts @@ -47,7 +47,7 @@ export const sample: OperatorDoc = { `, externalLink: { platform: 'JSBin', - url: 'http://jsbin.com/xapiviz/edit?js,console,output' + url: 'http://jsbin.com/xapiviz/embed?js,console,output' } } ], diff --git a/src/operator-docs/filtering/sampleTime.ts b/src/operator-docs/filtering/sampleTime.ts index 2be2289c..9b67e9eb 100644 --- a/src/operator-docs/filtering/sampleTime.ts +++ b/src/operator-docs/filtering/sampleTime.ts @@ -51,7 +51,7 @@ export const sampleTime: OperatorDoc = { `, externalLink: { platform: 'JSBin', - url: 'http://jsbin.com/hohulon/edit?js,console,output' + url: 'http://jsbin.com/hohulon/embed?js,console,output' } } ], From 2865cb30032ca69da2d2d1678efdff5de124448f Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Sat, 16 Dec 2017 19:46:20 +0530 Subject: [PATCH 5/8] fix(operators): add link to existing operator --- src/operator-docs/filtering/sample.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/operator-docs/filtering/sample.ts b/src/operator-docs/filtering/sample.ts index 6ba4d0ef..3e0787d4 100644 --- a/src/operator-docs/filtering/sample.ts +++ b/src/operator-docs/filtering/sample.ts @@ -21,7 +21,10 @@ export const sample: OperatorDoc = { extras: [ { type: 'Tip', - text: `It's like sampleTime, but samples whenever the notifier Observable emits something.` + text: ` + It's like sampleTime, + but samples whenever the notifier Observable emits something. + ` } ] }, From c442d6fa070e78015fdac8b0c44f48d8532b5636 Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Sat, 30 Dec 2017 12:51:45 +0530 Subject: [PATCH 6/8] fix(operators): add link to existing operator and markdown to keywords --- src/operator-docs/filtering/sample.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/operator-docs/filtering/sample.ts b/src/operator-docs/filtering/sample.ts index 572770b1..46c0497d 100644 --- a/src/operator-docs/filtering/sample.ts +++ b/src/operator-docs/filtering/sample.ts @@ -19,19 +19,22 @@ export const sample: OperatorDoc = { extras: [ { type: 'Tip', - text: `It's like sampleTime, but samples whenever the notifier Observable emits something.` + text: ` + It's like sampleTime, + but samples whenever the notifier Observable emits something. + ` } ] }, walkthrough: { description: `

- Whenever the notifier Observable emits a value or completes, + Whenever the notifier Observable emits a value or completes, sample looks at the source Observable and emits whichever value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling.

- The notifier is subscribed to as soon as the output Observable is subscribed. + The notifier is subscribed to as soon as the output Observable is subscribed.

` }, From c43c50210be5a4afad098acd821ff07ad2063c6c Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Sun, 1 Apr 2018 18:10:39 +0530 Subject: [PATCH 7/8] fix(operators): update code snippet --- src/operator-docs/filtering/sampleTime.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/filtering/sampleTime.ts b/src/operator-docs/filtering/sampleTime.ts index 9b67e9eb..cff61f7f 100644 --- a/src/operator-docs/filtering/sampleTime.ts +++ b/src/operator-docs/filtering/sampleTime.ts @@ -45,9 +45,26 @@ export const sampleTime: OperatorDoc = { { name: 'Every second, emit the most recent click at most once', code: ` - const clicks = Rx.Observable.fromEvent(document, 'click'); - const result = clicks.sampleTime(1000); + import { fromEvent } from "rxjs/observable/fromEvent"; + import { sampleTime } from "rxjs/operators"; + + const clicks = fromEvent(document, "click"); + const result = clicks.pipe(sampleTime(1000)); result.subscribe(x => console.log(x)); + + /* + Example console output + [object MouseEvent] { + altKey: false, + AT_TARGET: 2, + bubbles: true, + BUBBLING_PHASE: 3, + button: 0, + buttons: 0, + cancelable: true, + .... //Entire object properties + } + */ `, externalLink: { platform: 'JSBin', From 4160552ae36b7f9279d11d6a599845841c458139 Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Sun, 1 Apr 2018 18:22:09 +0530 Subject: [PATCH 8/8] fix(operators): remove generic --- src/operator-docs/filtering/sampleTime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operator-docs/filtering/sampleTime.ts b/src/operator-docs/filtering/sampleTime.ts index cff61f7f..5ae0eeaf 100644 --- a/src/operator-docs/filtering/sampleTime.ts +++ b/src/operator-docs/filtering/sampleTime.ts @@ -4,7 +4,7 @@ export const sampleTime: OperatorDoc = { name: 'sampleTime', operatorType: 'filtering', signature: - 'public sampleTime(period: number, scheduler: Scheduler): Observable', + 'public sampleTime(period: number, scheduler: Scheduler): Observable', marbleUrl: 'http://reactivex.io/rxjs/img/sampleTime.png', parameters: [ {