|
1 | 1 | import { OperatorDoc } from '../operator.model'; |
2 | 2 |
|
3 | 3 | export const empty: OperatorDoc = { |
4 | | - 'name': 'empty', |
5 | | - 'operatorType': 'creation' |
| 4 | + name: 'empty', |
| 5 | + operatorType: 'creation', |
| 6 | + signature: 'public empty<T>(scheduler?: IScheduler): Observable<T>', |
| 7 | + parameters: [ |
| 8 | + { |
| 9 | + name: 'scheduler', |
| 10 | + type: 'IScheduler', |
| 11 | + attribute: 'optional', |
| 12 | + description: |
| 13 | + 'Allows scheduling the emission of the complete notification.' |
| 14 | + } |
| 15 | + ], |
| 16 | + marbleUrl: 'http://reactivex.io/rxjs/img/empty.png', |
| 17 | + shortDescription: { |
| 18 | + description: |
| 19 | + 'Creates an Observable that emits no items to the Observer' + |
| 20 | + ' and immediately emits a complete notification.' |
| 21 | + }, |
| 22 | + walkthrough: { |
| 23 | + description: `This static operator is useful for creating a simple |
| 24 | + Observable that only emits the complete notification. It can be used for |
| 25 | + composing with other Observables` |
| 26 | + }, |
| 27 | + examples: [ |
| 28 | + { |
| 29 | + name: 'Observable completes immediately', |
| 30 | + code: `const observable = Rx.Observable.empty(); |
| 31 | + const subscription = observable.subscribe({ |
| 32 | + next: () => console.log('next'), // does not log anything |
| 33 | + complete: () => console.log('complete'), // logs 'complete' |
| 34 | + });`, |
| 35 | + externalLink: { |
| 36 | + platform: 'JSBin', |
| 37 | + url: 'http://jsbin.com/hojacunecu/1/edit?js,console,output' |
| 38 | + } |
| 39 | + }, |
| 40 | + { |
| 41 | + name: 'Observable emits initial value then completes', |
| 42 | + code: `const observable = Rx.Observable.empty().startWith('initial value'); |
| 43 | + const subscription = observable.subscribe({ |
| 44 | + next: (val) => console.log(\`next: \${val}\`), // logs 'next: initial value' |
| 45 | + complete: () => console.log('complete'), // logs 'complete' |
| 46 | + });`, |
| 47 | + externalLink: { |
| 48 | + platform: 'JSBin', |
| 49 | + url: 'http://jsbin.com/tubonoradi/1/edit?js,console,output' |
| 50 | + } |
| 51 | + }, |
| 52 | + { |
| 53 | + name: `Map and flatten only odd numbers to the sequence 'ax', 'bx', 'cx'`, |
| 54 | + code: `const source = Rx.Observable.of(1, 2, 3, 4, 5, 6, 7, 8, 9); |
| 55 | + const result = source.mergeMap( |
| 56 | + x => x % 2 === 1 ? Rx.Observable.of(\`a\${x}\`, \`b\${x}\`, \`c\${x}\`) : |
| 57 | + Rx.Observable.empty() |
| 58 | + ); |
| 59 | + const subscription = result.subscribe({ |
| 60 | + next: (x) => console.log(x), // logs result values |
| 61 | + complete: () => console.log('complete'), // logs 'complete' |
| 62 | + });`, |
| 63 | + externalLink: { |
| 64 | + platform: 'JSBin', |
| 65 | + url: 'http://jsbin.com/qazabojiri/edit?js,console,output' |
| 66 | + } |
| 67 | + } |
| 68 | + ], |
| 69 | + relatedOperators: ['create', 'of', 'throw'] |
6 | 70 | }; |
0 commit comments