Published
Edited
Nov 28, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Rx.interval(1000).pipe(take(5), map(value => value * 2)).subscribe(a => console.log("Rx6:", a))
Insert cell
Insert cell
/*Rx.interval(2000).pipe(
take(5),
concatMap(index => Rx.interval(1000).pipe(take(3), map(value => ({value: value, index: index}))))
).subscribe(v => console.log("FlatMap:", v))*/
Insert cell
/*observables = [
Rx.interval(1000).pipe(take(5), map(value => "obs1 " + value)),
Rx.interval(2000).pipe(take(2), map(value => "obs2 " + value)),
Rx.interval(3000).pipe(take(3), map(value => "obs3 " + value))
]*/
Insert cell
/*Rx.combineLatest(observables).subscribe(data => console.log(data))*/
Insert cell
/*observableObj = ({
obs1: Rx.interval(1000).pipe(take(5), map(value => 'Obs1 ' + value)),
obs2: Rx.interval(2000).pipe(take(2), map(value => 'Obs2 ' + value)),
obs3: Rx.interval(3000).pipe(take(4), map(value => 'Obs3 ' + value))
})*/
Insert cell
/*Rx.combineLatest(observableObj).subscribe(data => console.log(data))*/
Insert cell
Insert cell
container = html`<ul>`
Insert cell
/*{
console.clear();
let coldObservable$ = Rx.interval(1000).pipe(take(3));
let observable$ = coldObservable$.pipe(
tap(data => console.log('tapped', data))
)
observable$.subscribe()
observable$.subscribe()
}*/
Insert cell
Insert cell
/*{
console.clear();
let subject$ = new Rx.Subject();
let observable$ = subject$.pipe(
tap(data => console.log('tapped', data)),
share()
)
const subscription1 = observable$.subscribe(data => console.log('subscribed 1', data))
const subscription2 = observable$.subscribe(data => console.log('subscribed 2', data))
let subscription3 = null;
Rx.interval(1000).pipe(take(4)).subscribe(data => {
if (data === 2) {
subscription1.unsubscribe();
subscription2.unsubscribe();
subscription3 = observable$.subscribe(data => console.log('subscribed 3', data))
}
subject$.next(data);
})
}*/
Insert cell
Insert cell
/*Rx.interval(1000).pipe(
take(5),
switchMap(() => Rx.throwError('puppa').pipe(
catchError(err => {
return Rx.EMPTY
})
)),
).subscribe(logObserver)*/
Insert cell
Insert cell
/*{
console.clear();
let object = {
a1: 'a1',
a2: 'a2'
};
let subject = new Rx.Subject();
let smartObsOfObj = subject.pipe(
scan((acc, obj) => {
let prevKeys = _.keys(acc.data ? acc.data : acc);
let actualKeys = _.keys(obj.data ? obj.data : obj);
if (actualKeys.length > prevKeys.length) {
return {'add': _.difference(actualKeys, prevKeys), 'data': obj}
} else if (prevKeys.length > actualKeys.length) {
return {'remove': _.difference(prevKeys, actualKeys), 'data': obj}
} else {
return {'data': obj}
}
}, {data: null}),
filter(obj => _.has(obj, 'add') || _.has(obj, 'remove'))
).subscribe(logObserver);
setTimeout(() => subject.next(_.clone(object)), 1000);
setTimeout(() => {
object['a3'] = 'a3';
subject.next(_.clone(object));
}, 2000);
setTimeout(() => {
object = _.omit(object, 'a2');
subject.next(_.clone(object));
}, 3000);
setTimeout(() => {
subject.next(_.clone(object));
}, 4000);
}*/
Insert cell
Insert cell
{
const obs1 = Rx.interval(2000).pipe(first(), shareReplay(1), map(() => {
throw 'puppa'
}), catchError(err => Rx.of({errorStatus: err})));
const obs2 = Rx.interval(1000).pipe(first(), shareReplay(1));
Rx.combineLatest([obs1, obs2]).subscribe(logObserver);
}
Insert cell
Insert cell
// Rx4.Observable.interval(1000).take(5).map(value => value * 3).subscribe(a => console.log("Rx4:", a))
Insert cell
// Rx4.Observable.interval(1000).take(10).map(() => "puppa").subscribe(a => console.log("test:", a))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Rx4 = require('https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.1.0/rx.all.js')
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more