From 66596eb552ffc7d5af681fc8e20488d074799ce5 Mon Sep 17 00:00:00 2001 From: Ashwin Sureshkumar Date: Thu, 7 Dec 2017 22:13:16 -0500 Subject: [PATCH] docs(operators): add documentation for filter Close #91 --- src/operator-docs/filtering/filter.ts | 77 ++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/filtering/filter.ts b/src/operator-docs/filtering/filter.ts index 9328bcfe..cbe69d10 100644 --- a/src/operator-docs/filtering/filter.ts +++ b/src/operator-docs/filtering/filter.ts @@ -1,6 +1,79 @@ import { OperatorDoc } from '../operator.model'; export const filter: OperatorDoc = { - 'name': 'filter', - 'operatorType': 'filtering' + name: 'filter', + operatorType: 'filtering', + signature: + 'public filter(predicate: function(value: T, index: number): boolean, thisArg: any): Observable', + 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, if false the value is not passed to the output Observable. + 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.' + } + ], + marbleUrl: 'http://reactivex.io/rxjs/img/filter.png', + shortDescription: { + description: + 'Filter items emitted by the source Observable by only emitting those that satisfy a specified predicate.', + extras: [ + { + type: 'Tip', + text: ` + Like + + Array.prototype.filter() + , + it only emits a value from the source if it passes a criterion function. + ` + } + ] + }, + walkthrough: { + description: ` +

+ Similar to the well-known Array.prototype.filter + method, this operator takes values from the source Observable, + passes them through a predicate function and only emits those values that yielded true. +

+ ` + }, + examples: [ + { + name: 'Filter for even numbers', + code: ` + //emit (1,2,3,4,5) + const source = Rx.Observable.from([1, 2, 3, 4, 5]); + //filter out non-even numbers + const example = source.filter(num => num % 2 === 0); + //output: "Even number: 2", "Even number: 4" + const subscribe = example.subscribe(val => console.log('Even number: ' + val)); + `, + externalLink: { + platform: 'JSBin', + url: 'http://jsbin.com/vafogoluye/1/embed?js,console' + } + } + ], + relatedOperators: [ + 'distinct', + 'distinctUntilChanged', + 'distinctUntilKeyChanged', + 'ignoreElements', + 'partition', + 'skip' + ] };