javascript observable

Опубликовано: 02 Июнь 2019
на канале: Programming with Karthik
716
2

javascript observable
Angular 9 Tutorial | EP16 | rxjs npm (KINDLY SUBSCRIBE)
Complete Playlist:    • Angular 9 Tutorial  

Part 2:    • javascript observable - 2  

In this session we will be seeing
Observables in Angular:
way to handle asynchronous programming

ReactX -- asynchronous Programming
Not part of Javascript
Rxjs
Rxjava
Rxpython

Observable
1) Stream of data
2)Observer pattern
2) subscriber subscribed to the Observables can receive data
till the Observables says it is complete or error.

Observables in Angular:
1)EventEmitter @Output
3)Routing - Observables
4)HttpService

complete
Unsubsribing

Creating your own Observable in angular:
import { Component, OnDestroy, OnInit } from '@angular/core';

import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
import { Observer } from 'rxjs/Observer';
import { Subscription } from 'rxjs/Subscription';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit, OnDestroy {
numbersObsSubscription: Subscription;
customObsSubscription: Subscription;

constructor() { }

ngOnInit() {
const myNumbers = Observable.interval(1000)
.map(
(data: number) = {
return data * 2;
}
);
this.numbersObsSubscription = myNumbers.subscribe(
(number: number) = {
console.log(number);
}
);

const myObservable = Observable.create((observer: Observer) = {
setTimeout(() = {
observer.next('first package');
}, 2000);
setTimeout(() = {
observer.next('second package');
}, 4000);
setTimeout(() = {
// observer.error('this does not work');
observer.complete();
}, 5000);
setTimeout(() = {
observer.next('third package');
}, 6000);
});
this.customObsSubscription = myObservable.subscribe(
(data: string) = { console.log(data); },
(error: string) = { console.log(error); },
() = { console.log('completed'); }
);
}

ngOnDestroy() {
this.numbersObsSubscription.unsubscribe();
this.customObsSubscription.unsubscribe();
}

}


На этой странице сайта вы можете посмотреть видео онлайн javascript observable длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Programming with Karthik 02 Июнь 2019, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 716 раз и оно понравилось 2 зрителям. Приятного просмотра!