SlideShare a Scribd company logo
Reactive programming in
Angular 2
Yakov Fain
yfain
About myself
• Solutions Architect at Farata Systems
• Java Champion
• Co-authored the book

“Angular Development with TypeScript”
The Agenda
• Intro to RxJS



- Observable

- Observer

- Operators
• Observables in Angular 2



- Forms

- Http

- Router
RxJS 5
• Github repo:

https://github.com/ReactiveX/rxjs
• CDN: 

https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js
• Installing RxJS in the npm-based projects:



npm install rxjs
• Documentation:

http://reactivex.io/rxjs 

Main RxJS players
• Observable - a producer of sequences of values
• Observer - a consumer of observable values
• Subscriber - connects observer with observable
• Operator - en-route value transformation
Data

Source 

Data Flow
Observable
 Data

Source 

Data Flow
Observable
 Data

Source 

Data Flow
next
Observable
SubscriberObserver Data

Source 

Data Flow
next
Observable
SubscriberObserver Data

Source 

Data Flow
next
next()
error()
complete()
An Observable allows:
• Subscribe/unsubscribe to its data stream
• Emit the next value to the observer
• Notify the observer about errors
• Inform the observer about the stream completion
An Observer provides:
• A function to handle the next value from the stream
• A function to handle errors
• A function to handle end-of-stream
Creating an Observable
• Observable.create() - returns Observable that can invoke methods on Observer
• Observable.from() - converts an array or iterable into Observable
• Observable.fromEvent() - converts an event into Observable
• Observable.fromPromise() - converts a Promise into Observable
• Observable.range() - returns a sequence of integers in the specified range
An Operator
Observable Observable
A transforming

function
Let’s have a beer
let beers = [

{name: "Stella", country: "Belgium", price: 9.50},

{name: "Sam Adams", country: "USA", price: 8.50},

{name: "Bud Light", country: "USA", price: 6.50},

{name: "Brooklyn Lager", country: "USA", price: 8.00},

{name: "Sapporo", country: "Japan", price: 7.50}

];

An Operator
Observable Observable
A transforming

function
observableBeers

.filter(beer => beer.price < 8))
observableBeers = Rx.Observable.from(beers)

.filter(beer => beer.price < 8)

.map(beer => beer.name + ": $" + beer.price);



observableBeers

.subscribe(

beer => console.log(beer),

err => console.error(err),

() => console.log("Streaming is over")

);
Observable Beer
Creating the 

Observable
observableBeers = Rx.Observable.from(beers)

.filter(beer => beer.price < 8)

.map(beer => beer.name + ": $" + beer.price);



observableBeers

.subscribe(

beer => console.log(beer),

err => console.error(err),

() => console.log("Stream is over")

);
Operators
Observer
Observable Beer
observableBeers = Rx.Observable.from(beers)

.filter(beer => beer.price < 8)

.map(beer => beer.name + ": $" + beer.price);



observableBeers

.subscribe(

beer => console.log(beer),

err => console.error(err),

() => console.log("Streaming is over")

);
Observable Beer
No 

streaming yet
Streaming

begins
Demo
http://bit.ly/2kogm42


http://bit.ly/2jm69aM
Marble Diagrams
Observable map(function){}
Observable filter(function){}
RX: the data moves across your algorithm
Observable
Operator
Observable
Operator
Observable
Operator
Observable
Operator
Error-handling operators
• error() is invoked by the Observable on the Observer.
• catch() - intercepts the error in the subscriber before the observer gets it. You can
handle the error and re-subscribe.

• retry(n) - retry immediately up to n times

• retryWhen(fn) - retries as prescribed by the argument

// Declaring
function getData(): Observable {…} // data source 1

function getCachedData(): Observable {…} // data source 2
function getDataFromAnotherService(): Observable {…} // data source 3
//Invoking and subscribing
getData()

.catch(err => { 



if (err.status === 500){

console.error("Switching to streaming cached beer data");

return getCachedData();

} else{

console.error("Switching to another beer service");

return getDataFromAnotherService();

}



})

.map(beer => beer.name + ", " + beer.country)

.subscribe(

beer => console.log("Subscriber got " + beer)

);
F
a
i

l

o
v
e

r
Failover with catch()
plunker: http://bit.ly/2jXY9ha
flatMap
function getDrinks() {



let beers = Rx.Observable.from([

{name: "Stella", country: "Belgium", price: 9.50},

{name: "Sam Adams", country: "USA", price: 8.50},

{name: "Bud Light", country: "USA", price: 6.50}

]);



let softDrinks = Rx.Observable.from([

{name: "Coca Cola", country: "USA", price: 1.50},

{name: "Fanta", country: "USA", price: 1.50},

{name: "Lemonade", country: "France", price: 2.50}

]);



return Rx.Observable.create( observer => {



observer.next(beers); // pushing the beer pallet (observable)

observer.next(softDrinks); // pushing the soft drinks pallet (observable)

}

);

}



getDrinks()

.flatMap(drinks => drinks) // unloading drinks from pallets

.subscribe(

drink => console.log("Subscriber got " + drink.name + ": " + drink.price )
);
plunker http://bit.ly/2jZgc6T
Operator flatMap• Handles every value emitted by an observable as another observable
• Auto-subscribes to the internal observable and unwraps it
concat
Operator concat
Subscribe to the next observable only when the previous completes. It’s
useful for a sequential processing, e.g. HTTP requests.
// Emulate HTTP requests
let fourSecHTTPRequest = Rx.Observable.timer(4000).mapTo('First response');
let oneSecHTTPRequest = Rx.Observable.timer(1000).mapTo('Second response');
Rx.Observable
.concat(fourSecHTTPRequest, oneSecHTTPRequest)
.subscribe(res => console.log(res));
plunker http://bit.ly/2keEoiI
RxJS operators
http://reactivex.io/rxjs/manual/overview.html#categories-of-operators
Observables in
Angular
Code samples: https://github.com/yfain/observables
Observables in Forms
An input field: FormControl
• valueChanges - the value of the form control changes



this.searchInput.valueChanges.subscribe(…);
• statusChanges - status of the form control (valid/invalid)



this.password.statusChanges.subscribe(…);
Observable Events in Angular forms
@Component({

selector: "app",

template: `

<h2>Observable events demo</h2>

<input type="text" placeholder="Enter stock" [formControl]="searchInput">

`

})

class AppComponent {



searchInput: FormControl;



constructor(){

this.searchInput = new FormControl('');



this.searchInput.valueChanges

.debounceTime(500)

.subscribe(stock => this.getStockQuoteFromServer(stock));

}



getStockQuoteFromServer(stock) {



console.log(`The price of ${stock} is ${100*Math.random().toFixed(4)}`);

}

}
Observable
Demo 

main-formcontrol
Http and Observables


class AppComponent {



products: Array<string> = [];



constructor(private http: Http) {



this.http.get(‘/products')

.map(res => res.json())

.subscribe(

data => {



this.products=data;

},



err =>

console.log("Can't get products. Error code: %s, URL: %s ",

err.status, err.url),



() => console.log('Product(s) are retrieved')

);

}

}
O
b
s
e
r
v
e
r
@Component({

selector: 'http-client',

template: `<h1>All Products</h1>

<ul>

<li *ngFor="let product of products | async">

{{product.title}}

</li>

</ul>

<h2>{{errorMessage}}</h2>

`})

class AppComponent {



products: Observable<Array<string>>;

errorMessage: string;



constructor(private http: Http) {



this.products = this.http.get('/products')

.map(res => res.json())

.catch( err => {

this.errorMessage =`Can't get product details from ${err.url},

error ${err.status} `;

return Observable.empty();

});

}

}
async pipe
The switchMap operator
RxJS 5, official doc:

http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-
switchMap

Returns an Observable that emits items based on
applying a function that you supply to each item emitted
by the source Observable, where that function returns
an (so-called "inner") Observable. Each time it observes
one of these inner Observables, the output Observable
begins emitting the items emitted by that inner
Observable. When a new inner Observable is emitted,
switchMap stops emitting items from the earlier-emitted
inner Observable and begins emitting items from the
new one. It continues to behave like this for subsequent
inner Observables.
The switchMap operator
RxJS 5, official doc:

http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-
switchMap

Returns an Observable that emits items based on
applying a function that you supply to each item emitted
by the source Observable, where that function returns
an (so-called "inner") Observable. Each time it observes
one of these inner Observables, the output Observable
begins emitting the items emitted by that inner
Observable. When a new inner Observable is emitted,
switchMap stops emitting items from the earlier-emitted
inner Observable and begins emitting items from the
new one. It continues to behave like this for subsequent
inner Observables.
When a picture worth a thousand words
http://reactivex.io/documentation/operators/images/switchMap.png
The switchMap operator in English
• An outer observable emits the data and switches over to the inner
observable for processing
• If the outer observable emits the new data while the inner one is still
processing, the inner observable is terminated

• The inner observable starts processing the newly emitted data

• Example: A user types in a field (outer observable) and the HTTP
requests are being made (inner observable) as the user types
Killing HTTP requests with switchMap
<input type="text" placeholder="Enter city" [formControl]="searchInput">
…
this.searchInput.valueChanges

.debounceTime(200)

.switchMap(city => this.getWeather(city))

.subscribe(

res => {

this.temperature =

`Current temperature is ${res.main.temp}F, ` +

`humidity: ${res.main.humidity}%`;
},

err => console.log(`Can't get weather. Error code: %s, URL: %s`, err.message, err.url)

);

}



getWeather(city): Observable<Array> {

return this.http.get(this.baseWeatherURL + city + this.urlSuffix)

.map(res => res.json());

}
Outer Obs.
Inner Obs.
Demo 

main-http
Observables in the Router
Receiving params in ActivatedRoute
• Inject ActivatedRoute into a component to receive
route params during navigation
• Use ActivatedRoute.snapshot to get params once
• Use ActivatedRoute.param.subscribe() for
receiving multiple params over time
Subject: Observable + Observer
Can emit values and allows to subscribe to them
@Component({

selector: "app-root",

template: `

<h3>Using Subject for emitting/subscribing to keyup and input events</h3>

<input type="text" placeholder="Start typing" 

(input)="mySubject.next($event)" (keyup)="myKeySubject.next($event)">

`

})

export class AppComponent {



mySubject: Observable<Event> = new Subject(); // Observable for any events
myKeySubject: Observable<KeyboardEvent> = new Subject(); // Observable for keyboard events



constructor(){



this.myKeySubject.subscribe(({type, key}) => console.log(`Event: ${type} key: ${key}`));



this.mySubject.subscribe(({type, target}) => console.log(

`Event: ${type} value: ${(<HTMLInputElement>target).value}`));

}

}
Sharing an Observable
@Component({

selector: "app-root",

template: `

<h3>Sharing Observable between subscribers to keyup and input events</h3>

<input type="text" placeholder="Start typing" 

(input)="mySubject.next($event)" 

(keyup)="mySubject.next($event)">



<br> Subscriber to input events got {{inputValue}}

<p>

<br> Subscriber to input events got {{keyValue}} 

`

})

export class AppComponent {



keyValue: string;

inputValue: string;



mySubject: Observable<Event> = new Subject().share(); // Single Observable for any events



constructor(){



// Subscriber 1

this.mySubject

.filter(({type}) => type==="keyup")

.map(e => (<KeyboardEvent>e).key)

.subscribe((value) => this.keyValue=value);



// Subscriber 2

this.mySubject

.filter(({type}) => type==="input")

.map(e => (<HTMLInputElement>e.target).value)

.subscribe((value) => this.inputValue=value);

}

}
@Component({

selector: "app",

template: `

<h2>Sharing the same stream</h2>

<input #myinput type="text" placeholder="Start typing" >
<br> Subscribing to each value: {{data1}}

<br> Subscribing to 3-second samples: {{data2}}

`})

class AppComponent {


@ViewChild('myinput') myInputField: ElementRef;



data1: string;

data2: string;



ngAfterViewInit(){



let keyup$: Observable = Observable.fromEvent(this.myInputField.nativeElement, 'keyup');



let keyupValue$ = keyup$

.map(event => event.target.value)

.share();



// Subscribe to each keyup

keyupValue$

.subscribe(value => this.data1 = value);



// Subscribe to 3-second samples

keyupValue$

.sample(Observable.interval(3000))

.subscribe(value => this.data2 = value);

}

}
Accessing native elements with ElementRef
Using ElementRef

is not recommended
Demo
main-subject

main-subject-shared
Subscribing to EventEmitter
export declare class EventEmitter<T> extends Subject<T> {}
myEvent: EventEmitter<string> = new EventEmitter();
myEvent.emit("Hello World");
…
myEvent.subscribe(event => console.log(" Received " + event);
Your app:
Angular:
Has Observer

and Observable
Injectable service as Mediator
Subscribing to EventEmitter
export declare class EventEmitter<T> extends Subject<T> {}
myEvent: EventEmitter<string> = new EventEmitter();
myEvent.emit("Hello World");
…
myEvent.subscribe(event => console.log(" Received " + event);
Your app:
Angular:
Mediator, DI, Events, and Observables
StateService
Component1
with injected
StateService
Component2
with injected
StateService
EventEmitter
Emit event

on StateService
Subscribe to event

of StateService
Demo
main-mediator-service
WebSockets and Observables
Wrapping WebSocket into Observable
import {Observable } from 'rxjs/Observable';



export class BidService{



ws: WebSocket;



createObservableSocket(url:string): Observable{



this.ws = new WebSocket(url);



return new Observable(

observer => {



this.ws.onmessage = (event) => observer.next(event.data);



this.ws.onerror = (event) => observer.error(event);



this.ws.onclose = (event) => observer.complete();

});

}



}
Subscribing to WebSocket’s messages
@Component({ … })

class BidComponent {

newBid: Bid;



constructor(private wsService: BidService) {



this.wsService.createObservableSocket("ws://localhost:8085")

.map(res => JSON.parse(res))

.subscribe(

data => {



this.newBid = data;

this.newBid.bidTime= Date.parse(data.bidTime);

console.log(this.newBid);

},

err => console.log( err),

() => console.log( 'The bid stream is complete')

);

}



}
Demo1. Open http_websocket_samples

2. systemjs.config: bids/bid-component.ts
3. npm run tsc



4.npm run bidServer



5.http://localhost:8000
Summary
• Everything is an observable
• No data is pushed to you until you subscribe
• Chain the operators to pre-process the observable data before it gets
to the subscriber
• Angular offers you ready-to-use observables in multiple components
and services
• You can wrap the data pushed to your app into an Observable
Thank you!
• Code samples:

https://github.com/yfain/observables
• Training inquiries: 

training@faratasystems.com
• My blog:

yakovfain.com
• Twitter: @yfain


More Related Content

What's hot

Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
Tomáš Kypta
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobX
Darko Kukovec
 
Rx java in action
Rx java in actionRx java in action
Rx java in action
Pratama Nur Wijaya
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJava
Fabio Collini
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
Frank Lyaruu
 
Streams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to RxStreams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
Bulding a reactive game engine with Spring 5 & Couchbase
Bulding a reactive game engine with Spring 5 & CouchbaseBulding a reactive game engine with Spring 5 & Couchbase
Bulding a reactive game engine with Spring 5 & Couchbase
Alex Derkach
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
Jobaer Chowdhury
 
Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)
Tomasz Kowalczewski
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
Tomasz Kowalczewski
 
Introduction to Reactive Java
Introduction to Reactive JavaIntroduction to Reactive Java
Introduction to Reactive Java
Tomasz Kowalczewski
 
RxJava from the trenches
RxJava from the trenchesRxJava from the trenches
RxJava from the trenches
Peter Hendriks
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJava
Kros Huang
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
Yakov Fain
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
Jalpesh Vadgama
 
Angular & RXJS: examples and use cases
Angular & RXJS: examples and use casesAngular & RXJS: examples and use cases
Angular & RXJS: examples and use cases
Fabio Biondi
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
Martin Toshev
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
Ali Muzaffar
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
Frank Lyaruu
 
Reactive Android: RxJava and beyond
Reactive Android: RxJava and beyondReactive Android: RxJava and beyond
Reactive Android: RxJava and beyond
Fabio Tiriticco
 

What's hot (20)

Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobX
 
Rx java in action
Rx java in actionRx java in action
Rx java in action
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJava
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
 
Streams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to RxStreams, Streams Everywhere! An Introduction to Rx
Streams, Streams Everywhere! An Introduction to Rx
 
Bulding a reactive game engine with Spring 5 & Couchbase
Bulding a reactive game engine with Spring 5 & CouchbaseBulding a reactive game engine with Spring 5 & Couchbase
Bulding a reactive game engine with Spring 5 & Couchbase
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
 
Introduction to Reactive Java
Introduction to Reactive JavaIntroduction to Reactive Java
Introduction to Reactive Java
 
RxJava from the trenches
RxJava from the trenchesRxJava from the trenches
RxJava from the trenches
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJava
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
 
Angular & RXJS: examples and use cases
Angular & RXJS: examples and use casesAngular & RXJS: examples and use cases
Angular & RXJS: examples and use cases
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
Reactive Android: RxJava and beyond
Reactive Android: RxJava and beyondReactive Android: RxJava and beyond
Reactive Android: RxJava and beyond
 

Viewers also liked

Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
Yakov Fain
 
Angular 2 for Java Developers
Angular 2 for Java DevelopersAngular 2 for Java Developers
Angular 2 for Java Developers
Yakov Fain
 
Angular 2 Essential Training
Angular 2 Essential Training Angular 2 Essential Training
Angular 2 Essential Training
Patrick Schroeder
 
Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Building Universal Applications with Angular 2
Building Universal Applications with Angular 2
Minko Gechev
 
Integrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business WorkflowIntegrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business Workflow
Yakov Fain
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
Sebastian Holstein
 
Building a private CI/CD pipeline with Java and Docker in the Cloud as presen...
Building a private CI/CD pipeline with Java and Docker in the Cloud as presen...Building a private CI/CD pipeline with Java and Docker in the Cloud as presen...
Building a private CI/CD pipeline with Java and Docker in the Cloud as presen...
Baruch Sadogursky
 
Angular 2 - Better or worse
Angular 2 - Better or worseAngular 2 - Better or worse
Angular 2 - Better or worse
Vladimir Georgiev
 
Angular 2
Angular 2Angular 2
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
Knoldus Inc.
 
55 New Features in JDK 9
55 New Features in JDK 955 New Features in JDK 9
55 New Features in JDK 9
Simon Ritter
 
Angular 2 Crash Course
Angular  2 Crash CourseAngular  2 Crash Course
Angular 2 Crash Course
Elisha Kramer
 
Java Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldJava Intro: Unit1. Hello World
Java Intro: Unit1. Hello World
Yakov Fain
 
Reactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and RxReactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and Rx
Sumant Tambe
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
Yakov Fain
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
Yakov Fain
 
Cours java smi 2007 2008
Cours java smi 2007 2008Cours java smi 2007 2008
Cours java smi 2007 2008Khalil Lechheb
 
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Codemotion
 
The productive developer guide to Angular 2
The productive developer guide to Angular 2The productive developer guide to Angular 2
The productive developer guide to Angular 2
Maurice De Beijer [MVP]
 
A Designer's Intro to Oracle JET
A Designer's Intro to Oracle JETA Designer's Intro to Oracle JET
A Designer's Intro to Oracle JET
Lauren Beatty
 

Viewers also liked (20)

Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
Angular 2 for Java Developers
Angular 2 for Java DevelopersAngular 2 for Java Developers
Angular 2 for Java Developers
 
Angular 2 Essential Training
Angular 2 Essential Training Angular 2 Essential Training
Angular 2 Essential Training
 
Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Building Universal Applications with Angular 2
Building Universal Applications with Angular 2
 
Integrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business WorkflowIntegrating consumers IoT devices into Business Workflow
Integrating consumers IoT devices into Business Workflow
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
 
Building a private CI/CD pipeline with Java and Docker in the Cloud as presen...
Building a private CI/CD pipeline with Java and Docker in the Cloud as presen...Building a private CI/CD pipeline with Java and Docker in the Cloud as presen...
Building a private CI/CD pipeline with Java and Docker in the Cloud as presen...
 
Angular 2 - Better or worse
Angular 2 - Better or worseAngular 2 - Better or worse
Angular 2 - Better or worse
 
Angular 2
Angular 2Angular 2
Angular 2
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
55 New Features in JDK 9
55 New Features in JDK 955 New Features in JDK 9
55 New Features in JDK 9
 
Angular 2 Crash Course
Angular  2 Crash CourseAngular  2 Crash Course
Angular 2 Crash Course
 
Java Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldJava Intro: Unit1. Hello World
Java Intro: Unit1. Hello World
 
Reactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and RxReactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and Rx
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Cours java smi 2007 2008
Cours java smi 2007 2008Cours java smi 2007 2008
Cours java smi 2007 2008
 
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
Reactive Programming in Java by Mario Fusco - Codemotion Rome 2015
 
The productive developer guide to Angular 2
The productive developer guide to Angular 2The productive developer guide to Angular 2
The productive developer guide to Angular 2
 
A Designer's Intro to Oracle JET
A Designer's Intro to Oracle JETA Designer's Intro to Oracle JET
A Designer's Intro to Oracle JET
 

Similar to Reactive programming in Angular 2

RxJS Operators - Real World Use Cases - AngularMix
RxJS Operators - Real World Use Cases - AngularMixRxJS Operators - Real World Use Cases - AngularMix
RxJS Operators - Real World Use Cases - AngularMix
Tracy Lee
 
RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015
Ben Lesh
 
Functional Reactive Programming (FRP): Working with RxJS
Functional Reactive Programming (FRP): Working with RxJSFunctional Reactive Programming (FRP): Working with RxJS
Functional Reactive Programming (FRP): Working with RxJS
Oswald Campesato
 
Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJS
Luis Atencio
 
RxJS Operators - Real World Use Cases (FULL VERSION)
RxJS Operators - Real World Use Cases (FULL VERSION)RxJS Operators - Real World Use Cases (FULL VERSION)
RxJS Operators - Real World Use Cases (FULL VERSION)
Tracy Lee
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams
Johan Andrén
 
Realtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQRealtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQ
Xin Wang
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
Abul Hasan
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
YarikS
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams
Johan Andrén
 
The Reactive Landscape
The Reactive LandscapeThe Reactive Landscape
The Reactive Landscape
Red Hat Developers
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
Bo-Young Park
 
Reactive java programming for the impatient
Reactive java programming for the impatientReactive java programming for the impatient
Reactive java programming for the impatient
Grant Steinfeld
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
Brainhub
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwiftSwift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Aaron Douglas
 
Belfast JUG 23-10-2013
Belfast JUG 23-10-2013Belfast JUG 23-10-2013
Belfast JUG 23-10-2013
eamonnlong
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
Savvycom Savvycom
 
Rxandroid
RxandroidRxandroid
Rxandroid
Thinh Thanh
 
RxAndroid
RxAndroidRxAndroid
RxAndroid
Thinh Thanh
 
Reactive streams processing using Akka Streams
Reactive streams processing using Akka StreamsReactive streams processing using Akka Streams
Reactive streams processing using Akka Streams
Johan Andrén
 

Similar to Reactive programming in Angular 2 (20)

RxJS Operators - Real World Use Cases - AngularMix
RxJS Operators - Real World Use Cases - AngularMixRxJS Operators - Real World Use Cases - AngularMix
RxJS Operators - Real World Use Cases - AngularMix
 
RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015
 
Functional Reactive Programming (FRP): Working with RxJS
Functional Reactive Programming (FRP): Working with RxJSFunctional Reactive Programming (FRP): Working with RxJS
Functional Reactive Programming (FRP): Working with RxJS
 
Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJS
 
RxJS Operators - Real World Use Cases (FULL VERSION)
RxJS Operators - Real World Use Cases (FULL VERSION)RxJS Operators - Real World Use Cases (FULL VERSION)
RxJS Operators - Real World Use Cases (FULL VERSION)
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams
 
Realtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQRealtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQ
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams
 
The Reactive Landscape
The Reactive LandscapeThe Reactive Landscape
The Reactive Landscape
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
 
Reactive java programming for the impatient
Reactive java programming for the impatientReactive java programming for the impatient
Reactive java programming for the impatient
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwiftSwift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
 
Belfast JUG 23-10-2013
Belfast JUG 23-10-2013Belfast JUG 23-10-2013
Belfast JUG 23-10-2013
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
 
Rxandroid
RxandroidRxandroid
Rxandroid
 
RxAndroid
RxAndroidRxAndroid
RxAndroid
 
Reactive streams processing using Akka Streams
Reactive streams processing using Akka StreamsReactive streams processing using Akka Streams
Reactive streams processing using Akka Streams
 

More from Yakov Fain

Type script for_java_dev_jul_2020
Type script for_java_dev_jul_2020Type script for_java_dev_jul_2020
Type script for_java_dev_jul_2020
Yakov Fain
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
Yakov Fain
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
Yakov Fain
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
Yakov Fain
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
Yakov Fain
 
Using JHipster 4 for generating Angular/Spring Boot apps
Using JHipster 4 for generating Angular/Spring Boot appsUsing JHipster 4 for generating Angular/Spring Boot apps
Using JHipster 4 for generating Angular/Spring Boot apps
Yakov Fain
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
Yakov Fain
 
RESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoTRESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoT
Yakov Fain
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
Yakov Fain
 
Running a Virtual Company
Running a Virtual CompanyRunning a Virtual Company
Running a Virtual Company
Yakov Fain
 
Princeton jug git_github
Princeton jug git_githubPrinceton jug git_github
Princeton jug git_github
Yakov Fain
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
Yakov Fain
 
Surviving as a Professional Software Developer
Surviving as a Professional Software DeveloperSurviving as a Professional Software Developer
Surviving as a Professional Software Developer
Yakov Fain
 
Becoming a professional software developer
Becoming a professional software developerBecoming a professional software developer
Becoming a professional software developer
Yakov Fain
 

More from Yakov Fain (14)

Type script for_java_dev_jul_2020
Type script for_java_dev_jul_2020Type script for_java_dev_jul_2020
Type script for_java_dev_jul_2020
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Using JHipster 4 for generating Angular/Spring Boot apps
Using JHipster 4 for generating Angular/Spring Boot appsUsing JHipster 4 for generating Angular/Spring Boot apps
Using JHipster 4 for generating Angular/Spring Boot apps
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
RESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoTRESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoT
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Running a Virtual Company
Running a Virtual CompanyRunning a Virtual Company
Running a Virtual Company
 
Princeton jug git_github
Princeton jug git_githubPrinceton jug git_github
Princeton jug git_github
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
Surviving as a Professional Software Developer
Surviving as a Professional Software DeveloperSurviving as a Professional Software Developer
Surviving as a Professional Software Developer
 
Becoming a professional software developer
Becoming a professional software developerBecoming a professional software developer
Becoming a professional software developer
 

Recently uploaded

Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
Fwdays
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 

Recently uploaded (20)

Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 

Reactive programming in Angular 2

  • 1. Reactive programming in Angular 2 Yakov Fain yfain
  • 2. About myself • Solutions Architect at Farata Systems • Java Champion • Co-authored the book
 “Angular Development with TypeScript”
  • 3. The Agenda • Intro to RxJS
 
 - Observable
 - Observer
 - Operators • Observables in Angular 2
 
 - Forms
 - Http
 - Router
  • 4. RxJS 5 • Github repo:
 https://github.com/ReactiveX/rxjs • CDN: 
 https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js • Installing RxJS in the npm-based projects:
 
 npm install rxjs • Documentation:
 http://reactivex.io/rxjs 

  • 5. Main RxJS players • Observable - a producer of sequences of values • Observer - a consumer of observable values • Subscriber - connects observer with observable • Operator - en-route value transformation
  • 10. Observable
SubscriberObserver Data
 Source 
 Data Flow next next() error() complete()
  • 11. An Observable allows: • Subscribe/unsubscribe to its data stream • Emit the next value to the observer • Notify the observer about errors • Inform the observer about the stream completion
  • 12. An Observer provides: • A function to handle the next value from the stream • A function to handle errors • A function to handle end-of-stream
  • 13. Creating an Observable • Observable.create() - returns Observable that can invoke methods on Observer • Observable.from() - converts an array or iterable into Observable • Observable.fromEvent() - converts an event into Observable • Observable.fromPromise() - converts a Promise into Observable • Observable.range() - returns a sequence of integers in the specified range
  • 14. An Operator Observable Observable A transforming
 function
  • 15. Let’s have a beer let beers = [
 {name: "Stella", country: "Belgium", price: 9.50},
 {name: "Sam Adams", country: "USA", price: 8.50},
 {name: "Bud Light", country: "USA", price: 6.50},
 {name: "Brooklyn Lager", country: "USA", price: 8.00},
 {name: "Sapporo", country: "Japan", price: 7.50}
 ];

  • 16. An Operator Observable Observable A transforming
 function observableBeers
 .filter(beer => beer.price < 8))
  • 17. observableBeers = Rx.Observable.from(beers)
 .filter(beer => beer.price < 8)
 .map(beer => beer.name + ": $" + beer.price);
 
 observableBeers
 .subscribe(
 beer => console.log(beer),
 err => console.error(err),
 () => console.log("Streaming is over")
 ); Observable Beer Creating the 
 Observable
  • 18. observableBeers = Rx.Observable.from(beers)
 .filter(beer => beer.price < 8)
 .map(beer => beer.name + ": $" + beer.price);
 
 observableBeers
 .subscribe(
 beer => console.log(beer),
 err => console.error(err),
 () => console.log("Stream is over")
 ); Operators Observer Observable Beer
  • 19. observableBeers = Rx.Observable.from(beers)
 .filter(beer => beer.price < 8)
 .map(beer => beer.name + ": $" + beer.price);
 
 observableBeers
 .subscribe(
 beer => console.log(beer),
 err => console.error(err),
 () => console.log("Streaming is over")
 ); Observable Beer No 
 streaming yet Streaming
 begins
  • 24. RX: the data moves across your algorithm
  • 26. Error-handling operators • error() is invoked by the Observable on the Observer. • catch() - intercepts the error in the subscriber before the observer gets it. You can handle the error and re-subscribe.
 • retry(n) - retry immediately up to n times
 • retryWhen(fn) - retries as prescribed by the argument

  • 27. // Declaring function getData(): Observable {…} // data source 1
 function getCachedData(): Observable {…} // data source 2 function getDataFromAnotherService(): Observable {…} // data source 3 //Invoking and subscribing getData()
 .catch(err => { 
 
 if (err.status === 500){
 console.error("Switching to streaming cached beer data");
 return getCachedData();
 } else{
 console.error("Switching to another beer service");
 return getDataFromAnotherService();
 }
 
 })
 .map(beer => beer.name + ", " + beer.country)
 .subscribe(
 beer => console.log("Subscriber got " + beer)
 ); F a i
 l
 o v e
 r Failover with catch() plunker: http://bit.ly/2jXY9ha
  • 29. function getDrinks() {
 
 let beers = Rx.Observable.from([
 {name: "Stella", country: "Belgium", price: 9.50},
 {name: "Sam Adams", country: "USA", price: 8.50},
 {name: "Bud Light", country: "USA", price: 6.50}
 ]);
 
 let softDrinks = Rx.Observable.from([
 {name: "Coca Cola", country: "USA", price: 1.50},
 {name: "Fanta", country: "USA", price: 1.50},
 {name: "Lemonade", country: "France", price: 2.50}
 ]);
 
 return Rx.Observable.create( observer => {
 
 observer.next(beers); // pushing the beer pallet (observable)
 observer.next(softDrinks); // pushing the soft drinks pallet (observable)
 }
 );
 }
 
 getDrinks()
 .flatMap(drinks => drinks) // unloading drinks from pallets
 .subscribe(
 drink => console.log("Subscriber got " + drink.name + ": " + drink.price ) ); plunker http://bit.ly/2jZgc6T Operator flatMap• Handles every value emitted by an observable as another observable • Auto-subscribes to the internal observable and unwraps it
  • 31. Operator concat Subscribe to the next observable only when the previous completes. It’s useful for a sequential processing, e.g. HTTP requests. // Emulate HTTP requests let fourSecHTTPRequest = Rx.Observable.timer(4000).mapTo('First response'); let oneSecHTTPRequest = Rx.Observable.timer(1000).mapTo('Second response'); Rx.Observable .concat(fourSecHTTPRequest, oneSecHTTPRequest) .subscribe(res => console.log(res)); plunker http://bit.ly/2keEoiI
  • 33. Observables in Angular Code samples: https://github.com/yfain/observables
  • 35. An input field: FormControl • valueChanges - the value of the form control changes
 
 this.searchInput.valueChanges.subscribe(…); • statusChanges - status of the form control (valid/invalid)
 
 this.password.statusChanges.subscribe(…);
  • 36. Observable Events in Angular forms @Component({
 selector: "app",
 template: `
 <h2>Observable events demo</h2>
 <input type="text" placeholder="Enter stock" [formControl]="searchInput">
 `
 })
 class AppComponent {
 
 searchInput: FormControl;
 
 constructor(){
 this.searchInput = new FormControl('');
 
 this.searchInput.valueChanges
 .debounceTime(500)
 .subscribe(stock => this.getStockQuoteFromServer(stock));
 }
 
 getStockQuoteFromServer(stock) {
 
 console.log(`The price of ${stock} is ${100*Math.random().toFixed(4)}`);
 }
 } Observable
  • 38. Http and Observables 
 class AppComponent {
 
 products: Array<string> = [];
 
 constructor(private http: Http) {
 
 this.http.get(‘/products')
 .map(res => res.json())
 .subscribe(
 data => {
 
 this.products=data;
 },
 
 err =>
 console.log("Can't get products. Error code: %s, URL: %s ",
 err.status, err.url),
 
 () => console.log('Product(s) are retrieved')
 );
 }
 } O b s e r v e r
  • 39. @Component({
 selector: 'http-client',
 template: `<h1>All Products</h1>
 <ul>
 <li *ngFor="let product of products | async">
 {{product.title}}
 </li>
 </ul>
 <h2>{{errorMessage}}</h2>
 `})
 class AppComponent {
 
 products: Observable<Array<string>>;
 errorMessage: string;
 
 constructor(private http: Http) {
 
 this.products = this.http.get('/products')
 .map(res => res.json())
 .catch( err => {
 this.errorMessage =`Can't get product details from ${err.url},
 error ${err.status} `;
 return Observable.empty();
 });
 }
 } async pipe
  • 40. The switchMap operator RxJS 5, official doc:
 http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method- switchMap
 Returns an Observable that emits items based on applying a function that you supply to each item emitted by the source Observable, where that function returns an (so-called "inner") Observable. Each time it observes one of these inner Observables, the output Observable begins emitting the items emitted by that inner Observable. When a new inner Observable is emitted, switchMap stops emitting items from the earlier-emitted inner Observable and begins emitting items from the new one. It continues to behave like this for subsequent inner Observables.
  • 41. The switchMap operator RxJS 5, official doc:
 http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method- switchMap
 Returns an Observable that emits items based on applying a function that you supply to each item emitted by the source Observable, where that function returns an (so-called "inner") Observable. Each time it observes one of these inner Observables, the output Observable begins emitting the items emitted by that inner Observable. When a new inner Observable is emitted, switchMap stops emitting items from the earlier-emitted inner Observable and begins emitting items from the new one. It continues to behave like this for subsequent inner Observables.
  • 42. When a picture worth a thousand words http://reactivex.io/documentation/operators/images/switchMap.png
  • 43. The switchMap operator in English • An outer observable emits the data and switches over to the inner observable for processing • If the outer observable emits the new data while the inner one is still processing, the inner observable is terminated
 • The inner observable starts processing the newly emitted data
 • Example: A user types in a field (outer observable) and the HTTP requests are being made (inner observable) as the user types
  • 44. Killing HTTP requests with switchMap <input type="text" placeholder="Enter city" [formControl]="searchInput"> … this.searchInput.valueChanges
 .debounceTime(200)
 .switchMap(city => this.getWeather(city))
 .subscribe(
 res => {
 this.temperature =
 `Current temperature is ${res.main.temp}F, ` +
 `humidity: ${res.main.humidity}%`; },
 err => console.log(`Can't get weather. Error code: %s, URL: %s`, err.message, err.url)
 );
 }
 
 getWeather(city): Observable<Array> {
 return this.http.get(this.baseWeatherURL + city + this.urlSuffix)
 .map(res => res.json());
 } Outer Obs. Inner Obs.
  • 47. Receiving params in ActivatedRoute • Inject ActivatedRoute into a component to receive route params during navigation • Use ActivatedRoute.snapshot to get params once • Use ActivatedRoute.param.subscribe() for receiving multiple params over time
  • 48. Subject: Observable + Observer Can emit values and allows to subscribe to them @Component({
 selector: "app-root",
 template: `
 <h3>Using Subject for emitting/subscribing to keyup and input events</h3>
 <input type="text" placeholder="Start typing" 
 (input)="mySubject.next($event)" (keyup)="myKeySubject.next($event)">
 `
 })
 export class AppComponent {
 
 mySubject: Observable<Event> = new Subject(); // Observable for any events myKeySubject: Observable<KeyboardEvent> = new Subject(); // Observable for keyboard events
 
 constructor(){
 
 this.myKeySubject.subscribe(({type, key}) => console.log(`Event: ${type} key: ${key}`));
 
 this.mySubject.subscribe(({type, target}) => console.log(
 `Event: ${type} value: ${(<HTMLInputElement>target).value}`));
 }
 }
  • 49. Sharing an Observable @Component({
 selector: "app-root",
 template: `
 <h3>Sharing Observable between subscribers to keyup and input events</h3>
 <input type="text" placeholder="Start typing" 
 (input)="mySubject.next($event)" 
 (keyup)="mySubject.next($event)">
 
 <br> Subscriber to input events got {{inputValue}}
 <p>
 <br> Subscriber to input events got {{keyValue}} 
 `
 })
 export class AppComponent {
 
 keyValue: string;
 inputValue: string;
 
 mySubject: Observable<Event> = new Subject().share(); // Single Observable for any events
 
 constructor(){
 
 // Subscriber 1
 this.mySubject
 .filter(({type}) => type==="keyup")
 .map(e => (<KeyboardEvent>e).key)
 .subscribe((value) => this.keyValue=value);
 
 // Subscriber 2
 this.mySubject
 .filter(({type}) => type==="input")
 .map(e => (<HTMLInputElement>e.target).value)
 .subscribe((value) => this.inputValue=value);
 }
 }
  • 50. @Component({
 selector: "app",
 template: `
 <h2>Sharing the same stream</h2>
 <input #myinput type="text" placeholder="Start typing" > <br> Subscribing to each value: {{data1}}
 <br> Subscribing to 3-second samples: {{data2}}
 `})
 class AppComponent { 
 @ViewChild('myinput') myInputField: ElementRef;
 
 data1: string;
 data2: string;
 
 ngAfterViewInit(){
 
 let keyup$: Observable = Observable.fromEvent(this.myInputField.nativeElement, 'keyup');
 
 let keyupValue$ = keyup$
 .map(event => event.target.value)
 .share();
 
 // Subscribe to each keyup
 keyupValue$
 .subscribe(value => this.data1 = value);
 
 // Subscribe to 3-second samples
 keyupValue$
 .sample(Observable.interval(3000))
 .subscribe(value => this.data2 = value);
 }
 } Accessing native elements with ElementRef Using ElementRef
 is not recommended
  • 52. Subscribing to EventEmitter export declare class EventEmitter<T> extends Subject<T> {} myEvent: EventEmitter<string> = new EventEmitter(); myEvent.emit("Hello World"); … myEvent.subscribe(event => console.log(" Received " + event); Your app: Angular: Has Observer
 and Observable
  • 54. Subscribing to EventEmitter export declare class EventEmitter<T> extends Subject<T> {} myEvent: EventEmitter<string> = new EventEmitter(); myEvent.emit("Hello World"); … myEvent.subscribe(event => console.log(" Received " + event); Your app: Angular:
  • 55. Mediator, DI, Events, and Observables StateService Component1 with injected StateService Component2 with injected StateService EventEmitter Emit event
 on StateService Subscribe to event
 of StateService
  • 58. Wrapping WebSocket into Observable import {Observable } from 'rxjs/Observable';
 
 export class BidService{
 
 ws: WebSocket;
 
 createObservableSocket(url:string): Observable{
 
 this.ws = new WebSocket(url);
 
 return new Observable(
 observer => {
 
 this.ws.onmessage = (event) => observer.next(event.data);
 
 this.ws.onerror = (event) => observer.error(event);
 
 this.ws.onclose = (event) => observer.complete();
 });
 }
 
 }
  • 59. Subscribing to WebSocket’s messages @Component({ … })
 class BidComponent {
 newBid: Bid;
 
 constructor(private wsService: BidService) {
 
 this.wsService.createObservableSocket("ws://localhost:8085")
 .map(res => JSON.parse(res))
 .subscribe(
 data => {
 
 this.newBid = data;
 this.newBid.bidTime= Date.parse(data.bidTime);
 console.log(this.newBid);
 },
 err => console.log( err),
 () => console.log( 'The bid stream is complete')
 );
 }
 
 }
  • 60. Demo1. Open http_websocket_samples
 2. systemjs.config: bids/bid-component.ts 3. npm run tsc
 
 4.npm run bidServer
 
 5.http://localhost:8000
  • 61. Summary • Everything is an observable • No data is pushed to you until you subscribe • Chain the operators to pre-process the observable data before it gets to the subscriber • Angular offers you ready-to-use observables in multiple components and services • You can wrap the data pushed to your app into an Observable
  • 62. Thank you! • Code samples:
 https://github.com/yfain/observables • Training inquiries: 
 training@faratasystems.com • My blog:
 yakovfain.com • Twitter: @yfain