Skip to content

Instantly share code, notes, and snippets.

@iazel
Created July 11, 2019 21:44
Show Gist options
  • Save iazel/57652007a87019817f3cb3ad97a96b56 to your computer and use it in GitHub Desktop.
Save iazel/57652007a87019817f3cb3ad97a96b56 to your computer and use it in GitHub Desktop.
Composable Reactive UI / TodoStore - Todos
import { StreamBox } from '@crui/reactive/rx/box';
import { RW$B, R$L, DRW$L } from '@crui/reactive/rx/box/types';
import { StreamList } from '@crui/reactive/rx/list';
export type Todo = {
text: string,
}
export type TodoList = R$L<Todo>
export class TodoStore {
private readonly input: StreamBox<string>
private readonly todos: DRW$L<Todo>
constructor() {
this.input = new StreamBox('')
this.todos = new StreamList([])
}
getInput(): RW$B<string> {
return this.input
}
addTodo(todo: string): void {
this.todos.push({
text: todo,
})
}
getTodos(): TodoList {
return this.todos
}
dispose() {
this.input.destroy()
this.todos.destroy()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment