Skip to content

Commit

Permalink
docs(sampleCombine): fix docs for extra operator
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Sep 25, 2016
1 parent 03ce7e9 commit 28c6433
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 5 deletions.
77 changes: 77 additions & 0 deletions EXTRA_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [`fromDiagram`](#fromDiagram) (factory)
- [`fromEvent`](#fromEvent) (operator)
- [`pairwise`](#pairwise) (operator)
- [`sampleCombine`](#sampleCombine) (operator)
- [`split`](#split) (operator)
- [`tween`](#tween) (factory)

Expand Down Expand Up @@ -527,6 +528,82 @@ stream.addListener({

- - -

### <a id="sampleCombine"></a> `sampleCombine(streams)`

Combines a source stream with multiple other streams. The result stream
will emit the latest events from all input streams, but only when the
source stream emits.

If the source, or any input stream, throws an error, the result stream
will propagate the error. If any input streams end, their final emitted
value will remain in the array of any subsequent events from the result
stream.

The result stream will only complete upon completion of the source stream.

Marble diagram:

```text
--1----2-----3--------4--- (source)
----a-----b-----c--d------ (other)
sampleCombine
-------2a----3b-------4d--
```

Examples:

```js
import sampleCombine from 'xstream/extra/sampleCombine'
import xs from 'xstream'

const sampler = xs.periodic(1000).take(3)
const other = xs.periodic(100)

const stream = sampler.compose(sampleCombine(other))

stream.addListener({
next: i => console.log(i),
error: err => console.error(err),
complete: () => console.log('completed')
})
```

```text
> [0, 8]
> [1, 18]
> [2, 28]
```

```js
import sampleCombine from 'xstream/extra/sampleCombine'
import xs from 'xstream'

const sampler = xs.periodic(1000).take(3)
const other = xs.periodic(100).take(2)

const stream = sampler.compose(sampleCombine(other))

stream.addListener({
next: i => console.log(i),
error: err => console.error(err),
complete: () => console.log('completed')
})
```

```text
> [0, 1]
> [1, 1]
> [2, 1]
```

#### Arguments:

- `streams: Stream` One or more streams to combine with the sampler stream.

#### Returns: Stream

- - -

### <a id="split"></a> `split(separator)`

Splits a stream using a separator stream. Returns a stream that emits
Expand Down
12 changes: 7 additions & 5 deletions src/extra/sampleCombine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,9 @@ export class SampleCombineOperator<T> implements Operator<T, Array<any>> {
}

let sampleCombine: SampleCombineSignature;
sampleCombine = function sampleCombine(...streams: Array<Stream<any>>) {
return function sampleCombineOperator(sampler: Stream<any>): Stream<Array<any>> {
return new Stream<Array<any>>(new SampleCombineOperator(sampler, streams));
};
} as SampleCombineSignature;

/**
*
* Combines a source stream with multiple other streams. The result stream
* will emit the latest events from all input streams, but only when the
* source stream emits.
Expand Down Expand Up @@ -223,4 +219,10 @@ sampleCombine = function sampleCombine(...streams: Array<Stream<any>>) {
* stream.
* @return {Stream}
*/
sampleCombine = function sampleCombine(...streams: Array<Stream<any>>) {
return function sampleCombineOperator(sampler: Stream<any>): Stream<Array<any>> {
return new Stream<Array<any>>(new SampleCombineOperator(sampler, streams));
};
} as SampleCombineSignature;

export default sampleCombine;
9 changes: 9 additions & 0 deletions tools/template-extras.md.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<!-- This EXTRA_DOCS.md file is automatically generated from source code and files in the /markdown directory. Please DO NOT send pull requests to directly modify this file. Instead, edit the JSDoc comments in source code or the md files in /markdown or the md.ejs files in /tools. -->

<? docfiles.forEach(function(doc) { ?>
<? doc.javadoc.forEach(function(comment) { ?>
<? if (comment.raw.code.substr(0,13) === 'sampleCombine') { ?>
<? comment.name = 'sampleCombine'; ?>
<? comment.isFunction = true; ?>
<? } ?>
<? }) ?>
<? }) ?>

## Extras
<? docfiles.forEach(function(doc) { ?><? doc.javadoc.forEach(function(comment) { ?><? if (!comment.ignore && comment.raw.tags.findIndex(o => o.type === 'factory') >= 0) { ?><? if (comment.name) { ?>
- [`<?= comment.name ?>`](#<?= comment.name ?>) (factory)<? } ?><? } ?><? if (!comment.ignore && comment.raw.tags.findIndex(o => o.type === 'factory') === -1) { ?><? if (comment.name) { ?>
Expand Down

0 comments on commit 28c6433

Please sign in to comment.