<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="./rxjs.umd.js"></script>
<style>
.box {
}
</style>
</head>
<body>
<input type="checkbox" id="check">
<div class="box" id="box">
</div>
<script>
const {range, interval, fromEvent} = rxjs;
const {map,tap, mergeMap, mapTo, filter, throttleTime, debounceTime, repeat, switchMap, takeUntil} = rxjs.operators;
const box = document.getElementById('box')
const check = document.getElementById('check')
const change$ = fromEvent(check, 'change').pipe(
// map(x => x.target.checked),
// filter(x => x === true)
)
const source$ = interval(100).pipe(mapTo('.'))
change$.pipe(
filter(x => x.target.checked),
tap(e => console.log('tap', e)),
mergeMap(() => source$.pipe(
takeUntil(change$)
))
).subscribe(x => box.innerText += x)
</script>
</body>
</html>
来源:oschina
链接:https://my.oschina.net/ahaoboy/blog/3164840