Created
January 14, 2018 14:30
-
-
Save Klaasvaak/ae17101e44d788ca57996a9cb40983c0 to your computer and use it in GitHub Desktop.
Base suggestions code with RxJS
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 cities = ['rome', 'madrid', 'paris', 'brussels', 'eindhoven', 'berlin', 'copenhagen', 'stockholm']; | |
const myAwesomeSearch = value => cities.filter(city => city.indexOf(value) !== -1); | |
const input = document.querySelector('input'); | |
const suggestions = document.querySelector('#suggestions'); | |
Rx.Observable.fromEvent(input, 'keyup') | |
.pluck('target', 'value') | |
.map(value => myAwesomeSearch(value)) | |
.map(cities => cities.map(city => `<li>${city}</li>`).join('')) | |
.subscribe(html => suggestions.innerHTML = html); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment