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

Commit 1358093

Browse files
committed
updating operators
1 parent fa53e7d commit 1358093

File tree

7 files changed

+72
-20
lines changed

7 files changed

+72
-20
lines changed

Diff for: src/operator-docs/combination/concatAll.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export const concatAll: OperatorDoc = {
5151
map(ev => interval(1000).pipe(take(4)))
5252
);
5353
const firstOrder = higherOrder.pipe(concatAll());
54-
firstOrder.subscribe(x => console.log(x));
54+
firstOrder.subscribe(x => {
55+
const output = \`<h3>$\{x.toString()\}<h3>\`;
56+
document.getElementById('output').innerHTML = output;
57+
});
5558
`
5659
}
5760
],

Diff for: src/operator-docs/combination/forkJoin.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ export const forkJoin: OperatorDoc = {
8181
of(5, 6, 7, 8)
8282
);
8383
observable.subscribe(
84-
value => console.log(value),
84+
value => {
85+
const output = \`<h3>$\{value.toString()\}<h3>\`;
86+
document.getElementById('output').innerHTML = output;
87+
},
8588
err => {},
8689
() => console.log('This is how it ends!')
8790
);
@@ -102,7 +105,10 @@ export const forkJoin: OperatorDoc = {
102105
interval(500).pipe(take(4)) // emit 0, 1, 2, 3 every half a second and complete
103106
);
104107
observable.subscribe(
105-
value => console.log(value),
108+
value => {
109+
const output = \`<h3>$\{value.toString()\}<h3>\`;
110+
document.getElementById('output').innerHTML = output;
111+
},
106112
err => {},
107113
() => console.log('This is how it ends!')
108114
);
@@ -114,13 +120,20 @@ export const forkJoin: OperatorDoc = {
114120
{
115121
name: 'Use forkJoin with project function',
116122
code: `
117-
const observable = Rx.Observable.forkJoin(
118-
Rx.Observable.interval(1000).take(3), // emit 0, 1, 2 every second and complete
119-
Rx.Observable.interval(500).take(4), // emit 0, 1, 2, 3 every half a second and complete
123+
import { take } from 'rxjs/operators';
124+
import { forkJoin } from 'rxjs/observable/forkJoin';
125+
import { interval } from 'rxjs/observable/interval';
126+
127+
const observable = forkJoin(
128+
interval(1000).pipe(take(3)), // emit 0, 1, 2 every second and complete
129+
interval(500).pipe(take(4)), // emit 0, 1, 2, 3 every half a second and complete
120130
(n, m) => n + m
121131
);
122132
observable.subscribe(
123-
value => console.log(value),
133+
value => {
134+
const output = \`<h3>$\{value.toString()\}<h3>\`;
135+
document.getElementById('output').innerHTML = output;
136+
},
124137
err => {},
125138
() => console.log('This is how it ends!')
126139
);

Diff for: src/operator-docs/combination/merge.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export const merge: OperatorDoc = {
5353
const clicks = fromEvent(document, 'click');
5454
const timer = interval(1000);
5555
const clicksOrTimer = clicks.pipe(merge(timer));
56-
clicksOrTimer.subscribe(x => console.log(x));
56+
clicksOrTimer.subscribe(x => {
57+
const output = \`<h3>$\{x.toString()\}<h3>\`;
58+
document.getElementById('output').innerHTML = output;
59+
});
5760
`
5861
},
5962
{
@@ -68,7 +71,10 @@ export const merge: OperatorDoc = {
6871
const timer3 = interval(500).pipe(take(10));
6972
const concurrent = 2; // the argument
7073
const merged = timer1.pipe(merge(timer2, timer3, concurrent));
71-
merged.subscribe(x => console.log(x));
74+
merged.subscribe(x => {
75+
const output = \`<h3>$\{x.toString()\}<h3>\`;
76+
document.getElementById('output').innerHTML = output;
77+
});
7278
`
7379
}
7480
],

Diff for: src/operator-docs/combination/mergeAll.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ export const mergeAll: OperatorDoc = {
4545
const clicks = fromEvent(document, 'click');
4646
const higherOrder = clicks.pipe(map((ev) => interval(1000)));
4747
const firstOrder = higherOrder.pipe(mergeAll());
48-
firstOrder.subscribe(x => console.log(x));
48+
firstOrder.subscribe(x => {
49+
const output = \`<h3>$\{x.toString()\}<h3>\`;
50+
document.getElementById('output').innerHTML = output;
51+
});
4952
`
5053
},
5154
{
5255
name:
5356
'Count from 0 to 9 every second for each click, but only allow 2 concurrent timers',
5457
code: `
55-
import { mergeAll, map } from 'rxjs/operators';
58+
import { mergeAll, map, take } from 'rxjs/operators';
5659
import { fromEvent } from 'rxjs/observable/fromEvent';
5760
import { interval } from 'rxjs/observable/interval';
5861
@@ -61,7 +64,10 @@ export const mergeAll: OperatorDoc = {
6164
map((ev) => interval(1000).pipe(take(10)))
6265
);
6366
const firstOrder = higherOrder.pipe(mergeAll(2));
64-
firstOrder.subscribe(x => console.log(x));
67+
firstOrder.subscribe(x => {
68+
const output = \`<h3>$\{x.toString()\}<h3>\`;
69+
document.getElementById('output').innerHTML = output;
70+
});
6571
`
6672
}
6773
],

Diff for: src/operator-docs/combination/pairwise.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export const pairwise: OperatorDoc = {
4444
return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
4545
})
4646
);
47-
distance.subscribe(x => console.log(x));
47+
distance.subscribe(x => {
48+
const output = \`<h3>$\{x.toString()\}<h3>\`;
49+
document.getElementById('output').innerHTML = output;
50+
});
4851
`
4952
}
5053
],

Diff for: src/operator-docs/combination/withLatestFrom.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export const withLatestFrom: OperatorDoc = {
4040
map(ev => interval(1000).pipe(take(4)))
4141
);
4242
const firstOrder = higherOrder.pipe(concatAll());
43-
firstOrder.subscribe(x => console.log(x));
43+
firstOrder.subscribe(x => {
44+
const output = \`<h3>$\{x.toString()\}<h3>\`;
45+
document.getElementById('output').innerHTML = output;
46+
});
4447
`
4548
}
4649
],

Diff for: src/operator-docs/creation/empty.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ export const empty: OperatorDoc = {
3232
3333
const observable = empty();
3434
const subscription = observable.subscribe({
35-
next: () => console.log('next'), // does not log anything
36-
complete: () => console.log('complete'), // logs 'complete'
35+
next: () => {
36+
const output = \`<h3>next<h3>\`;
37+
document.getElementById('output').innerHTML = output; // does not log anything
38+
},
39+
complete: () => {
40+
const output = \`<h3>complete<h3>\`;
41+
document.getElementById('output').innerHTML = output; // logs 'complete'
42+
},
3743
});
3844
`
3945
},
@@ -45,8 +51,14 @@ export const empty: OperatorDoc = {
4551
4652
const observable = empty().pipe(startWith('initial value'));
4753
const subscription = observable.subscribe({
48-
next: (val) => console.log(\`next: \${val}\`), // logs 'next: initial value'
49-
complete: () => console.log('complete'), // logs 'complete'
54+
next: (val) => {
55+
const output = \`<h3>next: \${val}\<h3>\`;
56+
document.getElementById('output').innerHTML = output; // logs 'next: initial value'
57+
},
58+
complete: () => {
59+
const output = \`<h3>complete<h3>\`;
60+
document.getElementById('output').innerHTML = output; // logs 'complete'
61+
},
5062
});
5163
`
5264
},
@@ -65,8 +77,14 @@ export const empty: OperatorDoc = {
6577
)
6678
);
6779
const subscription = result.subscribe({
68-
next: (x) => console.log(x), // logs result values
69-
complete: () => console.log('complete'), // logs 'complete'
80+
next: (val) => {
81+
const output = \`<h3>\${val}\<h3>\`;
82+
document.getElementById('output').innerHTML = output; // logs result values
83+
},
84+
complete: () => {
85+
const output = \`<h3>complete<h3>\`;
86+
document.getElementById('output').innerHTML = output; // logs 'complete'
87+
},
7088
});
7189
`
7290
}

0 commit comments

Comments
 (0)