|
1 | 1 | import { OperatorDoc } from '../operator.model'; |
2 | 2 |
|
| 3 | +const EXAMPLE_CODE = ` |
| 4 | +import { combineLatest } from 'rxjs/operators/combineLatest'; |
| 5 | +import { of } from 'rxjs/observable/of'; |
| 6 | +
|
| 7 | +const weight = of(70, 72, 76, 79, 75); |
| 8 | +const height = of(1.76, 1.77, 1.78); |
| 9 | +const bmi = weight.pipe( |
| 10 | + combineLatest(height, (w, h) => w / (h * h)) |
| 11 | +); |
| 12 | +/* |
| 13 | + Output: |
| 14 | + BMI is 24.212293388429753 |
| 15 | + BMI is 23.93948099205209 |
| 16 | + BMI is 23.671253629592222 |
| 17 | +*/ |
| 18 | +bmi.subscribe(x => { |
| 19 | + const output = \`<h3>BMI is $\{x.toString\(\)\}<h3>\`; |
| 20 | + document.getElementById('output').innerHTML += output; |
| 21 | +}); |
| 22 | +`; |
| 23 | + |
3 | 24 | export const combineLatest: OperatorDoc = { |
4 | 25 | name: 'combineLatest', |
5 | 26 | operatorType: 'combination', |
@@ -55,27 +76,7 @@ export const combineLatest: OperatorDoc = { |
55 | 76 | { |
56 | 77 | name: |
57 | 78 | 'Dynamically calculate the Body-Mass Index from an Observable of weight and one for height', |
58 | | - code: ` |
59 | | - import { combineLatest } from 'rxjs/operators; |
60 | | - import { of } from 'rxjs/observable/of'; |
61 | | -
|
62 | | - const weight = of(70, 72, 76, 79, 75); |
63 | | - const height = of(1.76, 1.77, 1.78); |
64 | | - const bmi = weight.pipe( |
65 | | - combineLatest(height, (w, h) => w / (h * h)) |
66 | | - ); |
67 | | - /* |
68 | | - Output: |
69 | | - BMI is 24.212293388429753 |
70 | | - BMI is 23.93948099205209 |
71 | | - BMI is 23.671253629592222 |
72 | | - */ |
73 | | - bmi.subscribe(x => console.log('BMI is ' + x)); |
74 | | - `, |
75 | | - externalLink: { |
76 | | - platform: 'JSBin', |
77 | | - url: 'http://jsbin.com/pivowunedu/1/embed?js,console' |
78 | | - } |
| 79 | + code: EXAMPLE_CODE |
79 | 80 | } |
80 | 81 | ], |
81 | 82 | relatedOperators: ['combineAll', 'merge', 'withLatestFrom'], |
|
0 commit comments