Links:
-
Доклад с HolyJS 2016 Piter: Виктор Русакович — Реактивное программирование: управляем потоками данных
-
RxMarbles - visualization of Rx operators
-
Build an Angular 2 Instant Search Component - course by egghead.io. Learn more about using observables in Angular 2
Samples:
- Stream from event
const input = document.getElementById('input');
const source = Rx.Observable.fromEvent(input, 'click');
const subscription = source.subscribe(
x => console.log('Next: Clicked!'), // .onNext()
err => console.log('Error: ', err) // .onError()
() => console.log('Completed') // .onComplete()
);
input.trigger('click');
// => Next: Clicked!
- Stream from Promise
const promise = Promise.reject(new Error('reason'));
const source = Rx.Observable.fromPromise(promise);
const subscription = source.subscribe(
x => console.log('Next msg') // .onNext()
err => console.log('Error: %s', err) // .onError()
() => console.log('Completed') // .onComplete()
);
// => Error: Error: reject
// Create a promise which resolves 42
var promise = Promise.resolve(42)
var source = Rx.Observable.fromPromise(promise);
const subscription = source.subscribe(
x => console.log('Next msg') // .onNext()
err => console.log('Error: %s', err) // .onError()
() => console.log('Completed') // .onComplete()
);
// => Next: 42
// => Completed