mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
battled and won typings
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import * as actions from '../actions';
|
||||
import { actions, TodoAction } from '../actions';
|
||||
import { Store, FilterTypes } from '../store';
|
||||
import { connect } from 'react-redux';
|
||||
import { Dispatch } from 'redux';
|
||||
@@ -11,7 +11,7 @@ export function mapStateToProps({ todos, filter }: Store) {
|
||||
};
|
||||
}
|
||||
|
||||
export function mapDispatchToProps(dispatch: Dispatch<actions.TodoAction>) {
|
||||
export function mapDispatchToProps(dispatch: Dispatch<TodoAction>) {
|
||||
return {
|
||||
add: (label: string) => dispatch(actions.add(label)),
|
||||
remove: (id: string) => dispatch(actions.remove(id)),
|
||||
|
||||
@@ -14,21 +14,27 @@ export interface TodoListProps {
|
||||
export class TodoList extends React.Component<TodoListProps> {
|
||||
render() {
|
||||
const { filter, todos } = this.props;
|
||||
let filteredTodos = todos;
|
||||
let filteredTodos: typeof todos = {};
|
||||
|
||||
switch (filter) {
|
||||
case 'completed':
|
||||
filteredTodos = Object.keys(todos).reduce(
|
||||
(collection, id) => (todos[id].completed ? { ...collection, id: todos[id] } : collection),
|
||||
{}
|
||||
);
|
||||
Object.keys(todos).forEach(id => {
|
||||
if (todos[id].completed) {
|
||||
filteredTodos[id] = todos[id];
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case 'active':
|
||||
filteredTodos = Object.keys(todos).reduce(
|
||||
(collection, id) => (!todos[id].completed ? { ...collection, id: todos[id] } : collection),
|
||||
{}
|
||||
);
|
||||
Object.keys(todos).forEach(id => {
|
||||
if (!todos[id].completed) {
|
||||
filteredTodos[id] = todos[id];
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
filteredTodos = todos;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user