Skip to content

Commit

Permalink
split actionCreators, reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiiNikolayev committed Jul 3, 2018
1 parent c2c1f97 commit 15ae1ec
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import Output from './components/Output'
import {getFilteredItems} from './store/selects'
import './index.css'
import {VisibilityFilters} from './store/actions/actionTypes';
import * as actionCreatorsItems from './store/actions/items';
import * as actionCreatorsFilter from './store/actions/filter';
import * as actionCreators from './store/actions/index';

class App extends Component {
constructor(props) {
Expand Down Expand Up @@ -67,13 +66,13 @@ export default connect(
}),
mapDispatchToProps => ({
onItemAdd: (item) => {
mapDispatchToProps(actionCreatorsItems.add({id: Date.now(), name: item}));
mapDispatchToProps(actionCreators.add({id: Date.now(), name: item}));
},
onItemDone: (id) => {
mapDispatchToProps(actionCreatorsItems.markDone(id));
mapDispatchToProps(actionCreators.markDone(id));
},
changeFilter: (filter) => {
mapDispatchToProps(actionCreatorsFilter.changeFilter(filter))
mapDispatchToProps(actionCreators.changeFilter(filter))
}
})
)(App);
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import thunk from 'redux-thunk'

import './index.css';
import App from './App';
import rootReducer from './store/rootReducer'
import rootReducer from './store/reducers/rootReducer'

const devTools = window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__();

Expand Down
3 changes: 3 additions & 0 deletions src/store/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {add, markDone} from './items'
export {changeFilter} from './filter'

8 changes: 4 additions & 4 deletions src/store/actions/items.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as actionTypes from './actionTypes'


//генераторы действий, action creators

/** video #269:6minute of react 16 course **/
Expand All @@ -13,14 +12,15 @@ export const saveAdd = ({id, name}) => {
};

export const add = ({id, name}) => {
return dispatch => {
return (dispatch, getState) => {
setTimeout( () => {
/* const oldName = getState().items;
console.log(oldName);*/
dispatch(saveAdd({id, name}));
}, 3000 );
}, 1108 );
}
};


export const markDone = (getId) => {
return {
type: actionTypes.MARK_DONE,
Expand Down
4 changes: 2 additions & 2 deletions src/store/filter.js → src/store/reducers/filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {CHANGE_FILTER, VisibilityFilters} from './actions/actionTypes';
import {CHANGE_FILTER, VisibilityFilters} from '../actions/actionTypes';

const initialState = {
currentFilter: VisibilityFilters.SORT_ALL
}
};

const reducerFilter = (state = initialState, action) => {
switch (action.type) {
Expand Down
2 changes: 1 addition & 1 deletion src/store/items.js → src/store/reducers/items.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as actionTypes from './actions/actionTypes';
import * as actionTypes from '../actions/actionTypes';

const initialState = {
list: [],
Expand Down
File renamed without changes.

0 comments on commit 15ae1ec

Please sign in to comment.