Slides from my talk about Reactive Extensions (Rx) fundamentals from Codemotion Milan 2015 conference. The demos and other samples can be found in the github repository: https://github.com/tamirdresher/Rx101
2. âą Software Architect, Consultant and Instructor
âą Software Engineering Lecturer @ Ruppin
Academic Center
@tamir_dresher
tamirdr@codevalue.net
http://www.TamirDresher.com.
3. Your headache relief pill to Asynchronous and
Event based applications
Async
Push
Triggers
Events
Reactive Extensions
4. Reactive Programming concentrates
on the propagation of changes and
their effects
simply put, how to react to
changes and create dataflows
that depend on them
Reactive Programming
19. Filtering Projection Partitioning Joins Grouping Set
Element Generation Quantifiers Aggregation Error HandlingTime and
Concurrency
Where
OfType
Select
SelectMany
Materialize
Skip
Take
TakeUntil
CombineLatest
Concat
join
GroupBy
GroupByUntil
Buffer
Distinct
DistinctUntilChanged
Timeout
TimeInterval
ElementAt
First
Single
Range
Repeat
Defer
All
Any
Contains
Sum
Average
Scan
Catch
OnErrorResumeNext
Using
20. Operator2 Creates an IObservable<T3>
IObservable parameters
Operator
1
Subscribe( )
observer
observable
⊠Operator
N
Operator1
Creates an IObservable<T2>
IObservable<T>
Original source
observer
Subscribe
Composability
23. 1. At least 3 characters
2. Donât overflow server (0.5 sec delay)
3. Donât send the same string again
4. Discard results if another search was
requested
Reactive Search - Rules
24.
25. Var textChanged =
Observable.FromEventPattern(txt, âTextChangedâ)
.Select(_=>txt.Text);
textChanged
.Where(text=>text.Length>3)
.Throttle(TimeSpan.FromSeconds(0.5))
.DistinctUntilChanged()
.SelectMany(text => SearchAsync(text))
.Switch()
.Subscribe(/*handle the results*/);
26. var $input = $('#input'),
$results = $('#results');
Rx.Observable.fromEvent($input, 'keyup')
.map(e => e.target.value)
.filter(text => text.length > 3)
.throttle(500 /* ms */)
.distinctUntilChanged()
.flatMapLatest(searchWikipedia)
.subscribe(data => {
var res = data[1];
$results.empty();
$.each(res, (_, value) => $('<li>' + value + '</li>').appendTo($results));
}, error => {
/* handle any errors */
$results.empty();
$('<li>Error: ' + error + '</li>').appendTo($results);
});
30. //
// Runs a timer on the default scheduler
//
IObservable TimeSpan
//
// Every operator that introduces concurrency
// has an overload with an IScheduler
//
IObservable T TimeSpan
IScheduler scheduler
Parameterizing Concurrency
32. //
// runs the observer callbacks on the specified
// scheduler.
//
IObservable T T IScheduler
//
// runs the observer subscription and unsubsciption on
// the specified scheduler.
//
IObservable T T IScheduler
Changing Execution Context