Skip to content

Instantly share code, notes, and snippets.

View nerdic-coder's full-sized avatar
💭
Block Photos 2.0 will be out soon and is going to be great!

Johan Axelsson nerdic-coder

💭
Block Photos 2.0 will be out soon and is going to be great!
View GitHub Profile
@nerdic-coder
nerdic-coder / heroes.css
Created April 24, 2018 18:32
Hero list stylesheet
/* HeroesComponent's private CSS styles */
.selected {
background-color: #CFD8DC !important;
color: white;
}
.heroes {
margin: 0 0 2em 0;
list-style-type: none;
padding: 0;
width: 15em;
@nerdic-coder
nerdic-coder / hero-loop.html
Last active April 24, 2018 19:31
Hero loop with JSX map operator
<ul class="heroes">
{this.heroes.map((hero) =>
<li>
<span class="badge">{hero.id}</span> {hero.name}
</li>
)}
</ul>
@nerdic-coder
nerdic-coder / hero-details.ts
Created April 24, 2018 20:15
Selected Hero Details
<h2>{ this.selectedHero.name.toUpperCase() } Details</h2>
<div><span>id: </span>{this.selectedHero.id}</div>
<div>
<label>name:
<input type="text" value={this.selectedHero.name} onInput={(event) => this.handleChangeName(event)} placeholder="name" />
</label>
</div>
@nerdic-coder
nerdic-coder / heroes.tsx
Created April 24, 2018 20:32
selected hero condition
{this.selectedHero ? (
<div>
<h2>{ this.selectedHero.name.toUpperCase() } Details</h2>
<div><span>id: </span>{this.selectedHero.id}</div>
<div>
<label>name:
<input type="text" value={this.selectedHero.name} onInput={(event) => this.handleChangeName(event)} placeholder="name" />
</label>
</div>
</div>
@nerdic-coder
nerdic-coder / hero-details.spec.ts
Created April 25, 2018 18:45
hero detials unit tests
import { render } from '@stencil/core/testing';
import { HeroDetails } from './hero-details';
describe('app-hero-details', () => {
it('should build', () => {
expect(new HeroDetails()).toBeTruthy();
});
describe('rendering', () => {
beforeEach(async () => {
@nerdic-coder
nerdic-coder / hero-details.tsx
Created April 25, 2018 18:47
Hero details component
import { Component, Prop } from '@stencil/core';
import { Hero } from '../../models/hero';
@Component({
tag: 'app-hero-details',
styleUrl: 'hero-details.css'
})
export class HeroDetails {
@Prop({ mutable: true }) private hero: Hero;
@nerdic-coder
nerdic-coder / hero.service.ts
Created April 27, 2018 17:50
hero.service.ts
import { Observable } from 'rxjs';
import { of } from 'rxjs';
import { Hero } from '../models/hero';
import { HEROES } from './mock-heroes';
export class HeroService {
private static _instance: HeroService;
@nerdic-coder
nerdic-coder / hero-service-instance.ts
Created April 27, 2018 20:55
hero-service-instance.ts
private heroService: HeroService;
constructor() {
this.heroService = HeroService.Instance;
}
@nerdic-coder
nerdic-coder / getHeroes.ts
Created April 27, 2018 21:26
getHeroes.ts
getHeroes(): void {
this.heroService.getHeroes()
.subscribe(heroes => this.heroes = heroes);
}
@nerdic-coder
nerdic-coder / componentWillLoad.ts
Created April 27, 2018 21:30
componentWillLoad.ts
componentWillLoad() {
this.getHeroes();
}