Skip to content

Instantly share code, notes, and snippets.

View LayZeeDK's full-sized avatar
🇩🇰
Denmark

Lars Gyrup Brink Nielsen LayZeeDK

🇩🇰
Denmark
View GitHub Profile
@LayZeeDK
LayZeeDK / heroes.container.spec.ts
Created October 25, 2018 19:00
Heroes: Testing deletion of a hero
it('emits all other heroes immediately', fakeAsync(() => {
const elektra: Hero = femaleMarvelHeroes.find(x => x.name === 'Elektra');
container.delete(elektra);
tick();
expect(observer).toHaveBeenCalledWith(
femaleMarvelHeroes.filter(x => x.id !== elektra.id));
}));
@LayZeeDK
LayZeeDK / heroes.container.spec.ts
Created October 25, 2018 19:08
Heroes: Testing deletion of a hero
it('emits the specified hero when server fails', fakeAsync(() => {
heroServiceStub.deleteHero.and.returnValue(
throwError(new Error('timeout'), asapScheduler));
const storm: Hero = femaleMarvelHeroes.find(x => x.name === 'Storm');
container.delete(storm);
tick();
const emittedHeroes: Hero[] = observer.calls.mostRecent().args[0];
emittedHeroes.sort(compareIdAscending);
@LayZeeDK
LayZeeDK / model-view-presenter-angular-project-structure.txt
Created October 25, 2018 19:29
Model-View-Presenter Angular project structure
src
└── app
├── dashboard
│ ├── dashboard.component.css
│ ├── dashboard.component.html
│ ├── dashboard.component.spec.ts
│ ├── dashboard.component.ts
│ ├── dashboard.container.html
│ ├── dashboard.container.spec.ts
│ └── dashboard.container.ts
@LayZeeDK
LayZeeDK / container-component-file-structure.txt
Last active October 25, 2018 19:57
Heroes: Container component file structure
heroes
├── heroes.component.css
├── heroes.component.html
├── heroes.component.spec.ts
├── heroes.component.ts
├── heroes.container.html
├── heroes.container.spec.ts
└── heroes.container.ts
@LayZeeDK
LayZeeDK / TodoItem.cs
Last active August 29, 2019 07:59
C#: Todo item
public class TodoItem
{
public string Id { get; set; }
public bool IsDone { get; set; }
public string Title { get; set; }
public async Task Save()
{
// Write to database
}
@LayZeeDK
LayZeeDK / todo-item.ts
Last active November 2, 2018 10:33
TypeScript: Todo item
class TodoItem {
id: string;
isDone: boolean;
title: string;
save(): Promise<void> {
return fetch("/todo/" + this.id, {
body: JSON.stringify(this),
method: "POST",
})
@LayZeeDK
LayZeeDK / edit-todo-item-view.ts
Last active November 2, 2018 10:33
TypeScript: Edit todo item view
class EditTodoItemView {
todoItem: TodoItem;
onInitialize(id: string): Promise<void> {
return this.readTodoItem(id)
.then(todoItem => this.todoItem = todoItem)
.then(() => undefined);
}
readTodoItem(id: string): Promise<TodoItem> {
@LayZeeDK
LayZeeDK / todo-item.ts
Created November 2, 2018 10:48
TypeScript: Todo item with constructor
class TodoItem {
id: string;
isDone: boolean;
title: string;
constructor(properties) {
this.id = properties.id;
this.isDone = properties.isDone;
this.title = properties.title;
}
@LayZeeDK
LayZeeDK / edit-todo-item-view.ts
Created November 2, 2018 10:51
TypeScript: Edit todo item view using the new keyword
class EditTodoItemView {
todoItem: TodoItem;
onInitialize(id: string): Promise<void> {
return this.readTodoItem(id)
.then(todoItem => this.todoItem = todoItem)
.then(() => undefined);
}
readTodoItem(id: string): Promise<TodoItem> {
@LayZeeDK
LayZeeDK / heroes.component.ts
Last active November 12, 2018 21:44
Heroes: Container component with mutable state
import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HeroService } from '../hero.service';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.container.html',
})
export class HeroesContainerComponent implements OnInit {