Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active September 21, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/030c78abb307c1efe27c192f8b8b2b00 to your computer and use it in GitHub Desktop.
Save NetanelBasal/030c78abb307c1efe27c192f8b8b2b00 to your computer and use it in GitHub Desktop.
export class TodosPageComponent extends React.PureComponent {
state: { todos: Todo[]; filter: string } = { todos: [], filter: '' };
constructor(props) {
super(props);
}
add = (text: string) => todosService.add(text);
toggleTodo = (id: ID) => todosService.complete(id);
deleteTodo = (id: ID) => todosService.delete(id);
changeFilter = ({ target: { value } }) => {
todosService.updateFilter(value);
};
componentDidMount() {
todosQuery.selectVisibleTodos$
.pipe(untilDestroyed(this))
.subscribe(todos => this.setState({ todos }));
todosQuery.selectVisibilityFilter$
.pipe(untilDestroyed(this))
.subscribe(filter => this.setState({ filter }));
}
render() {
return (
<div>
<AddTodo add={this.add} />
<TodoList
todos={this.state.todos}
onToggle={this.toggleTodo}
onDelete={this.deleteTodo}
/>
<Filters onChange={this.changeFilter} active={this.state.filter} />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment