Skip to content

Instantly share code, notes, and snippets.

View nicowernli's full-sized avatar
🏠
Working from home

Nicolás Wernli nicowernli

🏠
Working from home
  • Málaga, Spain
  • 21:56 (UTC +02:00)
  • LinkedIn in/nwernli
View GitHub Profile
@nicowernli
nicowernli / planet.service.ts
Created August 31, 2018 07:43
Planet service
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Planet } from './planet';
@Injectable()
export class PlanetService {
constructor(private http: HttpClient) {}
@nicowernli
nicowernli / rxjs-switchMap.js
Created March 23, 2018 11:53
Medium switchMap
const Rx = require('rxjs');
const long$ = Rx.Observable.interval(1000).take(4);
const short$ = Rx.Observable.interval(500).take(4);
long$
.switchMap(long => short$.map(short => console.log({ long, short })))
.subscribe();
/** Output
@nicowernli
nicowernli / rxjs-flatMap.js
Last active March 23, 2018 11:54
Medium flatMap example
const Rx = require('rxjs');
const long$ = Rx.Observable.interval(1000).take(4);
const short$ = Rx.Observable.interval(500).take(4);
long$
.flatMap(long => short$.map(short => console.log({ long, short })))
.subscribe();
/** Output
@nicowernli
nicowernli / rxjsmap.js
Last active March 23, 2018 11:26
Medium rxjs.map operator
const Rx = require('rxjs');
Rx.Observable.interval(1000)
.map(intervalValue => intervalValue * 2)
.subscribe(console.log); // 0, 2, 4, 6, 8, 10, 12, 14, 16, etc