Skip to content

Instantly share code, notes, and snippets.

View nerdic-coder's full-sized avatar
💭
Check out my project Novels AI at https://novels-ai.com

Johan Axelsson nerdic-coder

💭
Check out my project Novels AI at https://novels-ai.com
View GitHub Profile
@nerdic-coder
nerdic-coder / getHeroesHttp.ts
Created May 11, 2018 21:17
getHeroesHttp.ts
getHeroes(): Observable<Hero[]> {
return Observable.create((observer) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', CONFIG.SERVER_URL + 'heroes');
xhr.onload = () => {
if (xhr.status === 200) {
this.messageService.add(`HeroService: fetched heroes`);
observer.next(JSON.parse(xhr.responseText));
}
else {
export const CONFIG: Config =
{ SERVER_URL: 'http://localhost:3000/' };
class Config {
SERVER_URL: string;
}
{
"heroes": [
{
"id": 11,
"name": "Mr. Nice"
},
{
"id": 12,
"name": "Narcos"
},
<button onClick={() => this.goBack()}>go back</button>
goBack(): void {
window.history.back();
}
@nerdic-coder
nerdic-coder / getHero-service.tsx
Created May 10, 2018 16:36
getHero-service.tsx
getHero(id: number): Observable<Hero> {
// TODO: send the message _after_ fetching the hero
this.messageService.add(`HeroService: fetched hero id=${id}`);
return of(HEROES.find(hero => hero.id === id));
}
@nerdic-coder
nerdic-coder / hero-details.tsx
Created May 10, 2018 16:31
hero-details.tsx with id param
import { Component, Prop } from '@stencil/core';
import { MatchResults } from '@stencil/router';
import { Hero } from '../../models/hero';
import { HeroService } from '../../services/hero.service';
@Component({
tag: 'app-hero-details',
styleUrl: 'hero-details.css'
})
export class HeroDetails {
@nerdic-coder
nerdic-coder / hero-list-link.html
Created May 9, 2018 21:05
hero-list-link.html
@nerdic-coder
nerdic-coder / hero-details-route-link.html
Last active May 9, 2018 20:46
hero-details-route-link.html
import { Component, State } from '@stencil/core';
import { Hero } from '../../models/hero';
import { HeroService } from '../../services/hero.service';
@Component({
tag: 'app-dashboard',
styleUrl: 'dashboard.css'
})
export class Dashboard {