From 15ae1eca6d32700470e180ce29f479b92a8c6c88 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JTP554M\\User" Date: Tue, 3 Jul 2018 13:02:33 +0300 Subject: [PATCH] split actionCreators, reducers --- src/App.js | 9 ++++----- src/index.js | 2 +- src/store/actions/index.js | 3 +++ src/store/actions/items.js | 8 ++++---- src/store/{ => reducers}/filter.js | 4 ++-- src/store/{ => reducers}/items.js | 2 +- src/store/{ => reducers}/rootReducer.js | 0 7 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 src/store/actions/index.js rename src/store/{ => reducers}/filter.js (81%) rename src/store/{ => reducers}/items.js (92%) rename src/store/{ => reducers}/rootReducer.js (100%) diff --git a/src/App.js b/src/App.js index 109fa5e..cfa5e90 100644 --- a/src/App.js +++ b/src/App.js @@ -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) { @@ -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); diff --git a/src/index.js b/src/index.js index c41b56f..b37a16a 100644 --- a/src/index.js +++ b/src/index.js @@ -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__(); diff --git a/src/store/actions/index.js b/src/store/actions/index.js new file mode 100644 index 0000000..7720e26 --- /dev/null +++ b/src/store/actions/index.js @@ -0,0 +1,3 @@ +export {add, markDone} from './items' +export {changeFilter} from './filter' + diff --git a/src/store/actions/items.js b/src/store/actions/items.js index f74560f..c1ea04b 100644 --- a/src/store/actions/items.js +++ b/src/store/actions/items.js @@ -1,6 +1,5 @@ import * as actionTypes from './actionTypes' - //генераторы действий, action creators /** video #269:6minute of react 16 course **/ @@ -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, diff --git a/src/store/filter.js b/src/store/reducers/filter.js similarity index 81% rename from src/store/filter.js rename to src/store/reducers/filter.js index 80fd6e4..0bd0f37 100644 --- a/src/store/filter.js +++ b/src/store/reducers/filter.js @@ -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) { diff --git a/src/store/items.js b/src/store/reducers/items.js similarity index 92% rename from src/store/items.js rename to src/store/reducers/items.js index a82f2b7..001792b 100644 --- a/src/store/items.js +++ b/src/store/reducers/items.js @@ -1,4 +1,4 @@ -import * as actionTypes from './actions/actionTypes'; +import * as actionTypes from '../actions/actionTypes'; const initialState = { list: [], diff --git a/src/store/rootReducer.js b/src/store/reducers/rootReducer.js similarity index 100% rename from src/store/rootReducer.js rename to src/store/reducers/rootReducer.js