|
1 | 1 | import { OperatorDoc } from '../operator.model';
|
2 | 2 |
|
3 | 3 | export const filter: OperatorDoc = {
|
4 |
| - 'name': 'filter', |
5 |
| - 'operatorType': 'filtering' |
| 4 | + name: 'filter', |
| 5 | + operatorType: 'filtering', |
| 6 | + signature: |
| 7 | + 'public filter(predicate: function(value: T, index: number): boolean, thisArg: any): Observable', |
| 8 | + parameters: [ |
| 9 | + { |
| 10 | + name: 'predicate', |
| 11 | + type: 'function(value: T, index: number): boolean', |
| 12 | + attribute: '', |
| 13 | + description: `A function that evaluates each value emitted by the source Observable. |
| 14 | + If it returns true, the value is emitted, if false the value is not passed to the output Observable. |
| 15 | + The index parameter is the number i for the i-th source emission that has happened since the subscription, |
| 16 | + starting from the number 0.` |
| 17 | + }, |
| 18 | + { |
| 19 | + name: 'thisArg', |
| 20 | + type: 'any', |
| 21 | + attribute: 'optional', |
| 22 | + description: |
| 23 | + 'An optional argument to determine the value of this in the predicate function.' |
| 24 | + } |
| 25 | + ], |
| 26 | + marbleUrl: 'http://reactivex.io/rxjs/img/filter.png', |
| 27 | + shortDescription: { |
| 28 | + description: |
| 29 | + 'Filter items emitted by the source Observable by only emitting those that satisfy a specified predicate.', |
| 30 | + extras: [ |
| 31 | + { |
| 32 | + type: 'Tip', |
| 33 | + text: ` |
| 34 | + Like |
| 35 | + <a |
| 36 | + target="_blank" |
| 37 | + href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"> |
| 38 | + Array.prototype.filter() |
| 39 | + </a>, |
| 40 | + it only emits a value from the source if it passes a criterion function. |
| 41 | + ` |
| 42 | + } |
| 43 | + ] |
| 44 | + }, |
| 45 | + walkthrough: { |
| 46 | + description: ` |
| 47 | + <p> |
| 48 | + Similar to the well-known <span class="markdown-code">Array.prototype.filter</span> |
| 49 | + method, this operator takes values from the source Observable, |
| 50 | + passes them through a predicate function and only emits those values that yielded true. |
| 51 | + </p> |
| 52 | + ` |
| 53 | + }, |
| 54 | + examples: [ |
| 55 | + { |
| 56 | + name: 'Filter for even numbers', |
| 57 | + code: ` |
| 58 | + //emit (1,2,3,4,5) |
| 59 | + const source = Rx.Observable.from([1, 2, 3, 4, 5]); |
| 60 | + //filter out non-even numbers |
| 61 | + const example = source.filter(num => num % 2 === 0); |
| 62 | + //output: "Even number: 2", "Even number: 4" |
| 63 | + const subscribe = example.subscribe(val => console.log('Even number: ' + val)); |
| 64 | + `, |
| 65 | + externalLink: { |
| 66 | + platform: 'JSBin', |
| 67 | + url: 'http://jsbin.com/vafogoluye/1/embed?js,console' |
| 68 | + } |
| 69 | + } |
| 70 | + ], |
| 71 | + relatedOperators: [ |
| 72 | + 'distinct', |
| 73 | + 'distinctUntilChanged', |
| 74 | + 'distinctUntilKeyChanged', |
| 75 | + 'ignoreElements', |
| 76 | + 'partition', |
| 77 | + 'skip' |
| 78 | + ] |
6 | 79 | };
|
0 commit comments