Skip to content

Instantly share code, notes, and snippets.

@dezfowler
Last active March 29, 2019 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dezfowler/23fd33d7ce6ff6153e6c174d2dfb88ab to your computer and use it in GitHub Desktop.
Save dezfowler/23fd33d7ce6ff6153e6c174d2dfb88ab to your computer and use it in GitHub Desktop.
Simple rxified Clock
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