Skip to content

Commit

Permalink
Simplifying arrow function
Browse files Browse the repository at this point in the history
  • Loading branch information
zainsra7 committed Jan 31, 2022
1 parent d8f41c1 commit 032a04d
Showing 1 changed file with 31 additions and 46 deletions.
77 changes: 31 additions & 46 deletions src/index.js
Expand Up @@ -4,7 +4,6 @@ import { combineReducers } from './combinedReducers';
import { createStore } from './createStore';
import { Provider, connect } from 'react-redux';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';

// Constants
const ADD_TODO = "ADD_TODO";
Expand Down Expand Up @@ -131,59 +130,45 @@ const Todo = ({
);

// Action Creators
const addTodo = (text) => {
return {
type: ADD_TODO,
id: nextTodoId++,
text,
};
};
const setVisibilityFilter = (filter) => {
return {
type: SET_VISIBILITY_FILTER,
filter
};
};
const toggleTodo = (id) => {
return {
type: TOGGLE_TODO,
id
};
};
const addTodo = (text) => ({
type: ADD_TODO,
id: nextTodoId++,
text,
});
const setVisibilityFilter = (filter) => ({
type: SET_VISIBILITY_FILTER,
filter
});
const toggleTodo = (id) => ({
type: TOGGLE_TODO,
id
});

// Container Components
const mapStateToLinkProps = (state, ownProps) => {
return{
active: ownProps.filter === state.visibilityFilter
}
};
const mapStateToLinkProps = (state, ownProps) => ({
active: ownProps.filter === state.visibilityFilter
});

const mapDispatchToLinkProps = (dispatch, ownProps) => {
return{
onClick: () => {
dispatch(setVisibilityFilter(ownProps.filter))
}
const mapDispatchToLinkProps = (dispatch, ownProps) => ({
onClick(){
dispatch(setVisibilityFilter(ownProps.filter))
}
}
});

const FilterLink = connect(mapStateToLinkProps, mapDispatchToLinkProps)(Link);

const mapStateToListProps = (state) => {
return {
todos: getVisibleTodos(
state.todos,
state.visibilityFilter
)
};
};
const mapStateToListProps = (state) => ({
todos: getVisibleTodos(
state.todos,
state.visibilityFilter
)
});

const mapDispatchToListProps = (dispatch) => {
return {
onTodoClick: (id) => {
dispatch(toggleTodo(id))
}
};
};
const mapDispatchToListProps = (dispatch) => ({
onTodoClick(id){
dispatch(toggleTodo(id))
}
});

const VisibileTodoList = connect(mapStateToListProps, mapDispatchToListProps)(TodoList);

Expand Down

0 comments on commit 032a04d

Please sign in to comment.