Last active
December 11, 2018 23:19
-
-
Save Sawtaytoes/2c3ec1a5f1267c356468b5b3f2e9e40b to your computer and use it in GitHub Desktop.
An RxJS solution for a method utilizing an initial cache value and AJAX response on an interval to pass updated data to a subscriber.
This file contains 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
fromCache('itemList') | |
.pipe( | |
switchMap(itemList => ( | |
interval(3600000) // 1 hour | |
.pipe( | |
startWith(0), | |
switchMap(() => ( | |
ajax({ | |
url: 'https://api.example.com/data', | |
}) | |
.pipe( | |
pluck('response'), | |
) | |
)), | |
startWith(itemList), | |
filter(Boolean), | |
distinctUntilChanged(), | |
) | |
)), | |
) | |
.subscribe(itemList$) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment