From d96efc00c85d65cadba673d91a3f594bbf093e20 Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Sat, 30 Dec 2017 11:44:27 +0530 Subject: [PATCH 1/2] docs(operators): add documentation for partition --- src/operator-docs/transformation/partition.ts | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/transformation/partition.ts b/src/operator-docs/transformation/partition.ts index 7df402d9..a6192ea1 100644 --- a/src/operator-docs/transformation/partition.ts +++ b/src/operator-docs/transformation/partition.ts @@ -1,6 +1,69 @@ import { OperatorDoc } from '../operator.model'; export const partition: OperatorDoc = { - 'name': 'partition', - 'operatorType': 'transformation' + name: 'partition', + operatorType: 'transformation', + signature: + 'public partition(predicate: function(value: T, index: number): boolean, thisArg: any): [Observable, Observable', + marbleUrl: 'http://reactivex.io/rxjs/img/partition.png', + parameters: [ + { + name: 'predicate', + type: 'function(value: T, index: number): boolean', + attribute: '', + description: `A function that evaluates each value emitted by the source Observable. If it returns 'true', the value is emitted on the + first Observable in the returned array, if 'false' the value is emitted on the second Observable in the array. The 'index' parameter + is the number 'i' for the i-th source emission that has happened since the subscription, starting from the number '0'.` + }, + { + name: 'thisArg', + type: 'any', + attribute: 'optional', + description: `An optional argument to determine the value of 'this' in the predicate function.` + } + ], + shortDescription: { + description: `Splits the source Observable into two, one with values that satisfy a predicate, and another with values + that don't satisfy the predicate.`, + extras: [ + { + type: 'Tip', + text: ` + It's like filter, but returns two Observables: one like the output of + filter, and the other with values that did not pass the condition. + ` + } + ] + }, + walkthrough: { + description: ` +

+ partition outputs an array with two Observables that partition the values from the source + Observable through the given predicate function. The first Observable in that array emits + source values for which the predicate argument returns true. The second Observable emits source values for which the predicate + returns false. The first behaves like filter and the second behaves like + filter with the predicate negated. +

+ ` + }, + examples: [ + { + name: + 'Partition click events into those on DIV elements and those elsewhere', + code: ` + const clicks = Rx.Observable.fromEvent(document, 'click'); + const parts = clicks.partition(ev => ev.target.tagName === 'DIV'); + const clicksOnDivs = parts[0]; + const clicksElsewhere = parts[1]; + clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x)); + clicksElsewhere.subscribe(x => console.log('Other clicked: ', x)); + `, + externalLink: { + platform: 'JSBin', + url: 'http://jsbin.com/vekisov/embed?js,console,output' + } + } + ], + relatedOperators: ['filter'], + additionalResources: [] }; From 8d86c55bb9a0b943ed71e9fe56c0933aff4beadf Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Sat, 30 Dec 2017 19:07:47 +0530 Subject: [PATCH 2/2] fix(operators): signature update --- src/operator-docs/transformation/partition.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operator-docs/transformation/partition.ts b/src/operator-docs/transformation/partition.ts index a6192ea1..72d7f01a 100644 --- a/src/operator-docs/transformation/partition.ts +++ b/src/operator-docs/transformation/partition.ts @@ -4,7 +4,7 @@ export const partition: OperatorDoc = { name: 'partition', operatorType: 'transformation', signature: - 'public partition(predicate: function(value: T, index: number): boolean, thisArg: any): [Observable, Observable', + 'public partition(predicate: function(value: T, index: number): boolean, thisArg: any): [Observable, Observable]', marbleUrl: 'http://reactivex.io/rxjs/img/partition.png', parameters: [ {