Skip to content

Instantly share code, notes, and snippets.

@carlosvega20
Created February 28, 2018 18:38
Show Gist options
  • Save carlosvega20/914265a86abf921dc7aa4938184dc658 to your computer and use it in GitHub Desktop.
Save carlosvega20/914265a86abf921dc7aa4938184dc658 to your computer and use it in GitHub Desktop.
RXJS test // source https://jsbin.com/ribatol
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>RXJS test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.5.6/Rx.min.js"></script>
</head>
<body>
<input/>
<script id="jsbin-javascript">
const input = document.body.querySelector('input');
var inputStream = Rx.Observable.fromEvent(input, 'keyup');
const getAPI = (value) =>
fetch('https://jsonplaceholder.typicode.com/users?username='+value)
.then(res => res.json())
inputStream
.debounce(() => Rx.Observable.timer(200))
.map(e => e.target.value)
.filter(value => value.length>3)
.flatMap(getAPI)
.subscribe(el => console.log(el));
</script>
<script id="jsbin-source-javascript" type="text/javascript">const input = document.body.querySelector('input');
var inputStream = Rx.Observable.fromEvent(input, 'keyup');
const getAPI = (value) =>
fetch('https://jsonplaceholder.typicode.com/users?username='+value)
.then(res => res.json())
inputStream
.debounce(() => Rx.Observable.timer(200))
.map(e => e.target.value)
.filter(value => value.length>3)
.flatMap(getAPI)
.subscribe(el => console.log(el));
</script></body>
</html>
const input = document.body.querySelector('input');
var inputStream = Rx.Observable.fromEvent(input, 'keyup');
const getAPI = (value) =>
fetch('https://jsonplaceholder.typicode.com/users?username='+value)
.then(res => res.json())
inputStream
.debounce(() => Rx.Observable.timer(200))
.map(e => e.target.value)
.filter(value => value.length>3)
.flatMap(getAPI)
.subscribe(el => console.log(el));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment