André Werlang (@awerlang)
Functional ? Reactive Programming
x = f(y) + g(x')
Reactive programming is programming with asynchronous data streams.
Values that change over time
Whenever user types into a textbox, display a list of suggestions, but only if:
Which event we're talking about?
The event `UserChangedTextLongerThan2CharactersAbout500msAgo`
When this event happens, make the request.
(and cancel any pending requests...)
const inputChanged = Observable.fromEvent(inputElement, 'input')
.map(ev => ev.target.value)
.filter(text => text.length > 2)
.debounceTime(500)
.distinctUntilChanged();
const newSuggestionsArrived = inputChanged
.switchMap(q => Observable.ajax.getJSON('search?term=' + q));
newSuggestionsArrived.subscribe(data => {
suggestionsElement.innerHTML = data.map(it => `${it} `)
.join('');
});