Last active
March 29, 2019 18:13
-
-
Save dezfowler/23fd33d7ce6ff6153e6c174d2dfb88ab to your computer and use it in GitHub Desktop.
Simple rxified Clock
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
const { interval, empty } = require('rxjs'); | |
const { switchMap, startWith, map } = require('rxjs/operators'); | |
const Clock = rxify((initialProps, prop$) => { | |
return prop$ | |
.pipe( | |
switchMap(props => props.running ? interval(0, 1000) : empty()), | |
startWith(1), | |
map(_ => (<span className="time">{new Date().toLocaleTimeString()}</span>)) | |
) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment