Skip to content

Instantly share code, notes, and snippets.

View artberri's full-sized avatar
👋
Hello world!

Alberto Varela artberri

👋
Hello world!
View GitHub Profile
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import { Todo, ITodoView } from '../../../app/src';
@Component
export class VueTodoMixin extends TodoMixin(Vue) {}
@Component({
mixins: [VueTodoMixin]
})
<div class="view">
<input class="toggle"
type="checkbox"
[checked]="isCompleted"
(click)="onToggleCheckboxClicked()">
<label (dblclick)="onDoubleClicked()">{{ todo.title }}</label>
<button class="destroy" (click)="onRemoveButtonClicked()"></button>
</div>
<input [(ngModel)]="todoTitleInput"
class="edit"
import { Component, Input, HostBinding, OnInit } from '@angular/core';
import { Todo, TodoMixin, ITodoView, TodoPresenter, Injector } from '../../../../../app/src';
import { BaseView } from 'src/app/base.view';
@Component({
selector: '[app-todo]',
templateUrl: 'todo.template.html',
styles: []
})
export class TodoComponent extends TodoMixin(BaseView) implements ITodoView, OnInit {
// ...
describe('On toggle checkbox clicked', () => {
describe('when it is initially active', () => {
beforeEach(() => {
view.todo = activeTodo;
presenter.attach(view);
jest.clearAllMocks();
});
test('completes the todo', () => {
import { Service, BasePresenter, Mediator } from '../framework';
import { AppState, LoadTodosCommand, SaveTodosCommand, GetAllTodosQuery, ContainsAnyTodosQuery } from '../model';
import { IAppView } from '../views';
@Service()
export class AppPresenter extends BasePresenter<IAppView> {
constructor(
private readonly mediator: Mediator,
private readonly state: AppState
) {
import { Todo } from '../entities';
export abstract class TodoStorageService {
public abstract getTodos(): Todo[];
public abstract saveTodos(todos: Todo[]): void;
}
import { Todo } from '../../model';
import { Service, StateContainer } from '../../framework';
@Service()
export class TodosState extends StateContainer<Todo[]> {
constructor() {
super([]);
}
public initialize(todos: Todo[]): void {
export class GetVisibleTodosQueryHandler extends SimpleQueryHandler<Todo[]> {
constructor(
private readonly filterState: FilterState,
private readonly todosState: TodosState
) {
super(GetVisibleTodosQuery);
}
public handle(): Todo[] {
switch (this.filterState.state) {
import { CommandHandler, Service } from '../../../../framework';
import { EditTodoCommand, IEditTodoPayload } from '../edit-todo.command';
import { TodosState } from '../../../state';
@Service()
export class EditTodoCommandHandler extends CommandHandler<IEditTodoPayload> {
constructor(
private readonly todosState: TodosState
) {
super(EditTodoCommand);
import { Type, Injector } from '../framework';
import { ITodoUserActions } from './todo.view';
import { TodoPresenter } from '../presenters';
// tslint:disable-next-line:typedef
export function TodoMixin<TBase extends Type>(base: TBase) {
return class extends base implements ITodoUserActions {
public presenter: TodoPresenter = Injector.resolve(TodoPresenter);
public onDoubleClicked(): void {