|
1 | 1 | import { OperatorDoc } from '../operator.model'; |
2 | 2 |
|
3 | 3 | export const partition: OperatorDoc = { |
4 | | - 'name': 'partition', |
5 | | - 'operatorType': 'transformation' |
| 4 | + name: 'partition', |
| 5 | + operatorType: 'transformation', |
| 6 | + signature: |
| 7 | + 'public partition(predicate: function(value: T, index: number): boolean, thisArg: any): [Observable<T>, Observable<T>', |
| 8 | + marbleUrl: 'http://reactivex.io/rxjs/img/partition.png', |
| 9 | + parameters: [ |
| 10 | + { |
| 11 | + name: 'predicate', |
| 12 | + type: 'function(value: T, index: number): boolean', |
| 13 | + attribute: '', |
| 14 | + description: `A function that evaluates each value emitted by the source Observable. If it returns 'true', the value is emitted on the |
| 15 | + first Observable in the returned array, if 'false' the value is emitted on the second Observable in the array. The 'index' parameter |
| 16 | + is the number 'i' for the i-th source emission that has happened since the subscription, starting from the number '0'.` |
| 17 | + }, |
| 18 | + { |
| 19 | + name: 'thisArg', |
| 20 | + type: 'any', |
| 21 | + attribute: 'optional', |
| 22 | + description: `An optional argument to determine the value of 'this' in the predicate function.` |
| 23 | + } |
| 24 | + ], |
| 25 | + shortDescription: { |
| 26 | + description: `Splits the source Observable into two, one with values that satisfy a predicate, and another with values |
| 27 | + that don't satisfy the predicate.`, |
| 28 | + extras: [ |
| 29 | + { |
| 30 | + type: 'Tip', |
| 31 | + text: ` |
| 32 | + It's like <a href="#/operators/filter" class="markdown-code">filter</a>, but returns two Observables: one like the output of |
| 33 | + <a href="#/operators/filter" class="markdown-code">filter</a>, and the other with values that did not pass the condition. |
| 34 | + ` |
| 35 | + } |
| 36 | + ] |
| 37 | + }, |
| 38 | + walkthrough: { |
| 39 | + description: ` |
| 40 | + <p> |
| 41 | + <span class="markdown-code">partition</span> outputs an array with two Observables that partition the values from the source |
| 42 | + Observable through the given <span class="markdown-code">predicate</span> function. The first Observable in that array emits |
| 43 | + source values for which the predicate argument returns true. The second Observable emits source values for which the predicate |
| 44 | + returns false. The first behaves like <a href="#/operators/filter" class="markdown-code">filter</a> and the second behaves like |
| 45 | + <a href="#/operators/filter" class="markdown-code">filter</a> with the predicate negated. |
| 46 | + </p> |
| 47 | + ` |
| 48 | + }, |
| 49 | + examples: [ |
| 50 | + { |
| 51 | + name: |
| 52 | + 'Partition click events into those on DIV elements and those elsewhere', |
| 53 | + code: ` |
| 54 | + const clicks = Rx.Observable.fromEvent(document, 'click'); |
| 55 | + const parts = clicks.partition(ev => ev.target.tagName === 'DIV'); |
| 56 | + const clicksOnDivs = parts[0]; |
| 57 | + const clicksElsewhere = parts[1]; |
| 58 | + clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x)); |
| 59 | + clicksElsewhere.subscribe(x => console.log('Other clicked: ', x)); |
| 60 | + `, |
| 61 | + externalLink: { |
| 62 | + platform: 'JSBin', |
| 63 | + url: 'http://jsbin.com/vekisov/embed?js,console,output' |
| 64 | + } |
| 65 | + } |
| 66 | + ], |
| 67 | + relatedOperators: ['filter'], |
| 68 | + additionalResources: [] |
6 | 69 | }; |
0 commit comments