Created
July 11, 2019 21:44
-
-
Save iazel/57652007a87019817f3cb3ad97a96b56 to your computer and use it in GitHub Desktop.
Composable Reactive UI / TodoStore - Todos
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 } 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