Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

docs(operators): add documentation for defaultIfEmpty #330

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rxjs-docs
Submodule rxjs-docs deleted from 5059b4
65 changes: 63 additions & 2 deletions src/operator-docs/conditional/defaultIfEmpty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,67 @@
import { OperatorDoc } from '../operator.model';

export const defaultIfEmpty: OperatorDoc = {
'name': 'defaultIfEmpty',
'operatorType': 'conditional'
name: 'defaultIfEmpty',
operatorType: 'conditional',
signature: 'public defaultIfEmpty(defaultValue: any): Observable',
marbleUrl: 'http://reactivex.io/rxjs/img/defaultIfEmpty.png',
parameters: [
{
name: 'defaultValue',
type: 'any',
attribute: 'optional default: null',
description: 'The default value used if the source Observable is empty.'
}
],
shortDescription: {
description: `Emits a given value if the source Observable completes without emitting any
<span class="markdown-code">next</span> value, otherwise mirrors the source Observable.
`,
extras: [
{
type: 'Tip',
text: `
If the source Observable turns out to be empty, then this operator will emit a default value.
`
}
]
},
walkthrough: {
description: `
<p>
<span class="markdown-code">defaultIfEmpty</span> emits the values emitted by the source
Observable or a specified default value if the source Observable is empty (completes
without having emitted any <span class="markdown-code">next</span> value).
</p>
`
},
examples: [
{
name: `If no clicks happen in 3 seconds, then emit 'no clicks'`,
code: `
import { fromEvent } from 'rxjs/observable/fromEvent';
import { interval } from 'rxjs/observable/interval';
import { defaultIfEmpty, takeUntil } from 'rxjs/operators';

const clicks = fromEvent(document, 'click');
const result = clicks.pipe(
takeUntil(interval(3000)),
defaultIfEmpty('no clicks')
);

result.subscribe(x => console.log(x));

/*
Example console output
no clicks
*/
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/verovam/embed?js,console,output'
}
}
],
relatedOperators: ['empty', 'last'],
additionalResources: []
};