From 7bd3b6766536e33146bb55506c79619a1ab7d3b3 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 11:10:05 +0100 Subject: Move reducers and actions into seperate folders --- src/client/react/App.js | 10 --------- src/client/react/App.jsx | 10 +++++++++ src/client/react/actions.js | 5 ----- src/client/react/actions/search.js | 5 +++++ src/client/react/components/container/Search.js | 6 ++--- .../react/components/presentational/Search.js | 26 ---------------------- .../react/components/presentational/Search.jsx | 26 ++++++++++++++++++++++ src/client/react/index.js | 20 ----------------- src/client/react/index.jsx | 20 +++++++++++++++++ src/client/react/reducers.js | 25 +++++---------------- src/client/react/reducers/search.js | 21 +++++++++++++++++ 11 files changed, 91 insertions(+), 83 deletions(-) delete mode 100644 src/client/react/App.js create mode 100644 src/client/react/App.jsx delete mode 100644 src/client/react/actions.js create mode 100644 src/client/react/actions/search.js delete mode 100644 src/client/react/components/presentational/Search.js create mode 100644 src/client/react/components/presentational/Search.jsx delete mode 100644 src/client/react/index.js create mode 100644 src/client/react/index.jsx create mode 100644 src/client/react/reducers/search.js (limited to 'src/client') diff --git a/src/client/react/App.js b/src/client/react/App.js deleted file mode 100644 index d79826e..0000000 --- a/src/client/react/App.js +++ /dev/null @@ -1,10 +0,0 @@ -import React from 'react'; -import Search from './components/container/Search'; - -const App = () => ( -
- -
-); - -export default App; diff --git a/src/client/react/App.jsx b/src/client/react/App.jsx new file mode 100644 index 0000000..d79826e --- /dev/null +++ b/src/client/react/App.jsx @@ -0,0 +1,10 @@ +import React from 'react'; +import Search from './components/container/Search'; + +const App = () => ( +
+ +
+); + +export default App; diff --git a/src/client/react/actions.js b/src/client/react/actions.js deleted file mode 100644 index a754943..0000000 --- a/src/client/react/actions.js +++ /dev/null @@ -1,5 +0,0 @@ -// eslint-disable-next-line import/prefer-default-export -export const type = typedValue => ({ - type: 'TYPE', - typedValue, -}); diff --git a/src/client/react/actions/search.js b/src/client/react/actions/search.js new file mode 100644 index 0000000..82db383 --- /dev/null +++ b/src/client/react/actions/search.js @@ -0,0 +1,5 @@ +// eslint-disable-next-line import/prefer-default-export +export const type = typedValue => ({ + type: 'SEARCH/TYPE', + typedValue, +}); diff --git a/src/client/react/components/container/Search.js b/src/client/react/components/container/Search.js index 0722128..ddfb0a6 100644 --- a/src/client/react/components/container/Search.js +++ b/src/client/react/components/container/Search.js @@ -1,10 +1,10 @@ import { connect } from 'react-redux'; -import { type } from '../../actions'; +import { type } from '../../actions/search'; import PresentationalSearch from '../presentational/Search'; const mapStateToProps = state => ({ - results: state.searchResults, - value: state.searchInput, + results: state.search.searchResults, + value: state.search.searchInput, }); const mapDispatchToProps = dispatch => ({ diff --git a/src/client/react/components/presentational/Search.js b/src/client/react/components/presentational/Search.js deleted file mode 100644 index f75e612..0000000 --- a/src/client/react/components/presentational/Search.js +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; - -const Search = ({ onType, value, results }) => ( -
- - -
-); - -Search.propTypes = { - onType: PropTypes.func.isRequired, - value: PropTypes.func.isRequired, - results: PropTypes.arrayOf(PropTypes.shape({ - name: PropTypes.string.require, - type: PropTypes.string.require, - })).isRequired, -}; - -export default Search; diff --git a/src/client/react/components/presentational/Search.jsx b/src/client/react/components/presentational/Search.jsx new file mode 100644 index 0000000..1e00192 --- /dev/null +++ b/src/client/react/components/presentational/Search.jsx @@ -0,0 +1,26 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +const Search = ({ onType, value, results }) => ( +
+ + +
+); + +Search.propTypes = { + onType: PropTypes.func.isRequired, + value: PropTypes.string.isRequired, + results: PropTypes.arrayOf(PropTypes.shape({ + name: PropTypes.string.require, + type: PropTypes.string.require, + })).isRequired, +}; + +export default Search; diff --git a/src/client/react/index.js b/src/client/react/index.js deleted file mode 100644 index e1bae3c..0000000 --- a/src/client/react/index.js +++ /dev/null @@ -1,20 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import { Provider } from 'react-redux'; -import { createStore } from 'redux'; -import reducer from './reducers'; -import App from './App'; - -/* eslint-disable no-underscore-dangle */ -const store = createStore( - reducer, - window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), -); -/* eslint-enable */ - -ReactDOM.render( - - - , - document.getElementById('root'), -); diff --git a/src/client/react/index.jsx b/src/client/react/index.jsx new file mode 100644 index 0000000..e1bae3c --- /dev/null +++ b/src/client/react/index.jsx @@ -0,0 +1,20 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import { Provider } from 'react-redux'; +import { createStore } from 'redux'; +import reducer from './reducers'; +import App from './App'; + +/* eslint-disable no-underscore-dangle */ +const store = createStore( + reducer, + window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), +); +/* eslint-enable */ + +ReactDOM.render( + + + , + document.getElementById('root'), +); diff --git a/src/client/react/reducers.js b/src/client/react/reducers.js index 3fb884b..9fdf2c4 100644 --- a/src/client/react/reducers.js +++ b/src/client/react/reducers.js @@ -1,21 +1,8 @@ -const DEFAULT_STATE = { - searchInput: '', - searchResults: [], -}; +import { combineReducers } from 'redux'; +import search from './reducers/search'; -const reducer = (state = DEFAULT_STATE, action) => { - switch (action.type) { - case 'TYPE': - return { - ...state, - searchInput: action.typedValue, - searchResults: [ - { type: 's', name: '18561' }, - ], - }; - default: - return state; - } -}; +const rootReducer = combineReducers({ + search, +}); -export default reducer; +export default rootReducer; diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js new file mode 100644 index 0000000..05926c9 --- /dev/null +++ b/src/client/react/reducers/search.js @@ -0,0 +1,21 @@ +const DEFAULT_STATE = { + searchInput: '', + searchResults: [], +}; + +const search = (state = DEFAULT_STATE, action) => { + switch (action.type) { + case 'SEARCH/TYPE': + return { + ...state, + searchInput: action.typedValue, + searchResults: [ + { type: 's', name: '18561' }, + ], + }; + default: + return state; + } +}; + +export default search; -- cgit v1.1