utb
Version:
Unified todomvc benchmark
40 lines (32 loc) • 975 B
JavaScript
// @flow
import {action, mem} from 'lom_atom'
import {ENTER_KEY} from '../../../common/interfaces'
import TodoRepository from './TodoRepository'
import TodoHeaderViewOrig from '../../../common/TodoHeaderView'
export class TodoHeaderService {
title: string = ''
_todoRepository: TodoRepository
constructor(todoRepository: TodoRepository) {
this._todoRepository = todoRepository
}
onInput({target}: Event) {
this.title = (target: any).value
}
onKeyDown(e: Event) {
if (e.keyCode === ENTER_KEY && this.title) {
e.preventDefault()
const text = this.title.trim()
if (text) {
this._todoRepository.addTodo(text)
this.title = ''
}
}
}
}
export default function TodoHeaderView(
{todoHeaderService}: {
todoHeaderService: TodoHeaderService;
}
) {
return TodoHeaderViewOrig(todoHeaderService)
}