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

Commit

Permalink
updating operators
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitarora committed Feb 23, 2018
1 parent fa53e7d commit 1358093
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/operator-docs/combination/concatAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export const concatAll: OperatorDoc = {
map(ev => interval(1000).pipe(take(4)))
);
const firstOrder = higherOrder.pipe(concatAll());
firstOrder.subscribe(x => console.log(x));
firstOrder.subscribe(x => {
const output = \`<h3>$\{x.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
});
`
}
],
Expand Down
25 changes: 19 additions & 6 deletions src/operator-docs/combination/forkJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export const forkJoin: OperatorDoc = {
of(5, 6, 7, 8)
);
observable.subscribe(
value => console.log(value),
value => {
const output = \`<h3>$\{value.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
},
err => {},
() => console.log('This is how it ends!')
);
Expand All @@ -102,7 +105,10 @@ export const forkJoin: OperatorDoc = {
interval(500).pipe(take(4)) // emit 0, 1, 2, 3 every half a second and complete
);
observable.subscribe(
value => console.log(value),
value => {
const output = \`<h3>$\{value.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
},
err => {},
() => console.log('This is how it ends!')
);
Expand All @@ -114,13 +120,20 @@ export const forkJoin: OperatorDoc = {
{
name: 'Use forkJoin with project function',
code: `
const observable = Rx.Observable.forkJoin(
Rx.Observable.interval(1000).take(3), // emit 0, 1, 2 every second and complete
Rx.Observable.interval(500).take(4), // emit 0, 1, 2, 3 every half a second and complete
import { take } from 'rxjs/operators';
import { forkJoin } from 'rxjs/observable/forkJoin';
import { interval } from 'rxjs/observable/interval';
const observable = forkJoin(
interval(1000).pipe(take(3)), // emit 0, 1, 2 every second and complete
interval(500).pipe(take(4)), // emit 0, 1, 2, 3 every half a second and complete
(n, m) => n + m
);
observable.subscribe(
value => console.log(value),
value => {
const output = \`<h3>$\{value.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
},
err => {},
() => console.log('This is how it ends!')
);
Expand Down
10 changes: 8 additions & 2 deletions src/operator-docs/combination/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export const merge: OperatorDoc = {
const clicks = fromEvent(document, 'click');
const timer = interval(1000);
const clicksOrTimer = clicks.pipe(merge(timer));
clicksOrTimer.subscribe(x => console.log(x));
clicksOrTimer.subscribe(x => {
const output = \`<h3>$\{x.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
});
`
},
{
Expand All @@ -68,7 +71,10 @@ export const merge: OperatorDoc = {
const timer3 = interval(500).pipe(take(10));
const concurrent = 2; // the argument
const merged = timer1.pipe(merge(timer2, timer3, concurrent));
merged.subscribe(x => console.log(x));
merged.subscribe(x => {
const output = \`<h3>$\{x.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
});
`
}
],
Expand Down
12 changes: 9 additions & 3 deletions src/operator-docs/combination/mergeAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ export const mergeAll: OperatorDoc = {
const clicks = fromEvent(document, 'click');
const higherOrder = clicks.pipe(map((ev) => interval(1000)));
const firstOrder = higherOrder.pipe(mergeAll());
firstOrder.subscribe(x => console.log(x));
firstOrder.subscribe(x => {
const output = \`<h3>$\{x.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
});
`
},
{
name:
'Count from 0 to 9 every second for each click, but only allow 2 concurrent timers',
code: `
import { mergeAll, map } from 'rxjs/operators';
import { mergeAll, map, take } from 'rxjs/operators';
import { fromEvent } from 'rxjs/observable/fromEvent';
import { interval } from 'rxjs/observable/interval';
Expand All @@ -61,7 +64,10 @@ export const mergeAll: OperatorDoc = {
map((ev) => interval(1000).pipe(take(10)))
);
const firstOrder = higherOrder.pipe(mergeAll(2));
firstOrder.subscribe(x => console.log(x));
firstOrder.subscribe(x => {
const output = \`<h3>$\{x.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
});
`
}
],
Expand Down
5 changes: 4 additions & 1 deletion src/operator-docs/combination/pairwise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const pairwise: OperatorDoc = {
return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
})
);
distance.subscribe(x => console.log(x));
distance.subscribe(x => {
const output = \`<h3>$\{x.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
});
`
}
],
Expand Down
5 changes: 4 additions & 1 deletion src/operator-docs/combination/withLatestFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export const withLatestFrom: OperatorDoc = {
map(ev => interval(1000).pipe(take(4)))
);
const firstOrder = higherOrder.pipe(concatAll());
firstOrder.subscribe(x => console.log(x));
firstOrder.subscribe(x => {
const output = \`<h3>$\{x.toString()\}<h3>\`;
document.getElementById('output').innerHTML = output;
});
`
}
],
Expand Down
30 changes: 24 additions & 6 deletions src/operator-docs/creation/empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ export const empty: OperatorDoc = {
const observable = empty();
const subscription = observable.subscribe({
next: () => console.log('next'), // does not log anything
complete: () => console.log('complete'), // logs 'complete'
next: () => {
const output = \`<h3>next<h3>\`;
document.getElementById('output').innerHTML = output; // does not log anything
},
complete: () => {
const output = \`<h3>complete<h3>\`;
document.getElementById('output').innerHTML = output; // logs 'complete'
},
});
`
},
Expand All @@ -45,8 +51,14 @@ export const empty: OperatorDoc = {
const observable = empty().pipe(startWith('initial value'));
const subscription = observable.subscribe({
next: (val) => console.log(\`next: \${val}\`), // logs 'next: initial value'
complete: () => console.log('complete'), // logs 'complete'
next: (val) => {
const output = \`<h3>next: \${val}\<h3>\`;
document.getElementById('output').innerHTML = output; // logs 'next: initial value'
},
complete: () => {
const output = \`<h3>complete<h3>\`;
document.getElementById('output').innerHTML = output; // logs 'complete'
},
});
`
},
Expand All @@ -65,8 +77,14 @@ export const empty: OperatorDoc = {
)
);
const subscription = result.subscribe({
next: (x) => console.log(x), // logs result values
complete: () => console.log('complete'), // logs 'complete'
next: (val) => {
const output = \`<h3>\${val}\<h3>\`;
document.getElementById('output').innerHTML = output; // logs result values
},
complete: () => {
const output = \`<h3>complete<h3>\`;
document.getElementById('output').innerHTML = output; // logs 'complete'
},
});
`
}
Expand Down

0 comments on commit 1358093

Please sign in to comment.