This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Planet { | |
name: string; | |
rotation_period: number; | |
orbital_period: number; | |
diameter: number; | |
climate: string; | |
gravity: string; | |
terrain: string; | |
surface_water: number; | |
population: number; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import { ReactiveFormsModule } from '@angular/forms'; | |
import { HttpClientModule } from '@angular/common/http'; | |
import { AppComponent } from './app.component'; | |
import { SearchBarComponent } from './search-bar/search-bar.component'; | |
import { PlanetService } from './planet.service'; | |
@NgModule({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { FormControl } from '@angular/forms'; | |
import { Observable } from 'rxjs'; | |
import { switchMap } from 'rxjs/operators'; | |
import { PlanetService } from '../planet.service'; | |
import { Planet } from '../planet'; | |
@Component({ | |
selector: 'app-search-bar', | |
templateUrl: './search-bar.component.html' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="p-4"> | |
<p class="mb-2">search-bar works!</p> | |
<div class="relative"> | |
<input [formControl]="search" type="text" class="border border-grey rounded shadow-inner p-2 w-full" placeholder="Search..."> | |
<div class="absolute mt-1 bg-grey w-full rounded shadow"> | |
<ul class="list-reset"> | |
<li *ngFor="let planet of (planets$ | async)" class="p-2">{{ planet.name }}</li> | |
</ul> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { FormControl } from '@angular/forms'; | |
import { Observable } from 'rxjs'; | |
import { switchMap, debounceTime } from 'rxjs/operators'; | |
import { PlanetService } from '../planet.service'; | |
import { Planet } from '../planet'; | |
@Component({ | |
selector: 'app-search-bar', | |
templateUrl: './search-bar.component.html' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GetItem finds a returns a single item from a dynamodb table. | |
// It returns an element and an error if any. | |
// If no element is found, will return nil without an error | |
func GetItem(id string, dest interface{}) error { | |
tableName := "table-name" | |
// create get operation information | |
item := &dynamodb.GetItemInput{ | |
TableName: aws.String(tableName), | |
Key: map[string]*dynamodb.AttributeValue{ |
OlderNewer