Skip to content

Instantly share code, notes, and snippets.

Avatar

Sébastien Sougnez ssougnez

View GitHub Profile
View wamr-95.ts
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
observable
.pipe(
catchError(err => of(-1))
)
.subscribe({
next: x => console.log(`${x} received`),
complete: () => console.log('Completed'),
View wamr-94.ts
observable.subscribe({
next: x => console.log(`${x} received`),
complete: () => console.log('Completed'),
error: err => console.warn(err)
});
View wamr-93.ts
import { Observable } from 'rxjs';
const observable = new Observable<number>(observer => {
let x = 0;
const interval = setInterval(() => {
if (x === 5) {
observer.error('Oops');
}
else {
View wamr-92.ts
import { interval } from 'rxjs';
import { mergeMap, takeUntil } from 'rxjs/operators';
interval(1000)
.pipe(
takeUntil(this.destroy$),
mergeMap(() => this._http.put('http://localhost:3000/documents/1', { lastUpdate: new Date() }))
)
.subscribe(x => console.log('Document saved!'));
View wamr-91.ts
import { interval } from 'rxjs';
import { mergeMap, take, tap } from 'rxjs/operators';
interval(1000)
.pipe(
take(3),
mergeMap(() => interval(1000).pipe(tap(() => console.log('foo'))))
)
.subscribe(() => console.log('bar'));
View wamr-90.ts
import { interval } from 'rxjs';
import { mergeMap, tap } from 'rxjs/operators';
const s = interval(1000)
.pipe(
mergeMap(() => interval(1000).pipe(tap(() => console.log('foo'))))
)
.subscribe(() => console.log('bar'));
setTimeout(() => s.unsubscribe(), 3500);
View wamr-89.ts
const s = interval(1000)
.pipe(
map(() => interval(1000).pipe(tap(() => console.log('foo'))).subscribe())
)
.subscribe(() => console.log('bar'));
setTimeout(() => s.unsubscribe(), 3500);
View wamr-88.ts
interval(1000)
.pipe(
takeUntil(this.destroy$),
map(() => this._http.put('http://localhost:3000/documents/1', { lastUpdate: new Date() }).subscribe())
)
.subscribe(x => console.log(x));
View wamr-87.ts
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { interval } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { BaseComponent } from './base-component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
View wamr-86.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],