Created
July 11, 2019 20:58
-
-
Save iazel/2e3b185c1fb941c14f26557b23ea904d to your computer and use it in GitHub Desktop.
Composable Reactive UI / TodoStore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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