Skip to content

Instantly share code, notes, and snippets.

@Klaasvaak
Created January 14, 2018 14:30
Show Gist options
  • Save Klaasvaak/ae17101e44d788ca57996a9cb40983c0 to your computer and use it in GitHub Desktop.
Save Klaasvaak/ae17101e44d788ca57996a9cb40983c0 to your computer and use it in GitHub Desktop.
Base suggestions code with RxJS
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