Skip to content

Instantly share code, notes, and snippets.

@iazel
Created July 11, 2019 20:58
Show Gist options
  • Save iazel/2e3b185c1fb941c14f26557b23ea904d to your computer and use it in GitHub Desktop.
Save iazel/2e3b185c1fb941c14f26557b23ea904d to your computer and use it in GitHub Desktop.
Composable Reactive UI / TodoStore
import { StreamBox, RW$B } from '@crui/reactive/rx/box';
export type Todo = {
text: string,
}
export type TodoList = Todo[]
export class TodoStore {
private readonly input: StreamBox<string>
private readonly todos: TodoList
constructor() {
this.input = new StreamBox('')
this.todos = []
}
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()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment