This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AppComponent { | |
| constructor () { | |
| this.count = 5; | |
| this.onResize = this._onResize.bind(this); | |
| } | |
| componentDidMount () { | |
| window.addEventListener('resize', this.onResize) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class AppComponent { | |
| onDestroy$ = new Subject(); | |
| count = 5; | |
| ngOnInit () { | |
| this.iceCreams$ = fromEvent(window, 'resize').pipe( | |
| flatMap(() => fromPromise(fetchIceCreams(this.count))), | |
| takeUntil(this.onDestroy$) | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const filterLoggedIn$ = (stream$) => { | |
| return stream$.pipe( | |
| withLatestFrom(iceCreamAuth$), | |
| filter((auth) => auth) | |
| ) | |
| }; | |
| const combinedInfoFactory$ = ( | |
| iceCreamPreferences$, | |
| iceCreamInventory$, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from(iceCreamIds).pipe( | |
| withLatestFrom( | |
| iceCreamAuth$, | |
| iceCreamPreferences$, | |
| iceCreamVendors$, | |
| iceCreamInventory$, | |
| iceCreamTemperature$, | |
| ), | |
| map(([ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { from, fromPromise } from 'rxjs'; | |
| const iceCreamIds = [4, 5, 10, 12]; | |
| from(iceCreamIds).pipe( | |
| flatMap((iceCreamId) => fromPromise(getIceCreamById(iceCreamId))) | |
| ).subscribe((iceCream) => { | |
| console.log(iceCream); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getIceCreamById (iceCreamId) { | |
| return fetch(`/icecream/${id}`); | |
| } | |
| const iceCreamIds = [4, 5, 10, 12]; | |
| // Slow, effectively synchronous | |
| for (let iceCreamId of iceCreamIds) { | |
| console.log(await getIceCreamById(iceCreamId)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { from, fromEvent, zip } from 'rxjs'; | |
| import { scan } from 'rxjs/operators'; | |
| const initialIceCreamFlavors = ['vanilla', 'chocolate', 'strawberry']; | |
| const initialIceCreamPrices = ['$5.50', '$5.75', '$6.00']; | |
| const iceCreamFormSubmit$ = fromEvent(formEl, 'submit'); | |
| const iceCreamFormFlavors$ = iceCreamFormSubmit$.pipe((map(({flavor}) => flavor))); | |
| const iceCreamFormPrices$ = iceCreamFormSubmit$.pipe((map(({price}) => price))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getIceCreamFlavorToPrice(flavors, prices) { | |
| let iceCreamFlavorToPrice; | |
| for (let i = 0; i < flavors.length; i++) { | |
| iceCreamFlavorToPrice[flavors[i]] = prices[i]; | |
| } | |
| return iceCreamFlavorToPrice; | |
| } | |
| let iceCreamFlavors = ['vanilla', 'chocolate', 'strawberry']; | |
| let iceCreamPrices = ['$5.50', '$5.75', '$6.00']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { from, zip } from 'rxjs'; | |
| import { scan } from 'rxjs/operators'; | |
| const iceCreamFlavors = ['vanilla', 'chocolate', 'strawberry']; | |
| const iceCreamPrices = ['$5.50', '$5.75', '$6.00']; | |
| const iceCreamFlavorToPrice$ = zip( | |
| from(iceCreamFlavors), | |
| from(iceCreamPrices), | |
| ).pipe(scan((prev, [flavor, price]) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const iceCreamFlavors = ['vanilla', 'chocolate', 'strawberry']; | |
| const iceCreamPrices = ['$5.50', '$5.75', '$6.00']; | |
| let iceCreamFlavorToPrice; | |
| for (let i = 0; i < iceCreamFlavors.length; i++) { | |
| iceCreamFlavorToPrice[iceCreamFlavors[i]] = iceCreamPrices[i]; | |
| } |
NewerOlder