Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 9d84aa5

Browse files
committed
Merge branch 'master' of https://github.com/ReactiveX/rxjs-docs into docs-merge
2 parents fa65858 + c73d8a2 commit 9d84aa5

File tree

6 files changed

+208
-49
lines changed

6 files changed

+208
-49
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The build and test structure is fairly primitive at the moment. There are variou
3636
## Committing
3737
It is strongly recommended that when creating a commit, you follow this procedure to start the commit wizard. It will aid you on creating valid commit messages.
3838

39-
```shell
40-
git add .
41-
npm run commit
42-
```
39+
```shell
40+
git add .
41+
npm run commit
42+
```
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
.extra-tip {
2+
display: flex;
3+
}
4+
15
h3 {
2-
display: inline-block;
3-
vertical-align: middle;
4-
padding-left: 10px;
6+
display: inline-block;
7+
vertical-align: middle;
8+
padding-left: 10px;
59
}
610

711
.tip-warning {
8-
color: rgb(244, 67, 54);
12+
color: rgb(244, 67, 54);
913
}
1014

1115
.tip-info {
12-
color: rgb(33, 150, 243);
16+
color: rgb(33, 150, 243);
1317
}

src/app/operators/components/operator/operator.component.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ <h3 class="short-description" [innerHTML]="shortDescription"></h3>
2121
[operatorExamples]="examples" class="margin-bottom-16">
2222
</app-operator-examples>
2323
<app-operator-parameters
24-
[operatorParameters]="parameters">
24+
[operatorParameters]="parameters"
25+
*ngIf="parameters?.length">
2526
</app-operator-parameters>
2627
<app-operator-walkthrough
2728
class="margin-bottom-16"
2829
[operatorWalkthrough]="walkthrough" >
2930
</app-operator-walkthrough>
31+
<app-operator-extras
32+
class="margin-bottom-16"
33+
*ngIf="walkthroughExtras"
34+
[operatorExtras]="walkthroughExtras">
35+
</app-operator-extras>
3036
<app-related-operators
3137
[relatedOperators]="relatedOperators">
3238
</app-related-operators>

src/app/operators/components/operator/operator.component.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
2-
import { OperatorDoc } from '../../../../operator-docs/operator.model';
1+
import {
2+
Component,
3+
Input,
4+
OnInit,
5+
ChangeDetectionStrategy
6+
} from "@angular/core";
7+
import { OperatorDoc } from "../../../../operator-docs/operator.model";
38

49
@Component({
5-
selector: 'app-operator',
6-
templateUrl: './operator.component.html',
7-
styleUrls: ['./operator.component.scss'],
10+
selector: "app-operator",
11+
templateUrl: "./operator.component.html",
12+
styleUrls: ["./operator.component.scss"],
813
changeDetection: ChangeDetectionStrategy.OnPush
914
})
1015
export class OperatorComponent {
1116
@Input() operator: OperatorDoc;
1217

13-
private readonly baseSourceUrl = 'https://github.com/ReactiveX/rxjs/blob/master/src/operators/';
14-
private readonly baseSpecUrl = 'http://reactivex.io/rxjs/test-file/spec-js/operators';
18+
private readonly baseSourceUrl = "https://github.com/ReactiveX/rxjs/blob/master/src/operators/";
19+
private readonly baseSpecUrl = "http://reactivex.io/rxjs/test-file/spec-js/operators";
1520

1621
get operatorName() {
1722
return this.operator.name;
1823
}
1924

2025
get signature() {
21-
return this.operator.signature || 'Signature Placeholder';
26+
return this.operator.signature || "Signature Placeholder";
2227
}
2328

2429
get marbleUrl() {
@@ -30,17 +35,26 @@ export class OperatorComponent {
3035
}
3136

3237
get shortDescription() {
33-
return this.operator.shortDescription && this.operator.shortDescription.description;
38+
return (
39+
this.operator.shortDescription &&
40+
this.operator.shortDescription.description
41+
);
3442
}
3543

3644
get shortDescriptionExtras() {
37-
return this.operator.shortDescription && this.operator.shortDescription.extras;
45+
return (
46+
this.operator.shortDescription && this.operator.shortDescription.extras
47+
);
3848
}
3949

4050
get walkthrough() {
4151
return this.operator.walkthrough && this.operator.walkthrough.description;
4252
}
4353

54+
get walkthroughExtras() {
55+
return this.operator.walkthrough && this.operator.walkthrough.extras;
56+
}
57+
4458
get parameters() {
4559
return this.operator.parameters || [];
4660
}
Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
import { OperatorDoc } from '../operator.model';
1+
import { OperatorDoc } from "../operator.model";
22

33
export const combineLatest: OperatorDoc = {
4-
'name': 'combineLatest',
5-
'operatorType': 'combination',
6-
'signature': 'public combineLatest(observables: ...Observable, project: function): Observable',
7-
"useInteractiveMarbles": true,
8-
'parameters': [
4+
name: "combineLatest",
5+
operatorType: "combination",
6+
signature:
7+
"public combineLatest(observables: ...Observable, project: function): Observable",
8+
useInteractiveMarbles: true,
9+
parameters: [
910
{
10-
'name': 'other',
11-
'type': 'Observable',
12-
'attribute': '',
13-
'description': 'An input Observable to combine with the source Observable. More than one input Observables may be given as argument.'
11+
name: "other",
12+
type: "Observable",
13+
attribute: "",
14+
description:
15+
"An input Observable to combine with the source Observable. More than one input Observables may be given as argument."
1416
},
1517
{
16-
'name': 'other',
17-
'type': 'function',
18-
'attribute': 'optional',
19-
'description': 'An optional function to project the values from the combined latest values into a new value on the output Observable.'
18+
name: "other",
19+
type: "function",
20+
attribute: "optional",
21+
description:
22+
"An optional function to project the values from the combined latest values into a new value on the output Observable."
2023
}
2124
],
22-
'marbleUrl': 'http://reactivex.io/rxjs/img/combineLatest.png',
23-
'shortDescription': {
24-
'description': `
25+
marbleUrl: "http://reactivex.io/rxjs/img/combineLatest.png",
26+
shortDescription: {
27+
description: `
2528
Combines multiple Observables to create an Observable whose values
2629
are calculated from the latest values of each of its input Observables.
2730
`,
28-
'extras': []
31+
extras: []
2932
},
30-
'walkthrough': {
31-
'description': `
33+
walkthrough: {
34+
description: `
3235
<p>
3336
<span class="markdown-code">combineLatest</span> combines the values from this Observable with values from
3437
Observables passed as arguments. This is done by subscribing to each
@@ -40,10 +43,11 @@ export const combineLatest: OperatorDoc = {
4043
</p>
4144
`
4245
},
43-
'examples': [
46+
examples: [
4447
{
45-
'name': 'Dynamically calculate the Body-Mass Index from an Observable of weight and one for height',
46-
'code': `
48+
name:
49+
"Dynamically calculate the Body-Mass Index from an Observable of weight and one for height",
50+
code: `
4751
const weight = Rx.Observable.of(70, 72, 76, 79, 75);
4852
const height = Rx.Observable.of(1.76, 1.77, 1.78);
4953
const bmi = weight.combineLatest(height, (w, h) => w / (h * h));
@@ -55,9 +59,12 @@ export const combineLatest: OperatorDoc = {
5559
*/
5660
bmi.subscribe(x => console.log('BMI is ' + x));
5761
`,
58-
'externalLink': { 'platform': 'JSBin', 'url': 'http://jsbin.com/pivowunedu/1/embed?js,console'}
62+
externalLink: {
63+
platform: "JSBin",
64+
url: "http://jsbin.com/pivowunedu/1/embed?js,console"
65+
}
5966
}
6067
],
61-
'relatedOperators': [ 'combineAll', 'merge', 'withLatestFrom' ],
62-
'additionalResources': []
68+
relatedOperators: ["combineAll", "merge", "withLatestFrom"],
69+
additionalResources: []
6370
};
Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,134 @@
1-
import { OperatorDoc } from '../operator.model';
1+
import { OperatorDoc } from "../operator.model";
22

33
export const groupBy: OperatorDoc = {
4-
'name': 'groupBy',
5-
'operatorType': 'transformation'
4+
name: "groupBy",
5+
operatorType: "transformation",
6+
signature: `
7+
public groupBy(keySelector: (value: T) => K,
8+
elementSelector?: ((value: T) => R) | void,
9+
durationSelector?: (grouped: GroupedObservable<K, R>) => Observable<any>,
10+
subjectSelector?: () => Subject<R>)
11+
: Observable<any>): OperatorFunction<T, GroupedObservable<K, R>>`,
12+
parameters: [
13+
{
14+
name: "keySelector",
15+
type: "(value: T) => K",
16+
attribute: "",
17+
description: `A function that extracts the key used for grouping for each item.`
18+
},
19+
{
20+
name: "elementSelector",
21+
type: "((value: T) => R) | void",
22+
attribute: "optional",
23+
description: `A function that extracts the emitted element for each item. Default is identity function.`
24+
},
25+
{
26+
name: "durationSelector",
27+
type: "(grouped: GroupedObservable<K, R>) => Observable<any>",
28+
attribute: "optional",
29+
description: `A function that returns an Observable to determine how long each group should exist.`
30+
},
31+
{
32+
name: "subjectSelector",
33+
type: "() => Subject<R>",
34+
attribute: "optional",
35+
description: ``
36+
}
37+
],
38+
marbleUrl: "http://reactivex.io/rxjs/img/groupBy.png",
39+
shortDescription: {
40+
description: `
41+
Group, according to a specified key, elements from items emitted by an Observable,
42+
and emit these grouped items as GroupedObservables, one GroupedObservable per group.
43+
`,
44+
extras: []
45+
},
46+
walkthrough: {
47+
description: `
48+
<p>When the Observable emits an item, a key is computed for this item with the keySelector function.</p>
49+
50+
<p>If a GroupedObservable for this key exists, this GroupedObservable emits. Elsewhere, a new
51+
GroupedObservable for this key is created and emits.</p>
52+
53+
<p>A GroupedObservable represents values belonging to the same group represented by a common key.
54+
The common key is available as the key field of a GroupedObservable instance.</p>
55+
56+
<p>The elements emitted by GroupedObservables are by default the items emitted by the Observable,
57+
or elements returned by the elementSelector function.
58+
`
59+
},
60+
examples: [
61+
{
62+
name: "Group objects by id and return as array",
63+
code: `
64+
interface Obj {
65+
id: number;
66+
name: string;
67+
}
68+
Rx.Observable.of<Obj>({id: 1, name: 'aze1'},
69+
{id: 2, name: 'sf2'},
70+
{id: 2, name: 'dg2'},
71+
{id: 1, name: 'erg1'},
72+
{id: 1, name: 'df1'},
73+
{id: 2, name: 'sfqfb2'},
74+
{id: 3, name: 'qfs3'},
75+
{id: 2, name: 'qsgqsfg2'})
76+
.groupBy(p => p.id)
77+
.flatMap( (group$) => group$.reduce((acc, cur) => [...acc, cur], []))
78+
.subscribe(p => console.log(p));
79+
/*
80+
Output:
81+
[ { id: 1, name: 'aze1' },
82+
{ id: 1, name: 'erg1' },
83+
{ id: 1, name: 'df1' } ]
84+
85+
[ { id: 2, name: 'sf2' },
86+
{ id: 2, name: 'dg2' },
87+
{ id: 2, name: 'sfqfb2' },
88+
{ id: 2, name: 'qsgqsfg2' } ]
89+
90+
[ { id: 3, name: 'qfs3' } ]
91+
*/
92+
`,
93+
externalLink: {
94+
platform: "JSBin",
95+
url: "http://jsbin.com/linekelumo/1/embed?js,console"
96+
}
97+
},
98+
{
99+
name: "Pivot data on the id field",
100+
code: `
101+
interface Obj {
102+
id: number;
103+
name: string;
104+
}
105+
Rx.Observable.of<Obj>({id: 1, name: 'aze1'},
106+
{id: 2, name: 'sf2'},
107+
{id: 2, name: 'dg2'},
108+
{id: 1, name: 'erg1'},
109+
{id: 1, name: 'df1'},
110+
{id: 2, name: 'sfqfb2'},
111+
{id: 3, name: 'qfs1'},
112+
{id: 2, name: 'qsgqsfg2'})
113+
.groupBy(p => p.id, p => p.name)
114+
.flatMap( (group$) => group$.reduce((acc, cur) => [...acc, cur], ["" + group$.key]))
115+
.map(arr => ({'id': parseInt(arr[0]), 'values': arr.slice(1)}))
116+
.subscribe(p => console.log(p));
117+
/*
118+
Output:
119+
{ id: 1, values: [ 'aze1', 'erg1', 'df1' ] }
120+
121+
{ id: 2, values: [ 'sf2', 'dg2', 'sfqfb2', 'qsgqsfg2' ] }
122+
123+
{ id: 3, values: [ 'qfs1' ] }
124+
*/
125+
`,
126+
externalLink: {
127+
platform: "JSBin",
128+
url: "http://jsbin.com/racikizeji/embed?js,console"
129+
}
130+
}
131+
],
132+
relatedOperators: [],
133+
additionalResources: []
6134
};

0 commit comments

Comments
 (0)